2

I am trying to write a workflow that will use Shell to apply SHA256 to cells in an Excel spreadsheet.

The Workflow (which may be a bit of a hack) is working, but only when I click through it using "Step" - if I try to Run it or Loop it, the output is not the SHA256 hash but the original input.

Any ideas? As this seems really weird.

EDIT: Thanks to @Graham Miln I eventually got this working in AppleScript alone without Automator.

enter image description here

enter image description here

  • 1
    Can you please fix your screenshots? Linking to Dropbox doesn't work, it's better to upload them to AD directly (which you can do from the "add picture" dialog). – nohillside Nov 10 '15 at 9:48
0

The behaviour you describe suggests a timing issue. One or more steps are not completing before the next step begins.

Consider combining all the steps into a single AppleScript. You can use the do shell script command in AppleScript to call out to shasum:

-- Get value to hash from clipboard
set myValue to the clipboard

-- Build the command to execute
set hashCommand to "echo -n " & quoted form of (myValue) & " | shasum -a 256"

-- Debug check the command; comment out when it looks good
display dialog hashCommand

-- Execute command and place on clipboard
set myHash to do shell script hashCommand
set the clipboard to myHash

The clipboard is accessible by AppleScript:

display dialog (the clipboard)

As a single AppleScript, you can debug using Applications > Utilities > Script Editor and gain much better insight into what is happening as the script runs.

  • That's really helpful, thanks. I've now boiled it down to the much simpler looking display dialog (the clipboard) set myValue to (the clipboard) set myHash to do shell script "echo -n " & quoted form of myValue & " | shasum -a 256 | pbcopy" display dialog (the clipboard) But something's wrong with the way the value is being passed into the Shell script because the output clipboard value isn't the right hash... (it is a hash, though) – hyperflux7 Nov 10 '15 at 11:39
  • The | pbcopy pipe is not required. do shell script is passing back the result of shasum into myHash. Use something like set the clipboard to myHash after creating the hash. – Graham Miln Nov 10 '15 at 12:27
  • The AppleScript in the answer has been extended with comments and clipboard interactions. – Graham Miln Nov 10 '15 at 12:35
  • Ok, apologies for not knowing much AppleScript but I now have set myValue to "1" set myHash to do shell script "echo -n \"" & quoted form of (myValue) & "\" | shasum -a 256" set the clipboard to myHash display dialog (the clipboard) and this does not produce the SHA256 hash of 1. If I remove shasum -a 256 from the Shell line, the output is -n '1' , suggesting a problem with how the value is passed into the Shell script? – hyperflux7 Nov 10 '15 at 12:44
  • Please can you edit your question to include your AppleScript, the hash you are getting for 1, and the hash you expect to see. This will make it easier to answer and may attract others to also help. – Graham Miln Nov 10 '15 at 12:53

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .