Automate Your Work with Macros

EmEditor’s macro feature helps you automate tasks, streamline workflows, and boost productivity through a flexible and robust scripting system. With support for both JavaScript and VBScript, macros in EmEditor are versatile, allowing you to automate everything from simple text transformations to complex, multi-step operations. Videos demonstrating macros can be viewed at the bottom of this article.

Flexible recording and execution

Creating your first macro is as simple as clicking the red Start Recording 🟥 button in the toolbar. Record your actions, click Stop Recording when finished, and instantly generate a script that can be reused. Macros can be executed from the Macros menu or Macros toolbar.

To display the macro toolbar, right-click on any toolbar and enable the Macros toolbar. This provides easy access to built-in and user-defined macros.

The My Macros tab of the Customize Macros dialog further enhances management. From this interface, you can add, remove, and reorder your macros. It also allows you to configure macros to run automatically based on specific triggers, providing an even deeper level of automation.

Run macros with temporary options

Need to run a macro on multiple documents or repeat it a set number of times? The Run with Temporary Options feature allows you to do just that. Simply select your macro, customize options like “Run the macro against each opened document,” and add the documents you want to process. This is perfect for batch operations or repetitive tasks.

Choose Your Scripting Engine

EmEditor supports two JavaScript engines: JScript and the modern V8 engine.

The V8 engine provides compatibility with the latest ECMAScript standards, such as async/await, Promises, fetch, Set, Map, and more. It leverages Microsoft Edge to deliver cutting-edge performance and expanded syntax support. The V8 engine makes it possible to integrate advanced features like asynchronous HTTP requests, enabling you to build macros that connect to external APIs or services.

Switching between engines is easy—select your preferred engine in the Customize Macros dialog or specify it within the macro file using the #language directive.

Trigger macros with events

EmEditor macros can be triggered automatically based on specific events. In the My Macros tab of the Customize Macros dialog, you can configure macros to execute automatically when a document is opened, saved, or modified.

Assign macro to keyboard shortcut

To assign a macro to a keyboard shortcut, navigate to Tools > Properties for Current Configuration (or All Configurations) > Keyboard. Under the My Macros category, select your macro, type a new shortcut in the field, and assign it. This allows you to execute your favorite macros instantly with a single key press.

Command categories

The macro environment provides powerful objects to give users complete control over their documents and editor configurations:

  • Document: Automate tasks on the active document, such as filtering or line retrieval.
  • Editor: Access global editor configurations and batch operations.
  • Selection: Manipulate and query the current text selection.
  • Window: Use global methods like alerts or status messages.
  • Shell: Interact with the operating system, including environment variables and file operations.

Call almost every editor command

Some uncommon editor commands do not have an associated named method. For those commands, you can use editor.ExecuteCommandByID() and pass the command ID.

Advanced customization

EmEditor’s macro system supports custom events and includes directives like #include for integrating external JavaScript files. With third-party libraries, you can extend the capabilities of your macros to handle sophisticated operations like date manipulations using popular libraries such as Luxon.

Built-in and user macros

EmEditor comes with built-in macros, like the AI Macro. Users can create and manage their macros easily, running them across multiple documents or setting them to repeat automatically.

Whether you’re automating data transformations, integrating web services, or streamlining repetitive tasks, EmEditor’s macros offer a comprehensive suite of tools to boost your productivity. Explore the endless possibilities today!