Last active
January 17, 2017 19:50
-
-
Save karstengresch/81ad474c8c5351a97df4c204bc702c5a 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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Adapted from these sources: | |
-- http://peterdowns.com/posts/open-iterm-finder-service.html | |
-- https://gist.github.com/cowboy/905546 | |
-- https://gist.github.com/shuntaroy/e5ce3ad61c0deb7e27f0 | |
-- | |
on run {input, parameters} | |
tell application "Finder" | |
set my_file to first item of input | |
set filetype to (kind of (info for my_file)) | |
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 | |
try | |
set currentWindow to the last window | |
on error | |
set currentWindow to (create window with default profile) | |
end try | |
tell current window | |
-- These commands return a tab | |
set newTab to (create tab with default profile) | |
tell newTab | |
select | |
tell current session of currentWindow | |
write text go_dir | |
end tell | |
end tell | |
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