Skip to content

Instantly share code, notes, and snippets.

@adriancmiranda
Last active June 27, 2023 02:55
Show Gist options
  • Save adriancmiranda/1934890349a06eadf29beba49d0081c2 to your computer and use it in GitHub Desktop.
Save adriancmiranda/1934890349a06eadf29beba49d0081c2 to your computer and use it in GitHub Desktop.
Apple script to open an iterm2 "nightly" window from right-clicking on a file or folder in Finder. To use:(1) Open Automator(2) Create a new service(3) Change "Service receives selected" drop downs to "Files or folders" in "Finder"(4) Select "Run applescript" from the sidebar, then paste this script in and save
-- Adapted from these sources:
-- http://peterdowns.com/posts/open-iterm-finder-service.html
-- https://gist.github.com/cowboy/905546
--
-- Modified to work with files as well, cd-ing to their container folder
on run {input, parameters}
tell application "Finder"
set my_file to first item of input
set filetype to (kind of (info for my_file))
-- Treats OS X applications as files. To treat them as folders, integrate this SO answer:
-- http://stackoverflow.com/a/6881524/640517
set dir_path to quoted form of (POSIX path of my_file)
end tell
CD_to(dir_path)
end run
on CD_to(theDir)
tell application "iTerm"
activate
set go_dir to "cd " & theDir
set newWindow to (create window with default profile)
tell current session of first window
write text go_dir
end tell
end tell
end CD_to
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment