Skip to content

Instantly share code, notes, and snippets.

@marcinczenko
Created December 31, 2015 04:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marcinczenko/cb5e0de6db5779995714 to your computer and use it in GitHub Desktop.
Save marcinczenko/cb5e0de6db5779995714 to your computer and use it in GitHub Desktop.
Automator: check the SHA256 of the selected file in a new iTerm2 window
-- Adapted from these sources:
-- http://peterdowns.com/posts/open-iterm-finder-service.html
-- https://gist.github.com/cowboy/905546
-- https://gist.github.com/eric-hu/5846890
-- Modified to work with files as well, cd-ing to their container folder
-- Modified to do an ls -l if the selected item in Finder is a file so that you get the name of the file waiting for you in the terminal.
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
if filetype is "Folder" or filetype is "Volume" then
set dir_path to quoted form of (POSIX path of my_file)
else
set dir_path to quoted form of (POSIX path of (container of my_file as string))
end if
end tell
CD_to(dir_path, my_file)
end run
on CD_to(theDir, theFile)
tell application "iTerm"
activate
set t to (make new terminal)
tell t
launch session "Default Session"
tell the last session
write text "cd " & theDir
set filetype to (kind of (info for theFile))
if filetype is not "Folder" and filetype is not "Volume" then
write text "openssl dgst -sha256 " & (POSIX path of theFile)
end if
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