AppleScript: Making the correct library window frontmost when multiple windows are open

I have an AppleScript that copies selected records from the frontmost library to another open library. After the copy completes, the script opens the destination folder in the target library.

That part works fine, but I then need to bring the correct browser window for the target library to the front.

The complication is that EagleFiler allows multiple browser windows for the same library (e.g. Snippets Library and Snippets Library (4)). The AppleScript dictionary exposes library documents and browser windows, but there’s no direct way to say “bring the window for this library document to the front”.

Calling:

tell application "EagleFiler"

    open (file of tgtLib)

end tell

does bring the library forward, but if multiple windows are open for that library it can raise the wrong one (e.g. the (4) window).

After a lot of experimentation I ended up using a routine that:

  1. Uses the short library name (e.g. Snippets Library)

  2. Iterates through browser windows

  3. Finds the window whose title matches that name (preferring the unnumbered one)

  4. Sets its index to 1 to bring it to the front

In simple terms, the routine just searches the open browser windows and raises the one whose title matches the target library.

This works reliably, but it feels a bit indirect.

So my question is:

Is there a more direct AppleScript way to bring the browser window for a specific library document to the front?

For example something like:

tell library document "Snippets Library.eflibrary"

    make its browser window frontmost

end tell

—or any other recommended approach.

Thanks for any suggestions.

At the app level, browser window 1 is the frontmost browser window.

At the document level, browser window 1 is the first window that was opened for that library (i.e. the one without a number in its title).

The window level is controlled by the index property.

So if you want to bring forward the first window for a given library you could do something like this:

tell application "EagleFiler"
    tell library document "Snippets Library.eflibrary"
        set browser window 1's index to 1
    end tell
end tell

Thanks Michael. I had not twigged the two different meanings of browser window 1, depending on the context. Explains all the struggling :laughing:

Application

├─ library documents

│ └─ browser windows (for that library)

└─ browser windows (all windows in the app)

For future users: Quick way to see the difference between application-level and library-level browser windows

While debugging a script that needed to bring the correct EagleFiler window to the front, I discovered a useful diagnostic snippet that makes the two window contexts visible.

EagleFiler exposes browser windows in two scopes:

  • Application level → all open browser windows
  • Library document level → only the windows belonging to that library

This short script shows both lists:

tell application "EagleFiler"
	
	log "---- Application level windows ----"
	repeat with i from 1 to count of browser windows
		log ("App window " & i & ": " & name of browser window i)
	end repeat
	
	log "---- Library level windows ----"
	repeat with L in library documents
		log ("Library: " & name of L)
		tell L
			repeat with j from 1 to count of browser windows
				log ("   Lib window " & j & ": " & name of browser window j)
			end repeat
		end tell
	end repeat
	
end tell

Typical output might look like:

---- Application level windows ----
App window 1: Snippets Library
App window 2: Developer
App window 3: Snippets Library (4)

---- Library level windows ----
Library: Snippets Library.eflibrary
   Lib window 1: Snippets Library
   Lib window 2: Snippets Library (4)

Library: Developer.eflibrary
   Lib window 1: Developer

This immediately shows that:

application → browser windows = all windows
library document → browser windows = only that library's windows

Which means that to bring forward the main window for a library you can simply do:

tell application "EagleFiler"
	tell library document "Snippets Library.eflibrary"
		set browser window 1's index to 1
	end tell
end tell

This will save a lot of trial-and-error when dealing with multiple windows for the same library.