• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: name of target of front window
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: name of target of front window


  • Subject: Re: name of target of front window
  • From: Luther Fuller <email@hidden>
  • Date: Sat, 29 Sep 2012 17:17:36 -0500

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.)


 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

References: 
 >name of target of front window (From: Ronald Hofmann <email@hidden>)

  • Prev by Date: name of target of front window
  • Next by Date: Re: name of target of front window
  • Previous by thread: name of target of front window
  • Next by thread: Re: name of target of front window
  • Index(es):
    • Date
    • Thread