Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Applescript droplet to get the SHA1 checksum Apps
Many software downloads will supply an 'SHA1 Checksum' to verify that what you downloaded is what the developer intended and not some malware pretender. It may not be obvious how to check this without using Terminal.

I created an Applescript droplet for verifying the 'NSA Secure Hash Algorithm 1' checksum that is sometimes supplied to authenticate a download. It's pretty simple, calling a shell script to output the checksum hash.

Just paste the following into AppleScript Editor and save the script as an Application.
-- if applet is double-clicked
set chosenFile to choose file with prompt "Select the file to checksum:"
do shell script "/usr/bin/openssl sha1 " & quoted form of POSIX path of chosenFile
display dialog result buttons {"OK"} default button "OK"

-- or if the file is drag and dropped
on open chosenFile
  do shell script "/usr/bin/openssl sha1" & quoted form of POSIX path of chosenFile
  display dialog result buttons {"OK"} default button "OK"
end open

You can either drag the file to verify onto the droplet, or you can double-click the applet and navigate to the file in question. Either approach should yield a dialog with the file's path and its resulting checksum hash.

The code was assembled from multiple sources, including Apple's Developer site, and tested by me under Snow Leopard.

[crarko adds: I tested this, and it works as described. This earlier hint describes a command-line tool (md5deep) that can be used to calculate a variety of checksums.]
    •    
  • Currently 3.20 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (10 votes cast)
 
[10,996 views]  

Applescript droplet to get the SHA1 checksum | 9 comments | Create New Account
Click here to return to the 'Applescript droplet to get the SHA1 checksum' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Applescript droplet to get the SHA1 checksum
Authored by: boredzo on Jun 11, '10 08:09:35AM
Alternatively, you could use a free application I wrote called EasyHash. It does both MD5 and SHA-1.

