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.
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 ).
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.
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):
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.
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.
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?
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?
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.