Opening Safari in Desktop 2

New to Keyboard Maestro.

  1. How do I create a macro so that Safari launches (opens a blank window) in Desktop 2.
  2. Is that possible?

Note: i checked the forum. Seems Apple hasn’t provided any API for that purpose. Or am i missing something?

You can try this, but it may not be 100% reliable.
First, you need to set the shortcut key for Desktop 2 in System Preferences > Keyboard > Shortcuts > Mission Control:


I used ⌃2, which I believe is the default.

You may also need to adjust the Pause after the Type Keystroke to work with your system.

MACRO:   Open Safari in Desktop 2

~~~ VER: 1.1    2018-03-03 ~~~


Open Safari in Desktop 2.kmmacros (5.8 KB)
Note: This Macro was uploaded in a DISABLED state. You must enable before it can be triggered.


Thanks jmichaeltx.

Seemed to work a couple of times and stopped working and now i keep getting those ENDLESS notifications:
Screenshot javascript Safari (04-03-2018 15-22-02)

i'm a removing Keyboard Maestro immediately from my Mac since kbm keeps sending those notifications and dramatically slows down macOS.

Please help.

Do you do as the KM notification requested?

I have done it, and I never get that notification, and Safari responds fine to KM, AppleScript, JavaScript, and JXA.

Not entirely sure why you’re seeing Safari complain that JavaScript isn’t enabled in the Develop menu for this action but I’ve found it advantageous (and harmless) to do so. It lets Keyboard Maestro control Safari.

You can of course set Safari (or any application) to always open in a particular Desktop by clicking on its icon in the Dock, selecting Options and selecting the desktop you want. When you open a new window in Safari, it will open it on that desktop.

No magic required.

Thanks for the information. I’d rather avoid enabling JavaScript for Apple Events… Scary since i dont exactly know what i’m doing…

Thanks for the suggestion :slight_smile:
I need to install Keyboard Maestro again & try what you suggested without enabling JavaScript in Develop menu unless you suggest otherwise

Update: i dont need Keyboard Maestro for that.
But i do need Keyboard Maestro since i need sometimes (several times a day) to open Safari on Desktop 2 but not by default.

I’m therefore back to square one : trying to install @JMichaelTX 's macro and enabling javascript in Safari’s dev menu (:-

JMichaelTX’s macro automates 1) switching to another Desktop and then 2) launching Safari and finally 3) opening a new window.

If you’re wary about the second and third steps, you can open a new window in Safari manually and move it to another desktop by clicking and holding in the title bar or the new window and typing Control and the Desktop number (Control-2 in his example). You don’t need Keyboard Maestro for that operation either.

But JMichaelTX’s macro may feel like a gift after you do that a while. :slight_smile:

Over the years I’ve found it quite safe and helpful to enable JavaScript in the Develop menu.

I believe this is quite safe. I’ve never heard of any issues with this being enabled. I just did a Google Search on this, and the only issues I found were about how to enable it.

This is required for almost any (all that I know of) automation of Safari. Of course, the choice is up to you.

@JMichaelTX @mrpasini : thanks for your reassuring advice :wink:

I reinstalled KBM and the macro

  • no system prompt this time (yet…)
  • but i get this notification
    Screenshot of Keyboard Maestro Engine (04-03-2018 15-15-41)

Note: i then set the pause to 2 seconds instead of 1, but no success.


That is very strange.
Can you confirm that Safari has this menu item:


Maybe Safari has not launched when this action executes. So you could insert this Action just before the IF/Then action:


Thanks again @JMichaelTX !

Yes Safari has this menu item but my system is in French. I therefore wrote “File” and “New Window” in French and… it worked :smile:

So, to recap:

  1. KBM “speaks” English to my Mac but demands I write in French (for the Safari Action) :thinking: On other respects, macOS underlying language is English.
  2. I assume i should write the app’s menu item in French only when the app is localized (and Safari is). If the app is in English or in another language (ForkLift 3.0 used to “speak” Hungarian, Renamer would speak Spanish at first… Fortunately i can speak those languages :relieved:), i’m supposed to write the menu items i want to use in the app’s language.

Please correct me if i’m wrong.

1 Like