Sub topic 7
Receiving files and text with Shortcut Input
This chapter assumes you can build a multi-step shortcut, use variables, and recognize content types such as text and files. You will make a shortcut accept content from Finder or another app, and then process it.
What Shortcut Input is
Shortcut Input is the content a shortcut receives when something else starts it. If you select three files in Finder and run a Quick Action, those files become the Shortcut Input. If you run the same shortcut from the menu bar with nothing selected, the input is empty.
Shortcut Input is a magic variable. You can drop it into any action's parameter, and it carries whatever the caller supplied.
Choosing what the shortcut accepts
Open the shortcut in the editor and open its details (the i button in the toolbar). The Details tab has the setting for accepted input types.
- Under Receive, choose the content types the shortcut accepts, such as Files, Text, URLs or Images.
- Turn on Use as Quick Action and Finder if you want it to appear in Finder.
- In the first action, the "Receive ... input from ..." line lets you choose what happens when no input arrives. Typical choices are Stop and Respond, Ask For, or Continue.
A worked example: report file sizes
This shortcut receives files from Finder and shows how large each one is.
- Create a new shortcut named File Sizes.
- In the details, enable Use as Quick Action and Finder. Set the accepted type to Files.
- Add a Repeat with Each action. Set its input to Shortcut Input.
- Inside the loop, add Get Details of Files. Set it to get File Size from Repeat Item.
- Add Add to Variable and name the variable
Sizes, using the file size result as the value. - After the loop, add Show Result and place the
Sizesvariable in it.
In Finder, select a few files, Control-click, and choose Quick Actions and then File Sizes. The result shows each size.
Text input
Text arrives the same way. Select text in any app, then choose Services from the app menu, or use the shortcut from the Share menu if you enabled it. The shortcut receives the selection as Text.
A common pattern is to handle both text and files in one shortcut. Put an If action first and test whether Shortcut Input has any value. When it does not, use Ask for Input or Select File as a fallback. That lets the same shortcut work from a Quick Action and from the menu bar.
Common errors
| Symptom | Likely cause | Fix |
|---|---|---|
| Shortcut is missing from Finder Quick Actions | Finder is not enabled, or Files is not an accepted type | Enable them in the shortcut details |
| "Nothing to repeat with" or an empty result | The shortcut was run with no selection | Add an If check, or set the no-input behavior to **Ask For** |
| Output shows a file name instead of its contents | The file was passed as a file object, not text | Add **Get Text from Input** to read the contents |
| Only the first item is processed | An action got the whole list but handles one item | Wrap the action in **Repeat with Each** |
| Shell script gets an unexpected path | Input passed as stdin instead of arguments | Set **Pass Input** to match your script |
Checking the input type
Not every action expects the same kind of content. If an action does not accept what it receives, Shortcuts tries to convert it. Files can become text, and rich text can become plain text. The conversion can lose information. Use Get Details of Files for metadata and Get Text from Input for contents, and check the result of each step before you rely on it.
Exercise
You built a shortcut that accepts Files and enabled it as a Finder Quick Action. When you run it from the menu bar, it stops with an error. What setting changes this, and what would you add so that the shortcut still works without a selection?
Show answer
Set the no-input behavior in the first action to Ask For (for example Files), or add an If action that checks whether Shortcut Input has a value and then uses Select File as a fallback. Either way, the shortcut asks the user for a file when nothing was passed in.
Exercise
In the File Sizes example, why does the Get Details of Files action use Repeat Item instead of Shortcut Input?
Show answer
Inside the loop, Repeat Item is the single file currently being processed. Using Shortcut Input would pass the whole set of files on every pass, so each pass would not report one file's size.