Created
June 21, 2018 14:32
-
-
Save oelna/c3781927770ef3d04a4da8fac4e2458b to your computer and use it in GitHub Desktop.
macOS Automator Action to calculate file hashes
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
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 |
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
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" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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:
calculate.sh
applescript.scpt