No internet connection
  1. Home
  2. How to

Get the name of the currently open Finder window

By Andrew Sherman @Andrew_Sherman
    2024-06-13 10:57:11.098Z

    I'd like to trigger a specific deck when a certain Finder window is open, for tasks that I use frequently that are related to the folder shown in that window. I tried to get the name of the window from the UI but it doesn't seem to show the name.

    sf.ui.finder.mainWindow.getElement("AXTitleUIElement").elementClick();
    

    I'm looking for the name or path of the window itself (not selected items in the folder). For example if I'm working in the browser and then switch to Finder and that specific window is front and active, I want a certain deck to trigger. Sometimes I have a Finder window open (selected in the sidebar) but no items are selected in the folder; I still want to access the folder name.

    Is there a way to achieve this? Perhaps using command line, or applescript, or a better way? I see that the Finder menu shows the names of the current windows with a tick next to the active one.

    Solved in post #4, click to view
    • 4 replies
    1. Try this:

      log(sf.appleScript.finder.firstWindow.targetPath);
      
      1. AAndrew Sherman @Andrew_Sherman
          2024-06-13 11:41:58.220Z

          Excellent, that gives the path just as I'm looking for. Now, is there a way to trigger a specific deck, when that specific Finder window is the front window and Finder is the front active application? I have different decks that I use for Finder that are normally used; I only want this deck to appear with that folder.

          1. It might be easier to use a Window Trigger for that and use a "Contains" filter on the title

            ReplySolution
            1. AAndrew Sherman @Andrew_Sherman
                2024-06-13 11:58:28.572Z

                Superb! Very simple, don't know how I missed the Window triggers. For somebody wanting to do this, you set up a new window trigger, When Finder is active, Window title match "ends with", and include the name of your folder in "Window title". There may be multiple folders with the same name so you may need to modify the folder name if you need it to be unique. But it works perfectly for my need.