I have a stay open script application (named “Foo”) that uses the following handler:
on makeFinderWindow()
tell application "Finder"
set bar to make new Finder window
return bar
end tell
end makeFinderWindow
When I call this handler from another script it returns
Finder window id 47 of application "Foo"
to the calling script. Now if I try to do anything with that Finder window using handlers in the calling script, it won’t work because AppleScript thinks the Finder window belongs to the application “Foo” instead of the Finder.
How can I get “Foo” to return a ref to a Finder window which belongs to the Finder and not “Foo”?
I know this can be done by loading the script containing this handler as a script object in the calling script, but I’m interested in how this can be done with a stay open AppleScript app.
Any AppleScript geniuses out there know the answer to this one. I’ve been working on it for three days.
I’m not a genius but thanks for the compliment anyway. I must have read the AppleScriptLanguageGuide at least a hundred times and more for that section on script objects.
Anyway, I kind of like that script object idea also. You can make it generic like for returning lists of Finder references also and you’ll have only subroutines in your stay open script library.
I don’t see any “foo” window here, but only correct Finder window reference…
set theScript to load script alias "HARD_DISK:Users:123:Desktop:foo.app"
set finderWindow to makeFinderWindow() of theScript
-- result: Finder window id 2809