Things 3 Get URL of notes

I was wondering if there was a way of getting (and opening) the URL of the notes field inside of a things task item? Right now, I have a very "hacky" workaround where I just use keystrokes to do it all but it's definitely more of a hack. I was wondering if anyone knew of a more elegant way of doing this via Apple Script or something? Thanks!

I haven't yet quite understood what you are asking here.

"Get" is a little unclear. Your title suggests at first that you want to find out what the URL string is for a given target, but then the macro you show is apparently opening some (already known ?) URL or other.

The meaning of all the keystrokes is a bit opaque without our having some sense of where you are starting.

Presumably in some (unspecified) view and cursor position within the Things 3 app ?


Stepping back,

  1. Where are you starting ?
  2. Where/what are you trying to get to ?

What is the use case ?

You correct. I updated the question. But, basically, I'm trying to open the URL that is in the note (the majority of my tasks comes from the Spark email app (a mac app) and they have a tight integration with the Things 3 app that allows you to natively save an email as a task in Things 3.

Once the task is in the Things app, inside the note there is the full email and a link back to the readdle spark email app and the link takes you right to the email.

What I was trying to do is to hit a keyboard shortcut (CMD+L) and automatically grab the URL and then open the link through Keyboard maestro.

What will be selected in Things when you want to follow the first link in a note ?

Assuming that it is a to do item, you should be able to:

  1. Obtain the note text with a Keyboard Maestro Execute osascript action (JavaScript or AppleScript).
  2. Somehow extract the first link, if any, in that note text. Easy if it is in Markdown format – trickier, but generally feasible, otherwise.
  3. Open that URL.

Here, using a url-matching regex adapted from this post:

javascript - What is a good regular expression to match a URL? - Stack Overflow

is one approach:

Open first link in note of selected Things3 to do.kmmacros (2.5 KB)


Expand disclosure triangle to view JS source
const
    selectedToDo = Application("Things3")
    .selectedToDos.at(0);

return selectedToDo.exists()
    ? (() => {
        const
            // See https://stackoverflow.com/questions/3809401/what-is-a-good-regular-expression-to-match-a-url
            rgx = /https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)/u,
            matchedURL = selectedToDo.notes()
            .match(rgx);

        return null !== matchedURL
            ? Object.assign(
                Application.currentApplication(),
                {includeStandardAdditions: true}
            )
            .doShellScript(`open "${matchedURL[0]}"`)
            : "No URL recognised in note of first selected item.";
    })()
    : "No to do selected in Things3.";

Use a shortcut to get the contents of the notes field of the given task.

Things 3 has robust shortcut support
image

You get the item, then get it's note, then open the URL. ez peazy

UPDATE: This even works if you have extra text in the field, I just tested the note:

http://google.com
afasdf

and it still worked!