Using Keyboard Maestro to Enable or Disable JavaScript in Safari

Using Keyboard Maestro to Enable or Disable JavaScript in Safari

It was a pleasure to join the discussion on Mac Power Users Episode #181. During the episode, we delved into various automation topics for Mac users, and both Katie and David showed particular interest in a specific Keyboard Maestro macro.

Several years back, I penned an article on how to toggle JavaScript in Safari quickly, but it wasn’t until after the podcast that I refined the macro, adding more robust error checks. This refinement process introduced me to a new feature in Keyboard Maestro, thanks to a tip from Peter Lewis.

Using Keyboard Maestro to Enable or Disable JavaScript in Safari

The macro is straightforward: a simple command (⌘ + J) toggles the JavaScript setting in Safari and refreshes the page. This macro proves incredibly useful for navigating websites that are cluttered with distractions. Additionally, using (⌥ + J) will display the current JavaScript status without altering it.

For those eager to try these macros, they are available for download on the Github page for these two macros.

For a deeper dive into the macro’s functionality and the new feature I discovered, keep reading.

Developing the Macros

Keyboard Maestro macros are typically categorized as either “global” or “local.” Global macros, like the ubiquitous ⌘ + space for Spotlight, work across all applications. Conversely, local macros are designed for specific applications, such as Safari. For instance, pressing ⌘ + J in Finder shouldn’t affect Safari’s settings.

To ensure these macros only function within Safari, they are grouped in a Keyboard Maestro “Group” set to activate only in Safari. This setup might sound complex, but it’s quite straightforward. Here’s a visual to help explain:

A more detailed version of this screenshot is available on Github.

In the screenshot, you can see the “Safari Only” Macros group.

This group functions like a folder, holding any number of Safari-specific macros. When you import my macros, they automatically populate this group, simplifying the setup process.

Once imported, you can review the macros to understand their construction. They might look complex due to the extensive error-checking, but their functionality is quite simple. For instance, look at how the menu item for disabling JavaScript changes:

Using Keyboard Maestro to Enable or Disable JavaScript in Safari
Using Keyboard Maestro to Enable or Disable JavaScript in Safari

As I previously suggested, assigning a keyboard shortcut to “Disable JavaScript” through System Preferences is less efficient than using a Keyboard Maestro macro, which syncs across all your Macs via Dropbox. This macro not only selects the menu item but also checks if the “Reload Page” option is available, reloading the page if possible.

By adding a few extra steps, the macro’s functionality expands, providing more value each time it’s used.

Share This Article

Daniel is a dedicated writer for TUAW, bringing years of experience and a deep love for all things Apple. With a keen eye for detail, Daniel covers everything from the latest iPhone and iPad releases to the newest features in macOS and watchOS. His insightful articles and reviews help readers stay informed and make the most of their Apple products. When he’s not writing, Daniel enjoys exploring new apps and tinkering with his MacBook Pro.