Or you can use Python's hashlib
import jmp
import sys, os, hashlib
from pathlib import Path
# Function to open a file and compute it's checksum
def file_cksum(a_filename):
digest = hashlib.md5()
try:
f = open(a_filename, 'rb') # open in binary mode
while True:
t = f.read(8192)
if len(t) == 0: break; # end of file
digest.update(t)
except:
print('file_cksum: Unexpected error: ', sys.exc_info()[0])
else:
f.close()
return digest.hexdigest()
jmp.run_jsl('''
local_path = Pick File("Chose File to checksum");
// Pick Directory on windows returns a leading / use Convert File Path()
If( Host is("Windows"),
local_path = Convert File Path( local_path, windows )
);
Python Send(local_path);
''')
print(local_path)
cksum = file_cksum(local_path)
print(f'MD5 {local_path}: {cksum}')
Using the JSL Pick File(), I selected the above code saved in a file md5_file.py
giving the results:
/Users/_me_/Scripts/md5_file.py
MD5 /Users/_me_/Scripts/md5_file.py: d175790247060d7e415516794660216f