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.
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
What about when creating a new user? Does that work over there or has it the same behavior?
If it DOES work on the new user, I would try this is in order inside the problem account:
It is (hopefully) unnecessary to mention that you want to create a backup of your machine first before trying the following steps, but I still felt the urge to do so.
- flush all cache files (
~/Library/Caches/*.*
)
- in Finder, open menu "Go", press down "Alt" and while holding click on "Library"
- navigate INTO the Caches folder and select every object you can find and remove them
- reboot the computer (logging in and out possibly does the same trick, but I want to be sure)
- empty the Trash at your leisure once logged back in
- check ~/Library/Saved Application States to see if there is a folder com.apple.Finder and dump it (if there is not, less work for you)
- This is more of a blunt measure, but I think still worth trying: create a folder on the Desktop, move all preference files in there and then test AFTER you logged out and back in. If it resumed working, try again with more and more preferences put back until either all are back in or the problem re-occurs. Occasionally, you may want to log out and back in as well to see if, after placing a file back, the behavior starts again. If removing all preferences does not bring the behavior back to normal, just move all back in overwriting every newly created one.
Until their respective preference files are back in, I would recommend not to open those applications (especially Mail) as this may have side-effects on your applications' settings and sometimes content becoming inaccessible (or more difficult to reach/get back).
The reasoning behind number 3 is that some preferences may not be viewed as the obvious origin, but still may have caused that. Removing them all and then putting them back one-by-one (or 5 at a time) makes sure that you can identify which file this has actually caused.
In the event that a newly created user has the same behavior (only then), you can try to install the latest combo update or re-install Mac OS X (no erase, just installing over the existing installation) to repair/re-add corrupted/missing files.
Best Answer
If you are saying that you want each double-click to open the new file in a new tab of the current Sublime window, rather than opening a new window in Sublime, then that is going to be an application-specific preference. Meaning, you'll need to look at the preferences for Sublime and see if there isn't some equivalent of "Open new file in tab" or "Open new window in new tab" setting.