Apple/MacOS Terminal/Finder tip: This tutorial shows how to open a Mac Terminal window in the current Finder folder by using AppleScript.
For a while I have wanted to be able to open a Mac Terminal window in the same directory as the Mac Finder folder that I’m currently looking at. I couldn’t find any other way to do this, so I finally wrote an AppleScript script to do it. Fortunately the script is pretty simple. Here's the code:
tell application "Finder" set myWin to window 1 set thePath to (quoted form of POSIX path of (target of myWin as alias)) tell application "Terminal" activate tell window 1 do script "cd " & thePath end tell end tell end tell
When I have a Mac Finder window in the foreground and run this script from the AppleScript menu on the MacOS menubar, it opens a Mac Terminal window, and automatically places me in the same directory as the current Finder folder. Sweet.
Related
- If you don’t know where to save your AppleScript scripts (programs), see my tutorial, Where to save AppleScript programs so you can access them on the Mac/AppleScript menu bar
- If you don’t know how to show the AppleScript menu in the Mac OS X menu bar, see my tutorial, How to enable the AppleScript menu on the MacOS menu bar
In summary, if you wanted to see how to open a MacOS Terminal window in the current Mac Finder path, I hope this