OS X Terminal: Make a shortcut that opens to a specific folder
I would like a shortcut in my Dock that opens the Terminal window to a specific folder (the place where i store my development files). Is there a simple way to do this?
Solution 1:
Fire up AppleScript Editor and put in the following script:
tell application "Terminal" to do script "cd /path/to/your/folder"
replacing /path/to/your/folder/
with the actual path of your folder. Then, go File - Save As (or Shift + Command + S
), save with File Format Application, add it to your dock, and that's it! When you click that application, it will open up Terminal, cd
to your directory, and you'll be ready to roll.
Solution 2:
There are some general solutions available that use the current path in Finder, such as OpenTerminalHere and cdto.
You can accomplish your specific goal by using AppleScript:
tell application "Terminal" to do script "cd /your/path"
Save in AppleScript Editor as Script (right-hand side of the Dock) or application (left-hand side of the Dock). Side effect of the script is that it will always open a new Terminal window.
A little more sophisticated, opening a new tab only if necessary (depends on your preferences of course); this solution uses GUI scripting and might require support for assistive devices in Universal Access in System Preferences:
tell application "Terminal"
activate
set b to busy of selected tab of front window of application "Terminal"
tell application "System Events"
set x to count windows of application "Terminal"
if x = 0 or b then
keystroke "n" using command down # new window
end if
keystroke "cd /your/path"
key code 36 # press enter
keystroke "k" using command down # optional, clear scrollback
end tell
end tell