Open in Terminal

Summary: Open Terminal windows for selected/dropped items.
Requires:
Suggested Key Binding: Command-Control-T
Install Location: ~/Library/Scripts/Applications/Finder/
Last Modified: 2019-10-02

Description

Opens Terminal windows for the items selected in the Finder (or the items dropped onto the droplet). If a folder or package is selected, the Terminal window’s working directory will be that folder. If a file is selected, the working directory will be the file’s containing folder.

I recommend saving the script as an application, giving it a Terminal-like icon, and setting LSUIElement to 1 in the Info.plist.

Installation Instructions · Download in Compiled Format · Download in Text Format

Script

on run
    
tell application "Finder"
        
set l to the selection
        
my processItems(l)
    
end tell
end run

on open l
    
my processItems(l)
end open

on processItems(l)
    
repeat with i in l
        
my processItem(i)
    
end repeat
end processItems

on processItem(i)
    
tell application "Finder"
        
if not my canChangeDirectoryTo(i) then set i to i's container
        
set a to i as alias
        
set p to a's POSIX path's quoted form
    
end tell
    
tell application "Terminal"
        
activate
        
do script with command "cd " & p
    
end tell
end processItem

on canChangeDirectoryTo(f)
    
tell application "Finder"
        
if class of f is folder then return true
        
if class of f is package then return true
        
if class of f is application file and name of f ends with ".app" then return true
        
return false
    
end tell
end canChangeDirectoryTo