AppleScript: Open a new window in current space without switching to active window in another space

14,122

Some applications have an action for opening a new window in their Dock context menu.

Other options for different applications:

tell application "TextEdit"
    make new document
    activate
end tell

tell application "Safari"
    make new document at end of documents with properties {URL:"http://g.co"}
    activate
end tell

tell application "Terminal"
    do script ""
    activate
end tell

tell application "System Events" to tell process "iTerm"
    click menu item "New Window" of menu "Shell" of menu bar 1
    set frontmost to true
end tell

tell application "Google Chrome"
    make new window
    activate
end tell
Share:
14,122

Related videos on Youtube

Will
Author by

Will

Scientific computing and web development.

Updated on September 18, 2022

Comments

  • Will
    Will over 1 year

    I want to have an application open a new window in the current space without switching to a space in which a window is already open, but I want to keep the

    When switching to an application, switch to a space with open windows for the application

    setting in System Preferences > Mission Control.

    In other words, I want to tell an application to open a new window directly, without first telling it to activate.

    How can I do this with AppleScript (if possible)?

  • Will
    Will about 11 years
    Great, thank you very much! Incidentally, how did you find those commands? Is there easily-accessible documentation?
  • Joel Mellon
    Joel Mellon over 10 years
    Thanks! Just a note for the quick copy/pasters (like myself): activate after making a new Chrome window to bring the new window (all windows actually) to the front. - All the other examples here include some form of activation.
  • ATSiem
    ATSiem over 5 years
    Awesome! I used the following example to open a new window of iA Writer (great text editor) using Alfred 3: '-- Open new iA Text Window tell application "iA Writer" make new document activate end tell'
  • ruucm Ji
    ruucm Ji over 4 years
    awesome. it's cool man