Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

Copy link
Owner Author

@oelna 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