Last active
December 8, 2016 23:10
-
-
Save alexandregz/7e2837e031c8d608b4f3ef3a2b855c32 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 | |
-- | |
-- Modified to work with files as well, cd-ing to their container folder | |
-- | |
-- FINAL VERSION | |
-- Save as "Application" from Automator and Drag&Drop to finder (see peterdowns post) | |
-- | |
on run {input, parameters} | |
tell application "Finder" | |
set dir_path to quoted form of (POSIX path of (folder of the front window as alias)) | |
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