Skip to content

Instantly share code, notes, and snippets.

@oelna
Created June 21, 2018 14:32
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oelna/c3781927770ef3d04a4da8fac4e2458b to your computer and use it in GitHub Desktop.
Save oelna/c3781927770ef3d04a4da8fac4e2458b to your computer and use it in GitHub Desktop.
macOS Automator Action to calculate file hashes
on run {input, parameters}
with timeout of 360 seconds
tell application "System Events"
activate
display dialog input buttons {"OK"} default button 1 with title "File Hashes" giving up after 300 --seconds
end tell
end timeout
end run
for file; do
if [[ -d "$file" ]]; then
echo "$(basename "$file") is a directory"
else
cd "$(dirname "$file")"
printf "File: $(basename "$file")"
printf "\n\nMD5: "
/usr/bin/openssl md5 "$(basename "$file")" | egrep -o [a-f0-9]{32}
printf "\nSHA1: "
shasum -a 1 "$(basename "$file")" | egrep -o [a-f0-9]{40}
printf "\nSHA256: "
shasum -a 256 "$(basename "$file")" | egrep -o [a-f0-9]{64}
fi
done | tr "\n" "\r"
@oelna
Copy link
Author

oelna commented Jun 21, 2018

Working from the quite perfect code sample on Superuser I made an Automator service to display the MD5, SHA1 and SHA256 hashes for a file via the Services context menu.

Instructions:

  • Make new Automator service
  • Set to "Service receives selected files or folders in Finder.app
  • Run Shell Script calculate.sh
  • Run Applescript applescript.scpt

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment