Didn't work as of today on my setup.
Used this ChatCPT prompt:
You are an advanced engineering level user of Keyboard Maestro and scripting languages.
Please troubleshoot the following:
I am trying to follow the instructions in the Keyboard Maestro post here: Pandoc MD to RTF
to convert the markdown on the clipboard to RTF when pasted into a Word document.
I get the following errors:
- Execute a Shell Script failed with script error: Execute a Shell Script failed with script error: [WARNING] Could not deduce format from file extension or
Defaulting to markdown
pandoc: I: withBinaryFile: does not exist (No such file or directory) Defaulting to markdown
- Execute a Shell Script failed with script error: [WARNING] Could not deduce format from file extension or
Defaulting to markdown
Here is the Shell Script I am using:
/bin/bash
export LC_CTYPE=UTF-8
/usr/local/bin/pandoc -t rtf -s I pbcopy
Here is the version of pandoc I am using:
ChatGPT updated the script to this:
#!/usr/bin/env bash
export LC_CTYPE=UTF-8
/usr/bin/pbpaste
| /usr/local/bin/pandoc --from=markdown --to=rtf --standalone
| /usr/bin/pbcopy
And it worked.
Below is the ChatGPT output from the above prompt. I only followed step 2 and it worked.
The rest, along with the explanations, were interesting. I'm unclear about Pandoc or Shell scripts so I have no idea if ChatGPT is accurate or writing nonsense. Take it with a very large grain of salt.
I have ChatGPT set to answer straight without fluff.
Blunt reality check
-
Your shell line is wrong. I and pbcopy are being treated as file names. Pandoc looks for a file literally called I, canât find it, and throws the withBinaryFile error. The â[could not deduce format]â warning pops up because, once the file lookup fails, Pandoc has no file-extension to guess the input format from.
-
Pandoc has to read from stdin and write to stdout, then you push the result back onto the clipboard. The classic, working pipeline is:
#!/usr/bin/env bash
export LC_CTYPE=UTF-8
/usr/bin/pbpaste \
| /usr/local/bin/pandoc --from=markdown --to=rtf --standalone \
| /usr/bin/pbcopy
-
- pbpaste dumps the current clipboard to stdin.
- pandoc converts Markdown â RTF on stdout (no temp file needed).
- pbcopy stuffs that RTF back onto the clipboard as the correct public.rtf flavour. This is exactly the pattern shown in the original forum thread and in other Pandoc clipboard tutorials.
- Keyboard Maestro macro tweaks
| Action |
Setting you need |
| Execute Shell Script |
âIgnore Resultsâ (donât pipe the scriptâs output back into KM â pbcopy already handled the clipboard) |
| Shell |
â/bin/bashâ (or /usr/bin/env bash) |
| Pass input |
âNothingâ |
| Path to pandoc |
/usr/local/bin/pandoc on Intel Macs, /opt/homebrew/bin/pandoc on Apple-silicon unless you linked it into /usr/local/bin. |
- Version is fine; path may not be. 3.7.0.2 supports RTF output. If which pandoc in Terminal shows a different path, point KM to that path or add it to PATH in the first line of your script:
export PATH="/opt/homebrew/bin:/usr/local/bin:$PATH"
- Why the flags?
- --from=markdown silences the âcould not deduce formatâ warning.
- --standalone (-s) makes Pandoc emit complete RTF with the needed headers; Word is happier with that.
- You donât need an explicit -o because stdout is piped straight into pbcopy.
- Quick test outside Keyboard Maestro
pbpaste | pandoc -f markdown -t rtf -s | pbcopy
open -a "Microsoft Word"
# âV â rich-text paste should work
If that behaves, the macro will behave.
- Still stuck? Checklist
- Run the script in Terminal firstâconfirm no errors.
- Make sure KMâs Execute Shell Script action is set to ignore its results.
- Verify pbpaste actually contains Markdown (use pbpaste | head to peek).
- Confirm that Wordâs paste is set to keep source formatting (Word > Preferences > Edit).
Thatâs itâfix the pipeline, kill the bogus arguments, and the macro will just work with Keyboard Maestro.