Rich text, clipboard actions have different behaviors between iOS and macOS

I found this today, while trying to get more mileage out of Notes (maybe there’s a better tool).

TLDR: on macOS, make rich text and clipboard actions give me a system file path instead of an actual rich text. (oh, and notes URLs are different on iOS and macOS)

I’m following this tutorial from Tom Twardzik on How to Create Deep Links to Specific Apple Notes on iOS (and yes, I know it says iOS). It appears to work on iOS, but I see some really weird results running the same shortcut on macOS[1].

The shortcut uses the Content Graph to allow us to access the internals of the note data and copy it to the clipboard. From there, we match the note’s direct link URL, plug that into link markdown and convert that to rich text which gets sent to the clipboard. It’s kludgy, but it works.

FIrst I noted that the URL for a note changes between iOS and macOS. The format on iOS is:

mobilenotes://showNote?identifier=00000000-0000-0000-0000-000000000000

The same note in macOS leaves off the mobile at the beginning of the URL (the UUID for the note remains the same, thankfully):

notes://showNote?identifier=00000000-0000-0000-0000-000000000000

I changed the regex in Tom’s shortcut to accommodate both:

(?:mobile)?notes:\/\/.*(?=;)

Now that we have the URL, we have to get it into rich text, and here’s where things appear to go sideways on the Mac. Here’s the last part of my shortcut (from iOS)

On iOS, I get a rich text link with the correct URL that I can paste into anything. On macOS, the output seems to be a filesystem path to an html file, with the link to the note sort of embedded in that path:

/var/folders/t6/svhh2wf55j5799sj9vht_2dc0000gn/T/com.apple.WorkflowKit.BackgroundShortcutRunner//[New test](notes:::showNote?identifier=00000000-0000-0000-0000-000000000000).html

I can go to that folder (/var/folders/t6/svhh2wf55j5799sj9vht_2dc0000gn/T/com.apple.WorkflowKit.BackgroundShortcutRunner), but there’s nothing there.[2] Certainly, it doesn’t paste into notes or any other app as expected.

My best guess is that the HTML file referenced contains the rich text generated from the Make rich text from markdown action, and somehow in macOS I’m getting a reference to the file rather than its contents.

I don’t suppose there’s a fix for this? or a better way to grab that notes:// URL?

[1] Versions for the curious
Mac Shortcuts 5.0 (1146.16)
macOS 12.5 (21G72) on MacBook Pro 15,1 (I9)
iOS 15.6 on iPhone 13 Pro Max

[2] I’m an old UNIX/Linux hack, so not afraid of this stuff, but I’m deep in the bowels of special macOS directory structure and I don’t know where to find docs

1 Like

I will be following this thread closely to see if someone has a solution. My experience says there isn’t one, and the problem is with the Make Rich Text from Markdown action. Even a minimal shortcut like this

fails. Running it and then clicking on the eyeball button in the result box that appears below the second action gives this,

which makes no sense.

If I add a Copy to Clipboard action to the end of this shortcut, I get, as @DonFaulkner does, a path to a file deep in the /var subdirectory. The path isn’t quite right (it’s missing the last subfolder), but there is a file down there with the name

[a link](https:::leancrew.com).html

and the HTML contents

<p><a href="https://leancrew.com">a link</a></p>

This is what I’d expect from a Markdown-to-HTML conversion, but it isn’t rich text on my clipboard.

I will be happy to learn that I’m missing something simple,

Rich Text conversions in Shortcuts have been problematic this past year, and this is just one of several examples of these issues. Sometimes adding the Get Clipboard action at the end coerces things to work (I’ve certainly had more luck with this on i*OS than macOS), sometimes it does not. Some previous issues have been resolved, but some remain.

Here’s a quick shortcut that shows three conversion paths.

The first is Markdown -> Rich Text. This is in effect the same demonstration as above that something rather buggy is occurring, and instead of the rich text content, an intermediary HTML file is being picked up. To me that suggests an issue with the underlying conversion engine that Shortcuts uses to switch between object types as viewable in the View Content Graph action.

The second is HTML -> Rich Text. For me, on my Mac (not running any beta OS), this works as expected. I can paste the result into an app supporting rich text and it looks just fine.

