Help passing data in and out of MacOS Shortcuts Applescript

Hi folks,

I would like a little help understanding how to pass data, basically a dictionary, into an AppleScript for search and replace in a Pages document.

The Shortcut Applescript module seems to have some way to pass input/data in and out - but the documentation on how to use it seems to be non-existent. Maybe it’s obvious, and I just don’t get it as a newcomer to AppleScript. But some guidens on how to go about it would be very greatly appreciated.

Here’s the info for the shortcut action.

2021-11-08-15.08.38

It notes “Files” as the input to the script, but it does accept text, so you could coerce your dictionary into a JSON format and pass that in. But then you would have to try and pick apart the text to get the elements you want in a usable format.

I tried just passing in a string of comma separated parameters to the action, and using string delimiters to split the string. However, while this works in my script editor, Shortcuts just kept giving me the whole list as one item. That feels pretty buggy, so I would be tempted to try using an osascript call to a script held outside of Shortcuts that I can test independently.

Expand for the Details

If I run this script in my script editor.

2021-11-08-15.29.41

I get …

2021-11-08-15.30.38

… followed by …

2021-11-08-15.30.49

When I do the same thing, but using Shortcuts to pass the content into the action like this.

2021-11-08-15.28.16

I get …

2021-11-08-15.32.18

… followed by …

2021-11-08-15.32.50

Which seem to be different behaviours given I copied and pasted the core code (just the “on” varies to allow me to test) between the two apps.

As for getting data back, a return seems to do the job just fine.

2021-11-08-15.14.48

I am not sure how accurate the result variable types are as I’m not quite sure how dictionaries would factor in to AppleScript. See my note on lists and object properties being the closest match I can think of to dictionaries in the discussion of episode #86 (third section of the post).