Sub topic 6
Working with text, files and other content types
This chapter explains how the Shortcuts app on a Mac treats the different kinds of data that flow between actions. It assumes you can build a multi-step shortcut and know what a variable and a magic variable are. You should also be comfortable with Finder, files and folders. The chapter shows how Shortcuts decides what a piece of data "is", how it converts one type into another, and where those conversions go wrong.
Why content types matter
Every value that passes from one action to the next has a content type. Examples are text, number, date, file, image, URL and list. The type decides which actions can accept the value and what they do with it.
Many errors that look random come from a type mismatch. A shortcut may ask for a number but receive text. It may expect one file but receive a list of files. It may expect text but receive a file, so you get the file's name or nothing at all.
Shortcuts is forgiving, so most mismatches do not raise an error. It converts silently. This is convenient, but it also means a shortcut can run to the end and give the wrong result.
The main content types
| Type | What it holds | Typical source action |
|---|---|---|
| Text | A string of characters | Text, Ask for Input |
| Rich text | Text with formatting such as bold or links | Make Rich Text from Markdown |
| Number | A numeric value | Number, Calculate |
| Date | A point in time | Current Date, Date |
| File | A file on disk with a name, extension and contents | Get File, Select File, Shortcut Input from Finder |
| Image | Pixel data, often with a file behind it | Take Screenshot, Select Photos |
| URL | A web or file address | URL |
| List | An ordered group of items of any type | List, Split Text |
| Dictionary | Key and value pairs | Dictionary, Get Dictionary from Input |
You can see the type of any result by running the shortcut and tapping the result bubble under an action in the editor. The preview shows the value in a form that matches its type.
Working with text
Building and combining text
The Text action holds a block of text. You can drop variables into it, and Shortcuts joins everything into one string. For example, a Text action containing Report for followed by the magic variable Current Date produces a line such as Report for 27 Nov 2026.
The Combine Text action joins the items of a list into a single string. You choose a separator: a space, a new line, a comma, or a custom value. Its counterpart, Split Text, breaks a string into a list at a chosen separator.
The diagram shows how the two actions convert between a single value and a list.
Changing and checking text
Use these actions for common text jobs:
- Change Case switches between uppercase, lowercase, capitalized and title case.
- Replace Text swaps one string for another. It can use regular expressions if you turn on that option.
- Match Text returns the parts of a string that match a pattern. It returns a list of matches.
- Get Text from Input pulls plain text out of whatever it receives, such as a file or a web page.
Replace Text is case-insensitive unless you turn on the case-sensitivity option. This is a frequent source of surprise when you replace a short word that also appears inside longer words.
Numbers hidden in text
Text that looks like a number is still text until an action treats it as a number. The Calculate action and the Number action both convert it. If the text contains extra characters, such as 12 KB, the conversion can fail or return only part of the value. Clean the text first with Replace Text, then convert it.
Be careful with decimal separators. A value such as 1,5 follows the number formats of your region settings, so the same shortcut can behave differently on a Mac set to another region.
Working with files
What a file value contains
A file value is more than its contents. It carries a name, an extension, a size, a location and a creation date. Shortcuts can pass the file itself between actions, so a later action can rename, move or convert it without you handling a path.
Use Get Details of Files to read a property such as File Size, File Extension, Name or Creation Date. The result is a new value of the matching type: a number for the size, text for the extension, and a date for the creation date.
Getting files into a shortcut
There are several ways to receive a file:
- Shortcut Input receives files that you pass in from Finder or another app. The next chapter covers this in detail.
- Select File opens a file picker when the shortcut runs.
- Get File reads a file at a path that you set in the action. The first time it runs, macOS can ask for permission to access that folder.
- Get Contents of Folder returns a list of the files in a folder.
Saving and changing files
- Save File writes a file to a location. Turn on "Ask Where to Save" if you want a prompt each time. Without it, an existing file with the same name can be replaced or renamed depending on the option you pick. Check this setting before you run a shortcut on files you care about.
- Rename File changes the name but keeps the extension unless you change it too.
- Move File and Delete Files act on the original, not a copy. Test with sample files first.
- Get File from Folder retrieves one file by name from a folder you choose.
Converting between files and text
You can turn a file into text with Get Text from Input, which works for plain-text files and also for formats such as PDF or rich text where Shortcuts can extract text. To create a text file, pass a text value to Make Text File or to Save File.
Be aware of encoding. A plain-text file saved in an unusual encoding can show garbled characters when read back. UTF-8 is the safest choice for files you create.
Lists: one value or many
A list holds several items, and many actions accept either a single item or a list. When you hand a list to an action built for a single item, Shortcuts often runs the action once per item. In other cases it uses only the first item.
This is the most common reason that a shortcut handles one file correctly but a batch incorrectly. To control the behavior, use a Repeat with Each loop. Inside the loop, the Repeat Item magic variable holds the current item, so each action sees one value at a time.
Useful list actions include:
- Get Item from List takes the first, last, random or numbered item.
- Sort orders a list by name, date, size or another property.
- Filter Files keeps only the items that match conditions such as extension or size.
- Count returns the number of items, characters, words or lines in the input.
Converting types on purpose
Shortcuts offers explicit conversion actions, and using them is better than relying on silent conversion.
| Goal | Action |
|---|---|
| Image or document to another file format | Convert Image, Make PDF |
| Text to a number | Number, Calculate |
| Date to text | Format Date |
| Text to a URL | URL |
| Any value to a dictionary or text | Get Dictionary from Input, Get Text from Input |
On a variable, you can also use Get Type to see what the value is, and the variable's options let you pick a property such as Name or File Extension. Choose the property you need in the variable's popup rather than converting through a separate action.
A worked example: counting words in dropped files
This shortcut receives text files and reports the word count of each one. It uses file, text, number and list types together.
- Add Receive input from Quick Actions at the top, set to accept Files.
- Add Repeat with Each, using Shortcut Input as the list.
- Inside the loop, add Get Text from Input. Its input is Repeat Item.
- Add Count with the type set to Words, and its input set to the Text result.
- Add a Text action that contains the Repeat Item name, a colon, and the Count result.
- After the loop, add Combine Text using the Repeat Results, with new lines as the separator.
- Add Show Result.
The conversion from file to text happens in step 3. The conversion from text to number happens in step 4. The list returned by the loop turns into one text block in step 6.
If a file is a type that cannot give text, such as a photo, step 3 returns an empty value and the count is zero. A common safeguard is to add Filter Files before the loop and keep only items whose extension is txt or md.
Common errors
- A shortcut works on one file but fails on several. An action received a list but handled only the first item. Wrap the step in Repeat with Each.
- You get a file name where you expected the contents. The variable is still a file. Add Get Text from Input.
- A number comes out wrong. The text contains units or uses a different decimal separator. Clean it and convert it explicitly.
- A saved file overwrites another. Save File was set to replace. Enable the prompt or add a date to the name.
- File access is denied. macOS blocks access to a folder that the shortcut has not been granted. Allow it when prompted, or review it in System Settings under Privacy & Security.
- Garbled characters appear. The source file uses a different text encoding than the one the action assumed.
Exercise
A shortcut uses Select File to pick several text files, then runs Get Text from Input and Count (Words) once, without a loop. It reports a single word count. Why can the result be misleading, and how do you fix it?
Show answer
The actions receive a list of files at once, so Get Text from Input can combine them into one text value or use only one item, and Count returns one total instead of one count per file. Wrap Get Text from Input and Count in a Repeat with Each loop over the selected files. Then each file produces its own text and its own count, and you can collect the results with Combine Text.
Exercise
You save a report using a file name made from the Current Date, but Save File fails on some runs. What is the likely cause and the fix?
Show answer
The default date text can contain characters such as slashes or colons that are not valid or safe in file names. Pass the date through Format Date with a custom format such as yyyy-MM-dd, and use that formatted text in the file name.