Open Library with Script

Is there a way to use AppleScript to direct EagleFiler to check to see if a library is open and then open the library if it is not open?

A script like this would do that:

tell application "EagleFiler"
    if exists library document "EagleFilerTest.eflibrary" then
        -- the library is already open
    else
        open POSIX file "/Users/mjt/Desktop/EagleFilerTest/EagleFilerTest.eflibrary"
    end if
end tell

However, there is no harm in telling EagleFiler to open a library that’s already open. It won’t open a “second copy” of it; it’ll just bring the window to the front.

Perfect! Thank you!

Hi Michael,

Is there a way to do this (assuming the library file is already open) without relying on targeting the library file itself? (i.e. Using AppleScript to target the window name or the library name instead?)

Ideally I would like to be able to run an AppleScript that asks EagleFiler to bring a particular window or library to the front – without activating and/or bringing to the front EagleFiler itself. (This would allow me to use a combination of AS and EagleFiler’s “Import” service to import my item to the library of my choosing automagically.)

Apologies if I’ve missed something that’s right in front of my face.

The window names will change based on what’s selected. However, you should be able to examine the windows and see which documents they have; or you can get the window from a document.

Manipulating windows via AppleScript looks kind of buggy at the moment. I’m not sure whether it’s a Cocoa issue. You might have better luck using accessibility scripting or telling EagleFiler to open the library and then sending EagleFiler to the background.

There isn’t but probably should be an AppleScript property for setting the current library to a document.

I could target the window name, but didn’t have any luck bringing it to front using ‘set index to 1’ or ‘set visible to true’ , etc.

I had been on those exact pages, but hadn’t gotten anything to work. Your prompt sent me back there, though, so thank you for that, because the persistence paid off (see below).

This is what I had been doing, though I was being picky and trying to avoid it.

That would be awesome.

Anyhoo, here’s a script that finally worked, adapted from one at the link you included.

set winTitle to "Reading Library"
tell application "System Events"
    tell process "EagleFiler"
        try
            perform action "AXRaise" of (windows whose title contains winTitle)
        end try
    end tell
end tell

(The “perform action” line is in a ‘Try’ block because, even though it seems to work, it throws an error in AS Editor.)

Thanks, as always, for your prompt and courteous assistance, Michael.

D’Oh! Looks like I spoke to soon in last post.

Turns out that even though I can bring my desired library (of the 2 or 3 I have open) to the front using the script I posted, the battle is not yet won. Once the ‘EagleFiler:Import’ Service is invoked (after the script has been run), it ends up targeting whichever library was frontmost before the script was run.

Instituting lengthy delays between invoking the script and invoking the import service didn’t work.

Nor did editing the script to fix the error and to try to get EagleFiler to see my desired window/library as being frontmost:

set windowName to "Reading Library"
tell application "System Events"
	tell process "EagleFiler"
		perform action "AXRaise" of (first window whose name contains windowName)
	end tell
end tell

tell application "EagleFiler"
	tell (first window whose name contains windowName)
		set index to 1
		set visible to true
	end tell
end tell

Any thoughts on how I might get it to work, Michael?

Looking at the code, EagleFiler sets the current library when you tell it to open a library or when a window becomes main. So changing the window order with EagleFiler in the background may not have any effect. I think you would have to close and open the library or else bring the application to the front temporarily so the desired window could become main.

Understood, Michael – thanks.

Then I shall continue to wait (patiently and hopefully) for this…

Thanks again, sir.

EagleFiler 1.6.5 adds a way to set the current library document via AppleScript.