[ Reply to This | # ]
Applescript droplet to get the SHA1 checksum
Authored by: wallybear on Jun 11, '10 08:11:39AM

Funny! I just needed this yesterday to correct a sha1 checksum for Wine; after a little research I found that the command line to calculate the checksum is

openssl dgst -sha1 your_file

where your_file is obviously the file to checksum.



[ Reply to This | # ]
Applescript droplet to get the SHA1 checksum
Authored by: karog on Jun 11, '10 10:19:32AM

It would be even more useful if it asked the user for the supplied checksum and did the comparison for you.



[ Reply to This | # ]
Applescript droplet to get the SHA1 checksum
Authored by: djdawson on Jun 11, '10 10:19:59AM
I created a similar script some time ago that handles multiple files and computes the MD5, SHA, and SHA1 checksums of all the files dragged onto it. It also reformats the output so the checksums appear at the beginning of each line, since that makes it easier to compare a list of checksums, and it puts the output in a new TextEdit document so it can be easily saved, copied, etc. I've pasted the script below, but I don't know how well the various quotes, etc. will be handled:


on open TheseItems
	set FILE_LIST to ""
	repeat with N from 1 to the count of TheseItems
		set ThisItem to item N of TheseItems as text
		set PNAME to POSIX path of ThisItem
		set FILE_LIST to FILE_LIST & " " & quoted form of PNAME
	end repeat
	set CHKSUM_MD5 to do shell script "/usr/bin/openssl dgst -md5 " & FILE_LIST & " | awk -F '= ' '{print $2, \"=\", $1};'"
	set CHKSUM_SHA to do shell script "/usr/bin/openssl dgst -sha " & FILE_LIST & " | awk -F '= ' '{print $2, \"=\", $1};'"
	set CHKSUM_SHA1 to do shell script "/usr/bin/openssl dgst -sha1 " & FILE_LIST & " | awk -F '= ' '{print $2, \"=\", $1};'"
	tell application "TextEdit"
		launch
		make new document
		set text of front document to CHKSUM_MD5 & return & return & CHKSUM_SHA & return & return & CHKSUM_SHA1
		tell the text of the front document
			set the font to "Courier"
			set the size to 12
		end tell
	end tell
	tell application "TextEdit" to activate
end open


[ Reply to This | # ]
Applescript droplet to get the SHA1 checksum
Authored by: jnsimonhints on Jun 11, '10 01:11:12PM

I have a command "shasum" that seems to be part of perl that does SHA1 checksums and seems to be a lot faster that using openSSL to do it.



[ Reply to This | # ]
Applescript droplet to get the SHA1 checksum
Authored by: prramesh on Jun 12, '10 02:28:26AM

what's the easy way to compare two checksum values? and find out any difference.



[ Reply to This | # ]
Applescript droplet to get the SHA1 checksum
Authored by: jordanmd on Jun 13, '10 09:21:06PM
I know this is not AppleScript, but if there are those that want a quick and easy compare and if you're a Terminal fan, I use this code in my $HOME/.bashrc file:

cksha1 ()
{
if [ $# -lt 2 ] ; then
	echo "Usage: cksha1 filepath sha1-sum ..." ;
	echo "       must specify at least one pair of file and checksum." ;
	echo "Exiting." ;
fi

filesha1=`/usr/bin/openssl sha1 $1 | /usr/bin/awk -F"=" '{ print $2 }'` ; 
	if [ $filesha1 == $2 ] ; then 
		echo "** SHA1 matches **" ; 
	else 
		echo " ********** ERROR: SHA1 DOES NOT MATCH **********" ; fi
}

This lets me copy the checksum from the web page where they list it and do the following in Terminal:

$ cksha1 ~/Desktop/Inbox/GoogleChrome.dmg e90cc5b126544dfa9a264a105d49a1824fb8786d
** SHA1 matches **

You can easily do the same for the other common digest format: MD5

ckmd5 ()
{
if [ $# -lt 2 ] ; then
	echo "Usage: ckmd5 filepath md5sum ..." ;
	echo "       must specify at least one pair of file and checksum." ;
	echo "Exiting." ;
fi

filemd5=`/usr/bin/openssl md5 $1 | /usr/bin/awk -F"=" '{ print $2 }'` ; 
	if [ $filemd5 == $2 ] ; then 
		echo "** MD5 matches **" ; 
	else 
		echo " ********** ERROR: MD5 DOES NOT MATCH **********" ; fi
}
With the same sort of results:
$ ckmd5 ~/Desktop/Inbox/GoogleChrome.dmg  520e8730b8d1551db45eb56649473267
** MD5 matches **
This allows you to create other commands that might automate grabbing files and comparing the checksums.

[ Reply to This | # ]
Applescript droplet to get the SHA1 checksum
Authored by: mech14 on Jul 24, '10 06:27:37PM

I didn't see this mentioned here, so I'm mentioning it.

muCommander (platform independent Finder/Explorer/Nautilus alternative), which is Java based has the option to calculate many hash keys (SHA1 is only 1 of the many). You can even calculate this on multiple files in a folder.

Awesome app. Also allows for viewing zip/rar files without unzipping them first. You can even delete/add files to the zip without unzip/rezip!!!

Just found this awesome app a few days ago after getting tired of Finder's inadequacies.
MEch



[ Reply to This | # ]
Applescript droplet to get the SHA1 checksum
Authored by: rsnake on Mar 02, '11 10:27:47AM
There's a typo in the code for droplet. It should be
do shell script "/usr/bin/openssl sha1 " & quoted form of POSIX path of chosenFile
instead of
do shell script "/usr/bin/openssl sha1" & quoted form of POSIX path of chosenFile
So the whole script should be:

-- if applet is double-clicked
set chosenFile to choose file with prompt "Select the file to checksum:"
do shell script "/usr/bin/openssl sha1 " & quoted form of POSIX path of chosenFile
display dialog result buttons {"OK"} default button "OK"

-- or if the file is drag and dropped
on open chosenFile
	do shell script "/usr/bin/openssl sha1 " & quoted form of POSIX path of chosenFile
	display dialog result buttons {"OK"} default button "OK"
end open
This works fine in 10.6

[ Reply to This | # ]