Adapting AppleScript to Automator Service

I’ve found some code from this thread: Microsoft Outlook Script to add attachment that works perfectly (thanks @wasabi) but I want to adapt it to be available in the Share menu, especially in Preview.

I’m struggling with how to take the input parameter in Automator’s Run AppleScript and use that to get filenames into the appropriate variables.

I’ve taken the final working code and pasted it below. I’ve changed “selectedItem” to input but that’s generating an error: "Can’t get name of {alias “Path to selected file”} where Path to selected file is the full colon separated path.

I’m hoping to add functionality to deal with multiple selected files in the Finder and eventually add the ability to compress folders.

But first, I want to get the basics working.

Thanks.

Cheers,
Jon

tell application "Finder" to set selectedItem to item 1 of (get selection)
set theAttachment to selectedItem as alias
set fileName to name of selectedItem

tell application "Microsoft Outlook"
	set newMessage to make new outgoing message with properties {subject:fileName}
	tell newMessage
		make new attachment with properties {file:theAttachment}
	end tell
	open newMessage
	get newMessage
end tell

So, I think I posted that a little too quickly as a bit more poking around, not to mention reading the error message a little more carefully allowed me to at least get the attachment path working.

The script now reads: “set theAttachment to input” and I’ve set the fileName variable to static text for the moment.

So, now onto getting it working with multiple files and showing up in Preview’s Share menu. If anyone has any ideas on that last one, I’d love your input. I did find this thread here: Move Automator QuickAction from QuickActions menu to main context menu, but that doesn’t get it into Preview.

Thanks in advance.

Cheers,
Jon

I’m replying as the author of that “Move Automator” thread. I’m sorry to say I have no idea of how to get anything into Preview’s Share menu!