On Sep 29, 2012, at 3:56 PM, Ronald Hofmann wrote: I´m trying a Finder tool with Objective-C and need to know if there is an Finder window open at a certain point of time.
Right now I´m using this: tell application "Finder" set theFolderName to name of target of front window end tell
But this only works if the front window is a normal window. If the front window is a search window theFolderName remains empty. If the front window is a Info window I receive an error.
I wonder if there is another way to distinguish between these different window types but without success so far.
Interesting. I've encountered this, too. If you already know the alias (path) of the folder, you can do something like this ...
property folderAlias : alias "Work_Files:Mail Archives:_News Lists:_Applescript-users:AppleScriptUsers:name of target of front window:" tell application "Finder" activate try set winVisible to visible of window of folderAlias on error set winVisible to false end try end tell
This will give winVisible the correct value even if the window is not frontmost.
On the other hand, if you need to get an alias to the frontmost folder window, do something like this ...
tell application "Finder" activate try set folderAlias to (target of front window) as alias on error display dialog "Error" end try end tell
If the front window is not a folder window (info, view) you get an error that you can handle in various ways.
But, the question seems to be about how to get an alias to a folder even if info or view windows are open. After playing around with this problem for a few minutes, this seems to work ...
tell application "Finder" activate set winIdList to id of every window set found to false repeat with winID in winIdList try set folderAlias to target of window id winID as alias set found to true exit repeat end try end repeat if not found then display dialog "Not Found" end tell log folderAlias
Try it and see if it works for you.
(Notice that I used an alias instead of the name. The results are more useful that way.)
|