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?
Fire up AppleScript Editor and put in the following script:
tell application "Terminal" to do script "cd /path/to/your/folder"
/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.
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
I am not on OS X right now so I can’t test this, but these ideas sprung to mind:
Make a shortcut (or script, and then shortcut to it) like this:
cd /path/to/your/folder && term
Where the path is to your folder and the correct command to launch the terminal is used.
If you only ever use the terminal in that way, you could put the cd (change directory) command into your bash profile, so whenever you open a new terminal it will go there.