19

I have several applications in my dock that can have multiple instances open (eg. Chrome, iTerm, Sublime, etc.)

When I click on one of the icons, I want a new window to open (this is what happens if no windows are currently open) However, if an instance is already open it just takes me to that instance.

This gets especially annoying when the instance is on a whole other desktop instance and cause my desktop to change.

Is there a setting you can set to make it so when you click the icon, it opens a new window instead of redirecting you to an already opened window?

4
  • 2
    I could show you how to do this with a bit of AppleScript that you could keep in the Dock.
    – Ian C.
    Commented Mar 27, 2012 at 15:21
  • Or you could just hit ctrl+n.
    – CoffeeRain
    Commented Mar 27, 2012 at 16:06
  • 3
    @CoffeeRain Ctrl-N? What's that? Does nothing in iTerm and Chrome. I think you meant Cmd-N -- but that only works if the app is in the foreground.
    – Ian C.
    Commented Mar 27, 2012 at 16:27
  • 1
    @IanC. Sorry, yes I did mean Cmd-N.
    – CoffeeRain
    Commented Mar 27, 2012 at 16:45

2 Answers 2

18

You can kludge something together with some AppleScript and some clever icon image pasting. Here's how you'd do it for iTerm/iTerm2.

Open the AppleScript Editor and paste in the following AppleScript:

set myapp to "iTerm"
on appIsRunning(appName)
    tell application "System Events" to (name of processes) contains appName
end appIsRunning
if appIsRunning(myapp) then
    # What you do here will depend on the program. This works for
    # iTerm but you'll need to look up the actions for other programs
    # since this bit is iTerm-specific.
    tell application "iTerm"
        set myterm to (make new terminal)
        tell myterm
            launch session "Default"
        end tell
    end tell
else
    tell application myapp
        activate
    end tell
end if

You can use the Run button in the editor to test that it works. If you want a different profile opened change "Default" on line 12 to the name of the profile you want opened.

Now save this AppleScript. In the Save dialog under "File Format" at the bottom select "Application" from the list.

I saved mine as "New iTerm.app" to my Desktop.

Now every time I click on "New iTerm.app" on my Desktop I get a new iTerm window. I can drag "New iTerm.app" to my Dock and it'll be a Dock icon I can click on any time I want to get a new iTerm window open. But the icon is the generic AppleScript icon.

Let's change it to the iTerm icon. Select "New iTerm.app" on the Desktop and click Cmd-I to bring up the properties screen for the application.

Now navigate to /Applications in a Finder window, find iTerm in the list of installed applications, select it and click Cmd-I to open the properties screen for the iTerm application.

Click the icon in the iTerm info window so it gets a soft blue shadow around it. Press Cmd-C to copy the icon to the clipboard.

Now click the icon in the "New iTerm.app" info window and press Cmd-V to paste the iTerm icon on to the "New iTerm.app" application.

Copying the icon from iTerm to New iTerm

It should now have an iTerm icon.

You can move the "New iTerm.app" to your /Applications folder if you like. Drag it from the folder you decide to keep it in, back to your dock, and you can now click on it in the Dock to open up a new iTerm window with every click.

If you wanted to be able to distinguish it from the running iTerm.app Dock icon you could consider pasting the icon in to an image editor like Pixelmator and adding a big red + to it so it's clearly identified as the icon to press for a new iTerm window instead of the icon to press to see the exiting, open iTerm application.

Here are some more scripts for some other applications to get you started customizing things:

Google Chrome (New Window)

set myapp to "Google Chrome"
on appIsRunning(appName)
    tell application "System Events" to (name of processes) contains appName
end appIsRunning
if appIsRunning(myapp) then
    tell application "Google Chrome"
        make new window
    end tell
else
    tell application myapp
        activate
    end tell
end if

Google Chrome (New Tab)

set myapp to "Google Chrome"
on appIsRunning(appName)
    tell application "System Events" to (name of processes) contains appName
end appIsRunning
if appIsRunning(myapp) then
    tell application "Google Chrome"
        make new tab at end of tabs of window 1
    end tell
else
    tell application myapp
        activate
    end tell
end if

Sublime Text 2

Unfortunately ST2 doesn't seem to have an AppleScript accessible extensions. You can always take a look at the OS X command line tool that ST2 ships with. You can call that from a simple script in the Dock to open a new window in ST2. So:

set myapp to "Sublime Text 2"
on appIsRunning(appName)
    tell application "System Events" to (name of processes) contains appName
end appIsRunning
if appIsRunning(myapp) then
    # Assumes you've installed the subl command line tool for ST2
    # in to /usr/local/bin. Adjust accordingly.
    do shell script "/usr/local/bin/subl --new-window"
else
    tell application myapp
        activate
    end tell
end if
4
  • 2
    Great answer with clear examples covering different use cases and the details! Thanks!
    – Adam Davis
    Commented Mar 27, 2012 at 16:17
  • @AdamDavis I'm just starting out with AppleScript so it was a nice exercise to test what I've learned.
    – Ian C.
    Commented Mar 27, 2012 at 16:26
  • Could this be used to get the name of the currently running application?
    – William
    Commented Feb 13, 2015 at 4:58
  • Is there a way to check if the app is running AND it's NOT on the current desktop? I'd love a new window only if the existing window is on another desktop.
    – adamdport
    Commented Mar 11, 2016 at 14:08
5

I'd like to expand the comment from @CoffeeRain and make it a bit more clearer as a proper answer. You can achieve this without a launcher app with Mission Control set up to have more than one virtual desktop on Big Sur and later.

In order to open a new window in the current desktop:

  1. Open preferences->mission control and disable "When switching to an application..."
  2. Now let's say you have opened your app in the Desktop1 and you're in the Desktop2. Click on the app icon in the dock and press cmd+n. This will open a new window of the app in the Desktop2
3
  • 1
    Thx @bmike for your edit Commented Nov 2, 2021 at 14:37
  • 1
    Is there some way to eliminate the extra action of pressing command+n? It's very annoying.
    – Apreche
    Commented Nov 8, 2022 at 16:35
  • Well this, not exactly what you want, but at least something. I created a shortcut (in shortcuts.app) to bind a some keys shortcut to open my app (let's say control+option+b). Now in order to open this app, I need to press control+option+b and then command+n. It is very quickly gets automatic for you and comfortable enough Commented Nov 10, 2022 at 9:18

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .