Reveal Safari Windows

Reveal Safari Windows Group and Support Group.zip (59.6 KB)

Yet another take on finding Safari windows. This one uses a palette of macros that specify strings and URLs. The macros search all Safari windows looking for those having a specified substring in their title — not tabs — or more accurately, in the title of their front tab.

  • If matching windows are found, they are brought forward and deminimized.. (You can easily remove the deminimization.)

  • If no matching windows are found a new one is opened with the specified URL.

Add your own items to the palette by following the pattern of the macros in the group.

Note that these macros require the macro Reveal Safari Windows Matching String Otherwise New One with URL, in the included group ➜ Reveal Safari Windows Support. (And that is where you would go to remove the deminimization.)

Today I was looking for this page or the macro to which it refers and had extreme difficulty finding it. That must make it nearly invisible to the rest of the community.

One problem is the “untitled macro file” name of the file that contain the macros.

More importantly, I’m sure, is that the combination of words in the OP somehow don’t get conjured up by a simple search. In an attempt to ameliorate that problem, I am adding phrases here that I hope would show up in a simple search (some of which are, in fact, in the OP).

  • choose
  • select
  • open
  • switch to
  • find
  • locate
  • title
  • tab
  • browser
  • window
  • front

That should be enough :-).

Hey Mitchell,

Setting the index of a Safari window is not enough to fully bring it to the front (a long-time Apple bug).

You have to use System Events like this:

--------------------------------------------------------------------------------
tell application "Safari"
   activate
   set WinList to name of (windows where its document is not missing value and its name contains "Keyboard Maestro")
end tell

tell application "System Events"
   tell application process "Safari"
      repeat with theWin in WinList
         tell window theWin
            perform action "AXRaise"
         end tell
      end repeat
   end tell
end tell
--------------------------------------------------------------------------------

I believe there’s a way to do this with JavaScript as well, but it’s eluding me at the moment.

Perhaps @ComplexPoint will chime in and help with that.

-Chris

1 Like

Here’s what I am thinking about this. Please correct errors.

I know there are all sorts of problems and shortcomings with using the index of a window, but I have never encountered a situation in which setting the index of a Safari window to 1 didn’t bring it to the front without an error.

The problem with AXRaise is that that action is performed on the window of the application process Safari, not a Safari window, and the action might be part of a context in which Safari windows are being searched, opened, etc. It’s not even possible, I don’t think, to generally get from a Safari window to the corresponding application process window, especially because multiple windows could share the same name.

There is a similar problem with attributes of application process windows, such as AXMinimized. The corresponding property of a Safari window is “miniaturized”. So, inside a context where Safari is the target I can set miniaturized of a window, just as I can set its index.

Unless you know a secret passageway from an application window to the corresponding application process window?

Hey Mitchell,

Set the window you want to index 1 – then create and immediately close a new document window.

It's kludgey, but it works.

-Chris

Looking and thinking about this I like it and don’t see a utility other than saving mouse moving time and effort which of course is a very good thing to do.

All these locations can be listed in the bookmarks menu, bookmarks sidebar, or in the favorites bar. What more does adding a palette provide?

I want to believe :alien:

Hey Bern,

Mitchell's palette does more than list Internet locations – it acts on existing windows and works the way he wants instead of the way the Safari UI tries to make him work.

I have a palette for 1-key operations in Safari:

Before I palletized these commands I would sometimes forget I had activated them (sometimes to my sorrow).

-Chris

Hi Chris,

Thank you for showing me. That’s much more useful and I’m aligned with the idea of adapting the UI to fit each users preferences. I now remember playing with and getting excited by palettes when I first realized what they could do.

I stretched them out horizontally making my own window menu bars. After a while little things got to me and I stopped using them. While great utility is there and there are several options to adjust the aesthetics, the aesthetics don’t go far enough for me. I suspect I’ll not be satisfied until I can adjust the UI to be as I see fit which may be a foolishly high mark to demand. Why not just use what’s available and move on?

This leads into what leaves me annoyed and others saying just learn to code and do what you want. If you don’t want it enough to pay the price of having it then just shut up. To which I can’t argue.

I think that’s why I forget about doing these things as when I remember what I see as the cost of moving beyond it I stop.

Thanks again for providing clarity.

Hey Bern,

One more thing.

My 1-Key palette is is enabled/disabled via a keyboard shortcut and is only shown when I'm using those 1-Key keyboard shortcuts.

I have palettes like this for several apps, where it's useful for me to have 1-Key keyboard shortcuts available during certain operations.

I don't care so much what they look like as long as I'm reminded that they're enabled.

-Chris

My macro does much more than just go to a bookmarked page, as @ccstone pointed out earlier. I will be posting an improved version of this soon, but meanwhile look at the macro Reveal Safari Windows Matching String Otherwise New One with URL that is in the ➜ Reveal Safari Windows Support group that comes along with the main group. It dxminimizes and brings to the front all windows whose current tab contains the designated string; if it doesn't find one, it opens the specified URL. My most frequent use of this is to bring to the front all my Safari windows tuned to a Keyboard Maestro Forum page.

I bind it to a modified function key.

Here's what my palette looks like now (minus some pages for Git Wikis, etc., for projects I am working on.

I've posted it's current state.

➜ Reveal Web Pages in Safari (272 KB)

There’s a bug here — doesn’t catch multiple windows with the same name. So I changed it to set WinList to the windows not their names. But then the perform fails with this error message:
Can’t make window id 19783 of application "Safari" into the expected type. Suggestion?