Follow first `message://` URL in text field?

I'd appreciate help to solve a problem I have spent quite some time researching but cannot find an answer. I want to search within a text field to find some text and place the cursor at the start of that found text, but cannot determine how to do this.

To elaborate, I have KM select the text field in an application, I want to locate a phrase within the text field that starts with "message://", I then want KM to place the cursor just before "message://".

Any help on how to achieve this would be greatly appreciated.

Seldom easy to generalise across applications, particularly for:

  1. identifying target coordinates, and
  2. directing cursor movements.

Any particular application(s) ?

What is the problem that you wish to solve in this way ?

1 Like

The application is Banktivity. It has a text note field for each transaction, but no URL field.

I place a URL link to an email message in that note field. The URL link is to the email in Mailmate.
There may be other text in the note field, however the URL is always the last item in the note field. I save the Banktivity transaction.

Later, I wish to select the URL in the note field and open it (which opens the email).
If I manually get the URL selected I have no problem using KM to open the email. (It copies it to clipboard, opens LaunchBar, pastes it and enters, and the email opens).
However, my challenge is getting the URL selected using KM. In part this is driven by the fact that the URL can vary in length depending on the email it is linking to.

I solved a similar challenge where I place the URL to another application (DEVONthink (DT)) in the note field (at the end of the note field in the same way). When I wish to open the link to DT for a transaction in Banktivity, I can get to the DT URL by selecting the note field, moving to the end of the note field (Command-Right Arrow) , then repeating Option-Shift-Left Arrow a certain number of times (to capture each part of the URL - as Option-Shift-Left Arrow only highlights as far as each instance of % or @, etc in the URL) (and always the same number of times for DT URLs) to highlight the URL and then copy it, etc. The reason this works for the DT URL is that DT URLs seem to always be of the same length (and with the same number of %, @, etc characters), so I can just repeat the Option-Shift-Left Arrow routine the requisite number of times to highlight the whole URL and then copy it.

As Mailmate URLs differ in length the approach I use for a DT URL will not work. (When I set a repeat number for Option-Shift-Left Arrow, for some URLs it will highlight in the note field text beyond the full URL and for others, not all the URL text).

I thought if I could search the note field for the first letters of the Mailmate URL (which are always the same), ie. "message://", the search would highlight those letters, I would Command-Left Arrow to the beginning of "message://" and then Command-Shift-Right Arrow to highlight the whole URL and copy it, and via LaunchBar open the URL.

Hence my desire to find a mechanism once the whole note field is selected to search for the start of the URL.

*Edited to correct references to Command-Shift-Left Arrow which should have read Option-Shift-Left Arrow (I have bolded Option where this has been corrected), and to clarify why this keystroke has to be repeated a certain number of times within a URL.

Can you not copy all the text and then, in KM, process that to extract the URL? If it's always the last item in the copied text that should be easy enough:

And to generalise a bit, in case, for example, of:

  1. a message:// url in non-terminal position
  2. more than one message:// url`

you could split the text,

  • first on message:// (discarding anything before it)
  • then on space (and perhaps ")" in case of MD links) pruning chunks (from the first such match onwards)

For example:

Message URLs in clipboard.kmmacros (22 KB)

Expand disclosure triangle to view JS source
.map(x => {

    const match = x.split(/[\s\\)]/ug).filter(Boolean)[0];

    return `message://${match}`;
1 Like

That sounds like a valid solution to me. Did you try doing that manually (without KM)? Does the application allow you to "search" for text in its text note field? If so, then it should be really easy to copy those keystrokes into a KM macro.

The idea is, if you have a method to achieve your goals using keystrokes (and sometimes the mouse) then a KM macro can easily be written to duplicate your keystrokes. But if you have no means of doing something manually, then it can get tricky.

Thank you @Nige_S, your suggestion achieves what I was seeking.

I have never used Regular Expressions before and should add this to my armoury, as I recently did for AppleScript.

Thanks to the terrific contributions to this forum, like yours, I am learning a lot and am encouraged to get better.

Thank you @ComplexPoint for your elaboration on handling multiple URLs.

At first attempt I didn't get this to work, but then found my error and it worked where there was one email URL in the text field.

Unfortunately where there is two email URLs in the text field separated by a space, neither email was returned. When I looked in the Clipboard History Switcher the System Clipboard showed both message URLs as a string with a space between them.

Is there some modification to the JS I should be making? Here is what I have (where Command-Space opens Launchbar):

Thank you for your help with this.

I will have to add JavaScript to my tool kit :grinning:

Yes, I tried doing the outlined process manually without KM and it worked, but I couldn't get KM to get the cursor to the beginning of the URL such as by searching for 'message' in the text field (which I can easily do manually).

The application itself does not allow you to search for text in its text note field. (You can search on 'message' in a list of transactions and it filters the list to transactions containing that term, but you cannot search to select in the note field).

@Nige_S's response above solves my problem of searching for the full URL in the text field using a Regular Expression.

1 Like

Iā€™m sure there is.

As always, you will need to provide sample input, to make testing possible.

( showing works better than telling )

In the meanwhile, you could experiment with the following version of the code in the Execute JS action:

Expand disclosure triangle to view JS source
.map(x => {

        match = x.split(/[\s\\)]/ug)

    return `message://${match}`;