Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5976991
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T21:18:25+00:00 2026-05-22T21:18:25+00:00

Is there any way to determine the currently active window, or a folder, in

  • 0

Is there any way to determine the currently active window, or a folder, in the Finder? I need this to determine, in some sense, an appropriate “default” location in which to do some particular things in my app.

Actually, does this question even make sense? Does this concept of a “currently active Finder window/folder” even exist in the first place? If it does not, I kindly ask how to get the currently selected Finder item.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T21:18:25+00:00Added an answer on May 22, 2026 at 9:18 pm

    Yes, the concept of the currently active Finder window does exist, as well as the currently selected item.

    For example, the following AppleScript gets the selection which is the current selection in the frontmost window. Since this returns a list of files or folders even if there is a single item, the next line gets the first item out of that list (after making sure that the count of the list is greater than 0). You can then ask the Finder for the container window of the selected item, which will return a Finder window object.

    tell application "Finder"
        set selectedItems to selection
    
        if ((count of selectedItems) > 0) then
            set selectedItem to (item 1 of selectedItems) as alias
            container window of selectedItem
        end if
    
    end tell
    

    I’m pretty sure the code sidyll posted will work okay in 10.5 and earlier, but it errors out in 10.6 due to the inevitable changes and quirkiness that AppleScript seems to have from one version of OS X to the next.

    [EDIT] Actually, I just figured out what’s going on.
    I usually have the Finder’s Inspector window open all the time (the dynamic Get Info window you get through Command-Option-i), the upper right panel in the image below:

    enter image description here

    That image shows 3 different classes of windows:

    1) The upper left, a Get Info window, is an information window, which inherits from the generic window class.

    2) The upper right, an Inspector window, is a plain window.

    3) The lower image shows a Finder window, which inherits from the generic window class.

    If I run the following script with the setup of windows shown above:

    tell app "Finder"
        every window
    end tell
    

    it returns the following result:

    {window “mdouma46 Info” of application
    “Finder”, information window “mdouma46
    Info” of application “Finder”, Finder
    window
    id 1141 of application
    “Finder”}

    So, what was happening in my case is that, since the Inspector window is a floating utility panel, if it’s currently being shown, asking the Finder for window 1 will always return the Inspector panel, since it’s always floating in front of the other windows.

    So the error I was getting when running the code was:

    error “Can’t make «class fvtg» of
    window 1 of application \”Finder\”
    into type alias.” number -1700 from
    «class fvtg» of window 1 to alias

    (In other words, the Inspector window, a plain window, doesn’t have the FileViewer target (fvtg) property; only Finder windows do).

    So, your code will work fine as long as the user doesn’t have the Inspector window, the Preferences window, or a Get Info window that is frontmost. By changing window to Finder window, though, you can make sure that you only look at the file viewer windows that have the target property.

    So, like this:

    NSDictionary *errorMessage = nil;
    
    NSAppleScript *script = [[[NSAppleScript alloc] initWithSource:
        @"tell application \"Finder\"\n"
            " if ((count of Finder windows) > 0) then\n"
               "  return (POSIX path of (target of Finder window 1 as alias))\n"
            "end if\n"
         "end tell"] autorelease];
    
    if (script == nil) {
        NSLog(@"failed to create script!");
        return nil;
    }
    NSAppleEventDescriptor *result = [script executeAndReturnError:&errorMessage];
    if (result) {
        // POSIX path returns trailing /'s, so standardize the path
        NSString *path = [[result stringValue] stringByStandardizingPath];
        return path;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there any way to determine if a text file is currently open in
Hey, is there any way to determine is UIPickerView is scrolling currently, I really
Is there any way I can determine the currently focused control on a web
Is there any way to determine a removable drive speed in Windows without actually
Is there any way to determine if an object is a generic list? I'm
Is there any way to determine precisely why a System.Transaction TrasactionScope is being escalated
Is there any way to determine the local culture of a PC (such as
Is there any way to determine if the mouse scrolls up or down using
Is there any way to determine a page numer (in paged list), that contains
Possible Duplicate: Is there any way to determine text direction from CultureInfo in asp.net?

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.