Trigger Macro when URL is arrived at

I want to launch a Macro when a website is launched, is this possible? Below is the Macro partially created.

Also, how do I state "do nothing" in an if then action?

Use the Focused Window trigger with a macro in a group limited to your browser with an If/Then action and a URL condition:

It's set up that way by default:

Incidentally, I don't know why you're activating and then quitting Transmission in your macro, but you don't need a shell script to quit an app, nor do you need to activate it first. Just use KM's built-in Quit a Specific Application action:

1 Like

Well here is what I want the Macro to do:


I think the second part will need a separate macro

  • If this image is seen in transmission "green bar"
  • then quit transmission and quit vpn


What do you think?

I agree that a second macro for the second part is the best way to go, but as a rule of thumb, don't rely on found images if you can help it. Transmission lets you run script files when a download completes:

so I would make a macro that does the quitting, copy the AppleScript to run it from the "Or by script" dropdown, then use Script Editor or Script Debugger if you have it to save the script as a file that Transmission can run.

1 Like

I can't seem to get the macro to run, please help:

Do I have the wrong trigger set?

No, the trigger is fine; it's the URL condition that's failing. By way of example, if I wanted a macro to run every time I went to, say,, I'd just set it up like this:

If you try to include the entire URL, it's much easier to get one thing wrong that ends up making the whole condition fail (like, say, putting http instead of https, since many sites redirect you to secure versions nowadays).

Incidentally, the idea is that macros like these run when you're already on the site in question, so making a new tab to open that site again seems redundant.

1 Like

OK, I'll remove the "New Safari Tab with URL" action. Maybe that is what is causing it to reload the macro every time I touch the address bar?

Thank you for this tip! I'll write a script to quit both "Transmission" and "Express-vpn" to avoid the need for creating a second macro to quit based on an image.

1 Like

Ok, everyone I'm still having problems with this Macro, it keeps running over and over every time I click anywhere on the browser. What do I need to add/change? I had to disable the Macro for now.

How can I force this macro run only once? Right now it keeps running over and over every time I click anywhere on the page.

You could change the condition to this:


Then it should only trigger when you open the main page or the search results, since the string the pirate bay is not in the window titles of most subpages.

However, the macro will trigger again when you go back to the search results for example.

But I guess what you really want is not starting the VPN again when it is already running, no?

I don’t know VPNExpress, but there is certainly a way to detect if it is running. If the Network Location changes, then it is easy (there is a built-in condition for that). If not, you could check if the VPNExpress app itself is running, or if it spawns a background process, check for that background process.

The reliable method to check if the VPN is up and working would be to compare your IP address against your normal (non-VPN) IP address. But this needs significantly more effort.

I'll try it and report back tonight.

OK, here is a probably better solution than what I proposed in the screenshot above:

Action when switching to Piratebay <2407 200225T224944>.kmmacros (3.9 KB)

It is basically still the same as your old macro, but it remembers the prvious browser URL and the actions are only run if…

  • the new URL is piratebay and
  • the previous one was not piratebay

The macro still triggers at every window title change, but the actions should run significantly less often. They should run only when you switch from a non-piratebay URL to a piratebay URL, that is, as long as you stay within piratebay the actions shouldn’t run again.


  • Replace the Speak Text action with the actions of your choice
  • Put the macro into your browser-specific macro group (Safari, Brave, Opera, whatever)
  • Make sure macro and macro group are enabled

I have the following code in the "Call script" section but it isn't responding as expected (AKA not working)

set apps to {"Transmission", "ExpressVPN"}
repeat with thisApp in apps
	tell application thisApp to quit
end repeat

Can someone tell me why?

Tested with other apps, but it works here.

For issues with tell application <variable> see this interesting topic:

Applescript to tell active application

especially post 3.

Did you have time to test the method proposed above?

It should efficiently eliminate your current main problem. (Actions run again when clicking anywhere on the already frontmost piratebay page.)

I am using your/my Macro, I think I've fixed it by eliminating the "Find and click on found image" action. Instead, I'm using the "type keystroke" action to pause for 5 seconds and then click the Return key. After that the Macro seems to work completely.

The only remaining part to get working within "Transmission" is the AppleScript below:

tell application "Transmission"
end tell

tell application "ExpressVPN"
end tell

I think the AppleScript wasn't executing because Seeding was still considered downloading and that's why everything wasn't shutting down even though I was done downloading. So, I've turned off seeding (i.e. sharing) and we'll see what happens.

Yes, since VPNs can leak or otherwise malfunction, it is probably a good idea anyway to stop any extra seeding. (You are already seeding the received parts, even while still “downloading”.)

You can also force-quit Transmission, for example via shell script action: killall Transmission

Can you show me how the killall command should be written? The AppleScript is not executing within Transmission.