Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

When using Spaces on Mac OS X trying to open a new terminal instance results in focus being pulled to whatever space has the most recently accessed terminal window. With Finder I can click on the Desktop and then use Cmd-N to create a new Finder window. What I am looking for is a method for performing the same function for Terminal windows.

How can I create a new Terminal instance in the current space, regardless of whether or not there is another Terminal instance in one or more other spaces.

Thanks.

share|improve this question

migrated from stackoverflow.com May 7 '11 at 11:30

This question came from our site for professional and enthusiast programmers.

    
i like the question, but think it should be on super user. –  hvgotcodes Oct 15 '10 at 0:50
add comment

5 Answers 5

You can create a new service using automator (from the applications folder). At the top of the automator window, enter: Service receives 'no input' in 'any application'. Then, in the workflow, add 'Run applescript'. Make the applescript contain the following:

on run {input, parameters}

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

    return input
end run

(You can add any command you like into the do script line between the " " (e.g. something useful to run when terminal first opens like "uptime" if you like, or just leave it blank).

Save the service as 'Open Terminal' or whatever name you like. It should now appear in your services menu.

Then if you want to add a keyboard shortcut, you just need to go to System Preferences -> Keyboard -> Keyboard Shortcuts tab, select services in the left hand menu, and find your new service (its probably near the bottom). Just click in the space to the right of your service name, and assign it whatever keyboard shortcut you like, and hey presto! it should all work

share|improve this answer
1  
It should be noted that this does actually provide the requested functionality. As a minor edit, you need the do shell script " " line for it to open a new window in the current space, but there is no need for the shell script to be a blank space. If it's a blank space, it causes the Terminal to run the blank space as a command, leading to execution delays and an extraneous line in the new Terminal window. Just make it a completely empty string: do shell script "" and then it opens a fresh Terminal window but doesn't issue any commands whatsoever in it. –  Dakota Aug 7 '13 at 3:05
    
Yep, you're right. I've updated the answer to remove the space from between the quotes. However, in order to work it needs to be do script "", and not do shell script "", as @dakota suggested –  tom Nov 28 '13 at 10:35
add comment

In the application assignments in System Preferences -> Spaces, either set Terminal to "Every Space" or delete the entry. Then it should be no problem to open a new Terminal window wherever you want, e.g. by clicking on the dock context menu "New Window" (works even if you have the "When switching to an app, switch to space with open windows from that app" option enabled).

share|improve this answer
    
The first sentence is irrelevant, as far as I can tell. Setting it to "Every Space" still changes the Space when opening a new window via something like AppleScript or a keybinding, and the dock context menu never changes the space regardless of this setting. The one interesting thing in this answer is the "When switching to an app, switch to space with open windows from that app" option. Disabling it "fixes" the keybinding/AppleScript case, but unfortunately "breaks" command-tab. If only OS-X had a proper "cycle windows" key binding that worked across all windows in all apps on all spaces. –  Laurence Gonsalves Apr 29 '11 at 6:34
    
@LaurenceGonsalves, you can cycle through all the Terminal windows across all Spaces with Command-Left/Right Arrow. Does that help? –  Chris Page Sep 22 '11 at 4:40
    
@Chris That's an interesting set of shortcuts, thanks, but they don't solve the problem I'm referring to. If the "When switching to an app..." setting is disabled and you're on a space with no Terminal windows and you command-tab to "Terminal" it doesn't switch to a space that has a Terminal window, and command-backtick won't do anything. Amazingly, command-left/right-arrow doesn't do anything in this case either (at least on Snow Leopard). Those keys will cycle between windows across spaces if a window in the current application has the focus, but if no window has the focus they do nothing. –  Laurence Gonsalves Sep 25 '11 at 2:18
add comment
tell application "Terminal"
    do script ""
    activate
end tell

To make this work under Lion, type the above into a new AppleScript window and save it. Invoke the script through a command launcher like QuickSilver or assign it to a keyboard shortcut. This should work, even if you have set the "When switching to an application, switch to a space with open windows for the application" setting enabled in Mission Control. The trick is to do the activate command last, rather than at the beginning.

share|improve this answer
    
Alternatively, create a Service using Automator and actuvate it using a keyboard shortcut set in System Preferences: apple.stackexchange.com/a/13655/36722 –  Dakota Aug 7 '13 at 3:10
add comment

If you use the dock menu to open a new window it opens in the current space.

share|improve this answer
    
Is there a way to do this from the keyboard? –  Laurence Gonsalves Apr 28 '11 at 22:03
    
Control-F3 is "Move focus to the Dock". You can use the arrow keys to navigate through Terminal's Dock icon menu. You can also type to select menu items by name, e.g., type "N" or "New W". See System Preferences > Keyboard > Keyboard Shortcuts > Keyboard & Text Input to see all the keyboard shortcuts for selecting and navigating through UI. –  Chris Page Sep 25 '11 at 6:42
    
It's possible to do this. You need to create a special Service using Automator, which you can then bind to a keyboard shortcut from System Preferences: apple.stackexchange.com/a/13655/36722 –  Dakota Aug 7 '13 at 3:10
add comment

You can disable OSX switching spaces automatically when you switch applications using the following commands:

defaults write com.apple.dock workspaces-auto-swoosh -bool NO
killall Dock

Works on 10.6.8

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.