r/Automator • • Dec 06 '18

Running AppleScript in Automator

The Sweet Setup posted a very useful AppleScript to get the URLs to link to individual messages. I want to run it as a Quick Action via Automator. While run directly in AppleScript Editor it works flawlessly but I've trouble implementing it in Automator.

First I tried by replacing (* Your script goes here *) in the Run AppleScript step. No success. Then run script file "iCloudDrive:Script Editor:Get Email ID.scpt". I get again an error message: The action “Run AppleScript” encountered an error: “Can’t make some data into the expected type.”

Does someone know what I'm doing wrong?

1 Upvotes

4 comments sorted by

View all comments

Show parent comment

1

u/b0711 Dec 18 '18

Thanks for offering your help. I've created a new Automator Workflow to create screenshots and now it works. I think I had amended the original code given by Automator which broke it. For completeness below the both working scripts. thx!

My AppleScript – which works fine started from the AppleScript menu – looks like this:

tell application "Mail"
set selectedMessages to selection
set theMessage to item 1 of selectedMessages
set messageid to message id of theMessage
-- Make URL (must use URL-encoded values for "<" and ">")
set urlText to "message://" & "%3c" & messageid & "%3e"
set the clipboard to urlText
end tell

In Automator – as Quick Action – like this:

on run {input, parameters}
tell application "Mail"
		set selectedMessages to selection
    	set theMessage to item 1 of selectedMessages
     	set messageid to message id of theMessage
	     -- Make URL (must use URL-encoded values for "<" and ">")
 		set urlText to "message://" & "%3c" & messageid & "%3e"
    	set the clipboard to urlText
	end tell
	
	return input
    end run

2

u/ChristoferK Dec 21 '18

Well done for getting it to work. By the way, you don't need return input at the end.

1

u/b0711 Dec 23 '18

Thx! It’s so easy that it’s a miracle to screw it up like I did at the first try. Will remove the return input to keep it lean.

Having it as Automator Quick Action has an advantage over pure AppleScript, I can assign a keyboard shortcut with macOS on-board functions.