To read a local Markdown file’s contents in Mac Shortcuts, convert the file input to text before using it. Check the result with a disposable sample; if conversion fails, read the file with cat and pipe its contents into the shortcut.
This walkthrough is for selecting one local Markdown file in Finder and displaying its literal source text, including heading markers and list punctuation. The useful distinction is between three things: the selected file, its pathname, and the text stored inside it.
Why does the shortcut receive a file instead of its text?
Finder supplies file input. Apple defines Files and Text as separate Shortcuts input types: a file can be a document of any kind, while text is plain text without applied formatting. Accepting a Markdown file therefore does not, by itself, establish that the next action receives its contents as text. Understanding input types in Shortcuts on Mac.
Shortcuts uses its Content Graph to convert between types when actions require it. Apple also documents an explicit control: click a variable token and change its Type. That conversion is different from choosing a property such as a file’s name. A name or pathname is still only a description of the file. The Content Graph engine, Adjust variables in Shortcuts on Mac.
Apple’s cited guide explains the conversion mechanism but does not promise that every file carrying an .md extension will convert to its source text. Treat conversion as something to verify with known contents. The command-based method below provides an explicit file-reading path when the native conversion does not produce the expected text.
Create a disposable Markdown file with known contents
Use this synthetic fixture so that a filename cannot be mistaken for a successful read. Paste the complete setup into Terminal. It creates a new temporary directory, writes one example file, and opens that directory in Finder.
demo_dir=$(/usr/bin/mktemp -d /tmp/markdown-shortcuts.XXXXXX) &&
printf '%s\n' '# Sample board' '' '- Blue square' '- Green circle' > "$demo_dir/sample.md" &&
/usr/bin/open "$demo_dir"
The expected file contents are:
# Sample board
- Blue square
- Green circle
The -d option tells mktemp to create a directory, and the trailing X characters allow it to choose a unique name. Each successful setup therefore gets a fresh directory. If creation fails, the && chain prevents the later commands from running. Apple distributes the relevant mktemp manual.
The printf command writes the synthetic lines, including the blank line. Its output redirection creates sample.md inside the new directory. Ordinary > redirection can overwrite an existing file, so keep this setup intact rather than changing its destination to an existing document. The new directory supplies the name-collision protection for this example. Apple’s printf manual, Shell Input and Output.
Build a Finder shortcut that explicitly requests text
Create a shortcut named Read Markdown Text. Apple documents creating a shortcut with the toolbar’s add button, naming it, and adding actions from the action library. Create a custom shortcut on Mac.
Set up its Finder entry point:
- Open the shortcut’s
Detailspanel. - Enable
Use as Quick Actionand selectFinder. - In the input block at the top of the editor, allow
FilesandText. Files support the Finder workflow; text supports the Terminal fallback below. - For missing input, choose
Stop and Respondand enterSelect one example Markdown file.
Apple documents the Finder option and notes that file or folder input may be necessary to enable it. Its input configuration also supports stopping with a response when nothing is received. Run a shortcut while working on your Mac, Limit the input for a shortcut.
Now add the content-processing actions:
- Add a
Textaction. - Put only the
Shortcut Inputvariable in its text field. - Click that variable token, open its
Typemenu, and selectText. Avoid selecting a filename property. - Add
Quick Lookafter theTextaction, using theTextaction’s output.
The explicit variable conversion requests text at the point where the input is consumed. The following Text action output is the value to use in later text-processing steps. Apple documents changing variable types through the variable editor. Adjust variables in Shortcuts on Mac.
For confirmation on your installed version, Control-click an action’s icon and choose Show Info. Apple documents this as the way to inspect an action’s accepted inputs and resulting outputs. This is particularly useful when adapting an existing shortcut containing several file and text variables. Navigate the action list in Shortcuts on Mac.
In Finder, select only sample.md, Control-click it, and choose Quick Actions, then Read Markdown Text. Apple documents that invocation method. If the shortcut is missing, first check its Finder setting and accepted input types. Run a shortcut while working on your Mac.
A successful result contains # Sample board and both list items. Seeing only sample.md or its directory path does not pass this check. Apple recommends placing Quick Look between actions to inspect the content flowing through a shortcut. Testing your actions in Shortcuts on Mac.
If conversion fails, read the contents before calling Shortcuts
Use Terminal to make the read operation explicit. Apple’s Terminal guide identifies cat as a tool for viewing text-file contents. Its Shortcuts command-line guide distinguishes file input supplied with -i from text supplied through a pipe. View text files in Terminal on Mac, Run shortcuts from the command line.
The following is a continuation of the setup example, not an independent program. Run it in the same Terminal tab after the setup succeeds, with the shortcut saved under the exact name Read Markdown Text:
(
set -o pipefail
if [ -f "$demo_dir/sample.md" ] && [ -r "$demo_dir/sample.md" ]; then
/bin/cat "$demo_dir/sample.md" |
/usr/bin/shortcuts run "Read Markdown Text"
else
printf '%s\n' 'The example file is missing or unreadable.' >&2
exit 1
fi
)
Here, cat reads the file and writes its contents to standard output. The pipe delivers those contents to the shortcut. Quoting the pathname keeps it together as one argument. The -f and -r checks require an existing regular file that is readable. Command Line Primer, Apple’s test manual.
The parentheses limit the shell-option change to this command group. pipefail makes a failed pipeline stage visible in the group’s exit status. The preliminary checks do not guarantee that a file remains available throughout a later read; if cat encounters a read error, inspect that error rather than accepting a partial preview as complete.
This fallback changes the shortcut’s incoming content from a file to text. It does not rename the Markdown file or create a converted document. The existing Text and Quick Look actions can inspect that incoming text.
These three command shapes have different meanings:
| Command shape | What the shortcut receives |
|---|---|
shortcuts run "Read Markdown Text" -i "$demo_dir/sample.md" |
File input; conversion is still needed inside the shortcut. |
printf '%s\n' "$demo_dir/sample.md" | shortcuts run "Read Markdown Text" |
The pathname as text. |
cat "$demo_dir/sample.md" | shortcuts run "Read Markdown Text" |
The file’s contents through standard input. |
The table illustrates Apple’s documented distinction between passing file paths with -i and passing text through a pipe. The operation before the pipe determines whether that text is a pathname or the document body. Run shortcuts from the command line.
Diagnose the result before adding more actions
Use the known fixture to decide what to fix:
- Only a filename appears: Check whether the variable is extracting a name property instead of requesting text.
- Only a pathname appears: Check whether the command prints the path instead of reading the file.
- Native conversion fails, but the Terminal method works: Use the explicit read method for this workflow; changing an input label alone has not solved the conversion.
- No input is received: Run from the selected Finder file or the documented Terminal command. Launching a shortcut from the Dock does not automatically supply the selected file.
- The source is blank: Compare against the fixture. A valid empty file and a missing file are different conditions.
Apple documents variable properties separately from content-type conversion, and notes that shortcuts launched from the Dock can receive no initial input. Those distinctions help locate the failure before changing later actions. Adjust variables in Shortcuts on Mac, Limit the input for a shortcut.
Keep the workflow limited to one small local text file while testing. Multiple selections need a separate decision about processing each file or combining their contents. This example establishes readable source text; it is not a byte-for-byte file-copy procedure.
Once the preview contains the expected heading and list lines, connect subsequent text-processing actions to the Text action’s output. Keep the synthetic fixture until that complete path works, then remove its disposable directory in Finder. The essential checkpoint is simple: the next action must receive the document body you verified.
Sources
Understanding input types in Shortcuts on Mac — Apple Support.
The Content Graph engine in Shortcuts on Mac — Apple Support.
Adjust variables in Shortcuts on Mac — Apple Support.
Create a custom shortcut on Mac — Apple Support.
Run a shortcut while working on your Mac — Apple Support.
Limit the input for a shortcut when run from another app on Mac — Apple Support.
Navigate the action list in Shortcuts on Mac — Apple Support.
Testing your actions in Shortcuts on Mac — Apple Support.
View text files in Terminal on Mac — Apple Support.
Run shortcuts from the command line — Apple Support.
Command Line Primer — Apple Developer Documentation Archive.
Shell Input and Output — Apple Developer Documentation Archive.
mktemp(1): make temporary file name (unique) — Apple Open Source Distributions.
printf(1): formatted output — Apple Open Source Distributions.
test(1): condition evaluation utility — Apple Open Source Distributions.