Shortcuts help?

I need a little help from someone who has more experience with Shortcuts. Here’s what I need to accomplish without my usual Ruby scripting:

Get the path to a directory full of RTF files (from nvALT)
For each file in the directory:

  • run it through pandoc -f rtf -t markdown_mmd
  • do some regex replacements on the results to fix image and wiki syntax
  • save the result to a Markdown file with the same name but with .md extension (replacing .rtf)

I would like the user to be able to select the output folder if possible, but would be fine with hardcoding that if needed.

Anyone want to help me take this on?

1 Like

These are the text substitutions to be made:

gsub(/!\\\[\\\]\(<(.*?)>\)/, '![](\1)')
      .gsub(/\\\[\\\[\[(.*?)\]\(.*?\\\]\\\]/, '[[\1]]')

To replace !\[\](<filename>) with ![](filename) and \[\[[note](nvalt://note)\]\] with [[note]]

I have this all scripted out in Ruby, but I want to make a shortcut available without users having to install Ruby or the Command Line Tools just to convert their old nvALT notes (for people who saved in RTF) to more portable Markdown.

I have some experience with this scenario :sweat_smile: and I think this does most of what you want:

https://www.icloud.com/shortcuts/e7e0b3798935456bb51b267324cf9cd7

P.S. I’ve used the (Shortcuts) native RTF to Markdown conversion as an example, but after re-reading your post, I’m not sure if you also want to replace pandoc. If so, the native conversion might be not good enough, and you would have to go the route of my first link (which I would recommend avoiding if possible :grimacing:).

In this shortcut I pass a json data set and execute a ruby script. The fourth value of a json data set is the file name for a taskpaper file. The command should read something like “append to text file”. Does that make sense here?


As a json data set, I pass the name for the task name_1, path_2 is the path for an md file to process, command_3 is an na command and target_4 is the name of the taskpaper file.

I’ll test the native conversion, it might be perfectly adequate. The biggest issue is that nvALT doesn’t store bulleted lists as RTF list types in all cases, which results in unnecessarily escaped characters.

Thanks, though, I’ll test this out!

I need a for loop to save to separate files, with the original input name with the extension changed. That’s the biggest part that’s tripping me up.


First I make a choice of reports. That is the beginning of the shortcut above. “mit jedem” translates to “with each …” So that is a loop. For each choosen report, I pick a json dataset. That is the following script (na Report Parameter Ruby):

So I would just put it all into a Ruby script. You can use variables directly in the Ruby script.

My shortcut converts and changes the extension in the same loop. And then saves all the files at once in the output folder selected by the user.

If the native conversion is enough, the shortcut can run both in iOS and macOS :slightly_smiling_face:

Thanks everyone for the assist. By combining multiple people’s input I think I have a working solution. @atnbueno mentioned on Mastodon that I could combine all of the regexes into a dictionary… can you share an example that I can play with? I didn’t get it working from the screenshot.

I find Shortcuts rather opaque when it comes to variables, what gets stored where and how it’s accessed when you’re not explicitly declaring vars. For example, I set up a dictionary, populated it, then set up a “Repeat with each item in Keys” action connected to it. When I tried to add a “Get Value for Repeat Item 2 in Dictionary”, the Dictionary variable didn’t show up, and when I got the the “Replace Repeat Item 2 in Dictionary” things got even weirder and it didn’t offer me the Dictionary Value variable. I could use a working example to play with.

Thanks everyone for your assistance!

This should work but I haven’t been able to test it:
https://www.icloud.com/shortcuts/787803e63bf14f25abe0567d89796d25

It may seem overkill for a few regexes, but it allows reordering, changing, inserting, and deleting them much more easily.

About inserting the variables, the “Variables…” submenu is not reliable. “Select variable…” will probably scroll to the wrong point, but it allows inserting any existing variable. Giving them specific names also help.

There is a program called Logger. This creates in a series of print statements to a log file for debugging, to see what is going on in a shortcut.
This is how I realized that dictionaries are actually json and what certain actions are delivering. In German Apple called a dictionary “Wörterbuch”, which is completely misleading.

Oh yeah, Rosemary Orchard recently took custody of that. I should check it out if I’m going to keep banging my head over Shortcuts.

Looks perfect at first glance, will give it a run-through tomorrow. If it works well, this may be the final version that gets published, you ok with that? How would you like to be credited?

No problem and no need to credit me for this. But @atnbueno is fine.

1 Like

The user I’m trying to help before I share this publicly is running into issues where she has corrupted RTF files and then the whole shortcut fails. Is there a way to handle errors? try/catch style?

By reading them as arguments, right? Or does it assign variables in some more accessible way?

In a Shortcuts action, I set variables from previous Shortcuts. In a Ruby script, one would typically use regular Ruby arguments passed to the script. Instead you can directly insert a Shortcuts variable (as an argument) where the Ruby variable is needed using the context menu. Compare the screenshot with the Ruby script I inserted above. I found this to be quite convenient when integrating a Ruby script. With the app Rubyist, Ruby scripts can also be used on the iPhone.

1 Like

Unfortunately there’s no error catching in Shortcuts