On that basis, the cumbersome workaround is to not convert the Markdown directly to rich text, but to go via HTML as an intermediary … which I believe what should happen with the Markdown to rich text conversion. BUT, to convert Markdown to HTML, since the Workflow days we’ve always gone via rich text; so it siounds like this would fail as we’d hit the same issue on the rich text conversion.

Except, we don’t because we’re keeping the conversion flow going within Shortcuts, so we can get away with it, the temporary HTML file remaining available for the subsequent conversion step (the path error seen is becuase the intermediary file is no longer available to the receiving app - as per the details in the original post).

The third option is therefore Markdown -> Rich Text -> HTML -> Rich Text, and for me that yields the desired conversion result.

https://www.icloud.com/shortcuts/244ff5ac7ad84e6daed5a04a35879de7

Give the three tests a try and compare the results. See if you get the same as me and if you can use the workaround until the functionality works as expected. Hopefully, the bug squashing efforts continue within Apple for these outstanding issues, and things will continue to settle down.

Hope that helps.

2 Likes

Thank you! It would never have occurred to me that a pipeline of conversions that starts with a conversion that does not work could somehow work in the aggregate.

After reading your solution and incorporating it into my test shortcut (which then worked), I noticed that Drafts provides a Markdown to HTML action. So if @DonFaulkner has Drafts installed on his devices, he could do a Markdown→HTML→Rich Text conversion using that action. Like this:

Advantage: one less step
Disadvantage: requires a third-party app

1 Like

Once we’re going to convert to rich text from HTML, why bother with the Markdown stage at all? Instead of creating a Markdown link from the match, why not create a HTML link instead? It’s just text, too, and nearly as simple to create.

Here’s my version, taking that approach.

One less step, and doesn’t require a third-party app.

https://www.icloud.com/shortcuts/2f4e2c2ed1724cb28898c97eacb65005

(I also renamed my magic variables, because OCD…)

Thanks for this! I thought I was losing my mind! I was referred here by the good Dr. Drang from the Mac Power Users forum. I’ve had good experience with using Drafts to prep the text for conversion. In my version, I also used another third-party app (Text Case), which has a shortcut action “Replace” to convert wiki-links ([[ and ]]) into bold italics, since I rarely want those in something that’s being exported to RTF, but I do want to be able to see key phrases.

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

Hey. I am trying to automate email generation extrating data from data jar and then converting the markdown text to rich text using the workarounds posted here. However it only seems to work copying it to the clipboard and then I have to still manually paste it in. Is there a way to get shortcuts to create and send the email converting markdown to rich text without me having to go and paste in the formatted text. Again the ipad version can do this no problem and I can chuck out lots of emails very quickly to all my students. Mac version of shortcuts seems to be more difficult. Any thoughts?

Take a look at Mail Assistant. It can be used without Drafts if necessary. It can take your original Markdown and convert to an HTML email.

Thanks for this - I have installed this and am trying to use it. It’s still not quite what I’m looking for (unless I’m using it wrong). It does make the email formatted correctly but I still have to interact with a window and click send. On the iPad version (using built in Mail), I send 27 formatted emails to all my students (with first names pulled from data jar) with one click and I don’t have to interact with any send dialogue boxes. I just want this to work on both iPad and Mac. (seems to be the trend with Shortcuts, haha). I can post the shortcut if that’s helpful.

I only use it occasionally, I’d forgotten it gets you to confirm the send on each run :confused: That’s definitely going to be a friction point for anything other than small volumes.

If you also had say Keyboard Maestro, you could work around it, but that probably starts to overcomplicate what feels like a straight forward requirement.

On that basis, I had a quick poke around online and while I don’t use Mail as my email app (I use Mailmate), the AppleScript in this post from 2013 looks like it would work. Certainly worth a quick test as it should only take a couple of minutes to give it a try and it incorporates the sending of the mail.

Shortcuts supports AppleScript so you should be able to embed it assuming it is indeed functional for your purposes.

So I’m stuck at the moment. All my bulk emailing and shortcut coolness has to be done on an iPad and I can’t use whichever device I’m working on. Very annoying.

Amazing! This might be the way to go. Thank you! Seems so silly that it works on iPad but not the Mac. I also can’t easily upgrade to Ventura (where it might be resolved) as my cmputer is too old. Very frsutrating. Thank you for your support!