Change variable syntax to accommodate Things 3 URL scheme

variables

#1

I am interested in exploring how I can use KM to integrate with URL schemes in Things 3, which the developers recently made available: https://support.culturedcode.com/customer/en/portal/articles/2803573#link-builder

The issue I’m running into is that these links use a lot of percentage signs, which is the same syntax that KM uses, so those links get messed up (since KM is trying to interpret these percentage signs as variables). Is there some sort of way around this?

For example, a base “create new task with X text” would look like this for the URL scheme:

things:///add?title=test%20to-do%20item%20here

The three percent signs there screw stuff up. Any ideas? Thanks!


#2

Not all KM text contexts process tokens.

One approach, for example, would be to let an Execute JS action:

  1. Perform the url encoding
  2. Open the encoded url

(() => {

    // standardAdditions :: () -> Application
    const standardAdditions = () =>
        Object.assign(Application.currentApplication(), {
            includeStandardAdditions: true
        });

    const strURL = encodeURI(
        'things:///add?title=test to-do item here'
    );

    return (
        standardAdditions()
        .openLocation(
            strURL
        ),
        strURL
    );
})();

#3

Or:

Build and open url.kmmacros (1.9 KB)


#4

and in the options gearwheel at the top right of the open URL action:

47


#5

Yep, just set the Action Gear menu options to “Process nothing”:

image


#6

I hate to bump an old topic, but has anyone gotten this working? I have the exact same URL working in the Shortcuts app, but when I try to run it on my Mac, Keyboard Maestro tells me it's an invalid URL. I've tried setting the action gear for the URL action to both process text normally and process nothing, and both result in the same error.


#7

No worries about bumping the old topic; people do that all the time here. As for your question, it's hard to say what might be going on without seeing the URL in question. Can you share it here, along with the macro you're using to try to open it?


#8

Sure thing. Here's the URL:

things:///add?title=Read%20%Variable%Title%%20by%20%Variable%Author%&checklist-items=Read%2010%25%20of%20%Variable%Title%%0ARead%2020%25%20of%20%Variable%Title%%0ARead%2030%25%20of%20%Variable%Title%%0ARead%2040%25%20of%20%Variable%Title%%0ARead%2050%25%20of%20%Variable%Title%%0ARead%2060%25%20of%20%Variable%Title%%0ARead%2070%25%20of%20%Variable%Title%%0ARead%2080%25%20of%20%Variable%Title%%0ARead%2090%25%20of%20%Variable%Title%%0ARead%20100%25%20of%20%Variable%Title%%0ASave%20Highlights&tags=Read&list=Personal

Like OP, I am trying to pass variables into the Things 3 URL scheme to function as a template. I've successfully made a similar workflow using Shortcuts for my iOS devices. I've also been able to create an Alfred workflow, but I much prefer the interface of KBM.

Here's the full macro.

2018-11-14-screenshot-1

Note: I can copy that same URL onto my iOS device or open it via Google Chrome on my Mac and it works just fine minus passing the actual variables, so there doesn't seem to be an actual issue with the URL but KBM thinks there is.

Also, I've done some testing and KBM seems to have no problem with the first part of the URL. As soon as I enter %Variable%Title% the Open URL text turns orange to report an error.


#9

Thanks for sharing. As you suspected, KM is indeed getting mixed up with the % signs used for variables and the ones used in percent encoding for URLs. The way I'd go about resolving this is to assemble the URL in a KM variable first, run a filter on the entire URL to percent encode it, then open the encoded URL variable:

New Book Project.kmmacros (3.4 KB)
image

Results

52%20AM

This also has the advantage of making it easier to change the resulting to-do item, since you can edit the title, checklist, notes, and other fields in plain text without worrying about hard-URL encoding everything.


#10

Note that Keyboard Maestro itself does not care anything about the format of the URL, however the URL is stored within a system NSURL object, and NSURL will only allow valid URLs, so it is NSURL that is rejecting the URL as invalid.

Also note that if you are processing text tokens (as controlled by the gear menu in the action), then you must deal with the fact that % is special to Keyboard Maestro, and so where you want an explicit % sign in the URL you need to double it, so eg:

…Read%%20%Variable%Title%%%20by%%20…

@gglick’s solution is a better solution, since all the % tokens in the Set Variable action are intended for Keyboard Maestro to process, and all the percent tokens needed in the URL are created by the Filter action.


#11

Sorry for such a late reply on this. The end of the year got away from me with completing my Masters and the holidays. This is exactly what I needed. Thank you so much. Seeing it broken down this way helped me port over all my existing Omnifocus templates and I'm back in business with Things. My workflow and frustration levels thank you!