Close current Safari tab using Javascript?

I’m currently triggering a KM script remotely using either my iPhone or iPad Pro but that pesky little new Safari tab has to go. I know the built-in functions for Safari will not allow this to happen but there must be a method for doing so using Javascript on the page and having the Shortcut automatically run that JS on the currently opened tab?

Is this at all possible?



There is no way to run something like that automatically, only from the share sheet. The fastest way would be just to press & hold on the tabs button until a menu pops up and then tap Close Tab.

If you have a shortcut already accessing the website via the share sheet, then the method from @dustinknopoff would work. But I wouldn’t create a shortcut just to close a tab.

You could also add a bookmark to your favourites with the address pointing to


and then tap on the URL bar and on the bookmark.

1 Like

You could trigger the macro remotely using the remote trigger option.

Then just use the get contents of URL action. No need to open Safari.

Now there are caveats to its use that are covered in the Keyboard Maestro wiki article linked above.

An alternative, and my preference, would be to use SSH (and potentially a VPN connection too) to get a really secure connection into your machine and trigger the macro that way.

This was discussed on the forum back in January and includes a brief write-up on how to implement an SSH-based approach.

Tries this but does not work for whatever reason.

That makes sense. No real way around it I suppose as I’m triggering the shortcut via Shortcuts.