Open Terminal.app with directory from a given URL?

With the URL <file:///Library/Fonts> (for example in a note in NV) I can open the finder with the given location. Can I do something similar for the terminal? That is, if I write for example (doesn't work, that is the question!) <terminal://Library/Fonts> the Terminal.app should open a new window and cd to that directory.


Solution 1:

Opening a New Terminal Interactively

As of Mac OS X Lion 10.7, Terminal has a “New Terminal at Folder” Service you can enable in:

System Preferences > Keyboard > Services > Files and Folders

With this Service you can open a new terminal by selecting a folder or file path in any application and choosing this Service in the contextual menu (Control-Click or Right-Click) or the Services submenu in the application menu.

It doesn’t support “file:” URLs, but you can select the path part of the URL “/Library/Fonts” and use the Service with that.

There is also a “New Terminal Tab at Folder” Service.

Opening a New Terminal Programmatically

If you need to open it from a command line or shell script, you can use the open command to tell Terminal to open a directory pathname or “file:” URL:

open -a Terminal file:///Library/Fonts

(This is equivalent to dragging a folder, file path or “file:” URL onto the Terminal application, which opens a new Terminal at that location.)

Solution 2:

This works from the command line:

/Applications/Utilities/Terminal.app/Contents/MacOS/Terminal /Users/ &

Where /Users/ is the directory you want to set the working directory to.