A syntax definition for getting more value from contact wiki-links

Inspired by another recent thread, I’ve been noodling with my syntax definition this morning.

My default syntax is GitHub MultiMarkdown with a few small tweaks to define wiki-link prefixes to run Shortcut actions (e.g. [[sc:Shortcut name]]), run Drafts actions (e.g. [[ax:Drafts action name]]), open an iThoughts map (e.g. [[map:iThoughts document name]]), search in GoodTask (e.g. [[gt:Text to find in GoodTask]] - that text could be a task title, or a project reference, a tag…).

This morning, I added [[@:Name]] for some slightly more nuanced functionality when referring to people. A tweak in the definition file:

"@": "drafts://x-callback-url/runAction?text=[[value]]&action=People",

…calls an action containing the following:

name = draft.content
let o = ["filter references", "view contact details"];
// create a prompt
let p = new Prompt();
p.title = name;

// buttons from array of options defined above
for(let btn of o) {
// display prompt
if (p.show()) {
    // display selected item...
    if (p.buttonPressed == "filter references") {
    		url = "drafts://x-callback-url/runAction?text=fromWikiLink:" + encodeURI(name) + "&action=" + encodeURI("Block level filter (MGCL/search)")
    } else if (p.buttonPressed == "view contact details") {
    		url = "x-cardhop://parse?s=" + encodeURI(name)

In effect: tapping on a person’s wiki-link invokes a prompt that offers two options: “filter references” and “view contact details”. The first option calls a block level filter / search action I’ve mentioned in another post. The second option opens Cardhop, using the name supplied as a search term to find details for that contact.

I’ve paired this with a simple shortcut that allows me to insert this style of wiki-link from my list of contacts, but because I’m so used to using the @ symbol to refer to people (among other things) the syntax is easy to generate on the fly without depending on much else.

Miscellaneous notes:

  • There are cascading dependencies here— a syntax definition that requires an action that depends on another action and an additional application. Easy for me because I already have all the referred to elements in place, but might be a little onerous for some! If anyone’s interested in this but doesn’t feel confident about making their own adjustments, I’ll consider posting the actions and syntax definition to make it easier to experiment with.
  • The Cardhop integration might be a dealbreaker for anyone who doesn’t have that app installed. Not sure about alternatives– can’t find much info on a URL scheme for Apple’s Contacts app…
  • The adjustment in the syntax definition file also requires an accompanying update to the RegEx “match” line in that file— mine (with all my adjustments) looks like:
    "match": "(\\[\\[)(((d|u|s|w|gt|map|node|google|wikipedia|bear|url|sc|ax|sx|@):)?([^\\[]+?))(\\]\\])",

I think I seriously need to look into syntax file hacking, :relaxed: that looks awesome.

I think if I actually wanted the contacts functionality without Cardhop I’d probably just try to write myself a Shortcut to display the contact info with some options to call/message/navigate to etc.

BTW, love that block search action - almost the only thing I use these days when I’m searching.

1 Like

It’s cool stuff. The biggest stumbling block for me here is the work with regular expressions. Thankfully, you don’t need much of that to extend wiki-links… :sweat_smile:

Ah yes— that’s pretty much what I was doing before this…

Big grin. I’m glad to hear it’s useful!

I’m actually thinking about a slight mod to block search, to offer the title of the draft as a search option. That’d make it work as a backlink action as well. Haven’t had time to look into it yet, though.

Ha! Ironically, the block level filter action evolved from a backlinks action I was working on. Haven’t updated that since I moved on to the block level filter, and I’m sure there are a few things I could/should fold back into it, though it’s functional. I had separate actions for linked and unlinked references, with an option to flip between the two. If you get yours to a point you’d be comfortable sharing, I’d be curious to see how you tackle it; alternatively, I’d be happy to share what I’ve got thus far if that would be helpful.

I’d love to see it, :relaxed:. I haven’t actually come up with anything very useful yet, to be honest. I’ve got Greg’s backlinks action, and a version I came up with that does the same thing but creates a workspace instead, which comes in handy when I want to work with them and don’t want to run the action repeatedly.

As for unlinked mentions, I’m still doing that by hand. Basically a query on the phrase excluding the phrase in brackets.

This works ok, but but my own notes use a lot of prefixes in front of titles, so I haven’t had time to write an action, since it’d probably involve removing those first etc etc. I’ve actually been a bit distracted by creating my own bullet journal system in Drafts, which I might write up at some point, so my notes actions right now are a mess.

Change of plan. It didn’t take much to update the action with backlinks in mind…

(Block level filtering/querying aka another option for searching for things in Drafts - #8 by jsamlarose)

This basically brings all three actions (block level filter, backlinks, unlinked references) together in one. Thanks for nudging me in that direction!

If you were thinking of something different, let me know…

1 Like

This is pretty much exactly what I was thinking of, :relaxed:. Once again, you’ve let me check off a task without writing a line of code. This is starting to be a trend.


LMAO. Just so happens I’m in a very “make all the things work now” kinda mood…!

The one thing I’ve had to change is where it displays the whole draft. I’ve got far too many full length articles in markdown for this to be at all practical, :scream:

Yeah— I figured that might be an issue in some cases. What are you currently doing when a search term is contained in a draft’s title? Just leaving the “context” field blank?

…aaaand: new update. I know you’ve already made your edit, but I’ve added an option to control whether full text is displayed or not, via a variable set in the first action step. I like the idea of being able to switch between options without having to dig too deeply into the code, and I figure it’s easier for anyone else who might have a preference for the way this particular feature works… :wink:

Hey, I’m happy to switch to your version, trust me. My edit was brutal.

1 Like