Trigger when a certain url in a hyperlink hits System keyboard

Where would I begin exploring how to trigger a macro based on the contents of a url, when that url hits the System Clipboard in the form of a hyperlink?

Is it something that could be accomplished by using apple script or automator.

And the last trick is I only want it to run when I’m using the application where they apply.

Adding a “Clipboard Changed” trigger is on the todo list, which would open up this as a possibility.

Otherwise if you can find something else that can detect the clipboard change (perhaps Control Plane can do it?) then you could trigger a macro that way, but for the moment I don’t have any good solution to this.

I have KM check Safari each time it’s brought to the front for a specified words in a title of a webpage. It might do the same for watching for a URL string. For example, when I download a WordPress editor, KM opens a designated palette of WordPress macros.

Wait, I may have solved my problem. Tell me if this makes sense.

I trigger a Macro with a keystroke.

The macro calls an application command that sends a url to the System clipboard.

The macro examines the content of the url

And then based on that it proceeds to one of 10 different outcomes.

Does that sound possible.

If you don’t mind triggering with a hot key, then there are endless possibilities. For Safari and Chrome URLs, you don’t even need to use the clipboard, you can get them with the text tokens (eg %SafariURL%).

After that processing the variable or clipboard should be straight forward.

The only thing you can’t do is trigger the macro automatically when the URL or clipboard changes.

It’s a third party app sending a hyperlink (or url) to the system clipboard.

Would it strain too much to examine the url and then, depending on the contents, call one of 270 different other macros?

Probably not.

How would I do that? I'm just not sure how to search the url, then call the appropriate macro if it matches the correct string.

Basically, what I do is use KM to save links from an RSS program, Reeder, to Pinboard, but to shuffle some of the fields, and add tags automatically.

Right now I call a Macro like this:

And then it executes one of 5-7 other Macros, each of which looks like this:

I know it works fine doing that if/then loop for seven items.

But is there a smarter way to do this on a level of say, 270 different url searches executing one of 270 different macros?

That's ultimately what I'm getting at.

Noi, there is no better way for 270 items.

You can simplify it a little by doing this:

If clipboard contains "jaysjournal"
    Execute Macro Whatever
    Cancel This Macro
If clipboard contains "mlb"
    Execute Macro Whatever
    Cancel This Macro

That avoids having to have endlessly nested If Then Else

Of course, if all the executed macros are the same except for the two bits of text, then you could do something like:

If clipboard contains "mlb"
    Set variable One to "[banter]"
    Set variable Two to "new, TOR"
    Execute Macro Standard
    Cancel This Macro

And then the Standard macro could be based on the two variables. Then you don't have to have 270 macros as well as 270 IF then Else actions.

Of course, if you had a switch statement like this:

it would be better than a bunch of If Then Else actions. But you don't. Oh well, you never know what the future might bring.

Thanks so much.

This is helpful.



1 Like

For a big repetitive string comparison job it might be easier to build and maintain an AppleScript:

set clipboardString to the clipboard
tell application "Keyboard Maestro Engine"
  if clipboardString contains "" then
    do script "24475519-4CF1-424E-B9EC-83404C611DFF" # UUID of macro
  else if clipboardString contains "" then
    do script "24475519-4CF1-424E-B9EC-83404C611DFF" # UUID of macro
  end if
end tell

What I usually do though is construct a string table and search with regex.

set myLookupTable to "		24475519-4CF1-424E-B9EC-83404C611DFF		34475519-4CF1-424E-B9EC-83404C611DFX

set myLookupValue to the clipboard
set regExPattern to "^" & myLookupValue & tab & "+([a-z0-9-]+)$"
  set foundValue to find text regExPattern in myLookupTable using "\\1" with regexp and string result without case sensitive
  tell application "Keyboard Maestro Engine"
    do script foundValue
  end tell
on error
  "Clipboard value not found!"
end try

I find this method to be much easier to maintain and sort.

Note: This script depends upon the Satimage.osax AppleScript Extension for regex support.

Keyboard Maestro also has regex support of course.

Best Regards,

Could you post your macro of that?


Thanks for asking.

Let me know if that helps.


Yes. Thank you!