%SafariURL% Token Not Working With Minimized Window (Safari 14)

I made a "Paste Current Safari URL" macro in the Global Macro Group where typing a string will paste the current Safari URL.

In the past, the macro would work whether I had Safari minimized or in a different space or not. Now, however, I have to keep the Safari window open in order for the content in the token to paste. Otherwise, the pasted string appears blank.

I recently upgraded to Safari 14, but I am not sure whether that has anything to do with the problem.

I tried deleting and creating the macro again to no avail.

I'm not sure if @ringmaster555 ever got an answer to this question .... but I have what I believe is a related issue that I'd like help with...so I thought this would be a good place to ask.

I have a simple macro (one action) that inserts the token %SafariURL% by pasting and which is triggered by the hot key CtrlShiftU. For the most part it works fine, pasting the url of the current tab as expected. It works this way if I have multiple Safari windows open or if I have a single Safari window open on a second "Desktop". However, if I have two Safari windows open on Desktop 2 and then use my macro, %SafariURL% always reports the tab in the first window that was opened... no matter how much clicking I do on the "second" Safari window. If I now close the "first Safari window" all is well again.

I suspect that this has something to do with "front window" a concept with which I still struggle, but I would like to be able to have multiple Safari windows open on a separate desktop and still have %SafariURL% report the current (frontmost?) tab's url, i.e., most recently clicked on tab's URL. Any thoughts / suggestions please?

Hey Dave,

Keyboard Maestro's browser tokens are all AppleScript under-the-hood.

Try this:

Open a couple of windows in Safari and run this in Apple's Script Editor.app:

tell application "Safari"
   name of front window
end tell

Note the result.

Then hit H to hide other apps.

Run the script again.

What normally happens is:

  • When Safari is visible it will return the "front" window i.e. the window with index 1 (front-to-back).

  • When Safari is hidden it will return the first window by order opened.

This is highly irritating and used to function "properly" i.e. the front-to-back index order was fixed.

But... Way back around Mavericks some nut-job engineer got a bee in his bonnet and insisted that front-to-back window-order-state did NOT exist when the Safari wasn't visible.

If I remember correctly – Safari is the only Apple app that exhibits this behavior...

The AppleScript community tried very hard to convince Apple to change this idiotic new behavior back, but they declined. We were the stupid ones for wanting back a behavior that had been "normal" for decades...

Don't get me started on the weirdness of AppleScript and Spaces!

-Chris

2 Likes

So I just tried, and you are exactly right.... If safari is hidden then the script returns the last tab that was open on the first window that was open.... doesn't matter which desktop they started on.

So thanks for explaining this ... frustrating as we both find the answer!

Dave

It's very frustrating that Apple has taken the trouble to provide multiple desktop support but has done such a half-assed job of it.

I'm sure the Linux people would swoon...

1 Like