-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsha256sum.applescript
84 lines (64 loc) · 2.39 KB
/
sha256sum.applescript
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
(*
AppleScript to calculate the sha256sum by [email protected] 2019
*)
-- if applet is double-clicked
set chosenFile to choose file with prompt "Select file to SHA256Sum:" of type {"IMG", "ISO", "DMG", "OVA"} default location "/Users/thomas/Downloads" without multiple selections allowed
calculate_check_sum(chosenFile)
-- or if the file is drag and dropped
on open chosenFile
if (count of chosenFile) = 1 then
calculate_check_sum(chosenFile)
else
display alert "Multiple selections are not allowed!" giving up after 5
end if
end open
-- calculate sha256sum and evaluate against given value
on calculate_check_sum(chosenFile)
-- get filename
set fileName to name of (info for chosenFile)
-- get the sha256sum from webstite
set checkSum to the text returned of (display dialog "Paste SHA256Sum" default answer "" with title fileName)
--To do:
-- show progress bar
(*
-- Update the initial progress information
set theItemsCount to 1
set progress total steps to theItemsCount
set progress completed steps to 0
set progress description to "Processing file..."
set progress additional description to "Preparing to process."
repeat with a from 1 to 1
-- Update the progress detail
set progress additional description to "Calculating check sum " & a & " of " & theItemsCount
*)
-- Calculate checksum
set checkSumResult to first word of (do shell script "/usr/bin/shasum -a 256 " & quoted form of POSIX path of chosenFile)
(*
-- Increment the progress
set progress completed steps to a
-- Pause for demonstration purposes, so progress can be seen
delay 1
end repeat
-- Reset the progress information
set progress total steps to 0
set progress completed steps to 0
set progress description to ""
set progress additional description to ""
*)
-- compairing check sums
ignoring white space
checkSumResult = checkSum
end ignoring
set checkSumComp to result
-- setting & formating display text
set displayText to checkSum & "
" & first word of checkSumResult & "
"&"
"
-- show checksum results to user
if checkSumComp = true then
display dialog displayText & "SHA256Sum OK!" buttons {"OK"} default button "OK" with title fileName
else
display dialog displayText & "NB! No SHA256Sum match!" buttons {"CANCEL"} default button "CANCEL" with title fileName with icon caution
end if
end calculate_check_sum