Skip to main content

⚠️ Please note that this topic or post has been archived. The information contained here may no longer be accurate or up-to-date. ⚠️

How to tell an app's file navigator to go to a folder and select specific images?

Comments

1 comment

  • Walter Rowe
    Moderator
    Top Commenter

    I figured out how to do this for Affinity Photo. If you write a simple Apple Script that "tells" system events to tell a specific application, then you can query that application's UI using "entire contents of ...". This will tell you the UI element hierarchy. If an app has a pop-up window, you can query just that window. If that window has a "sheet" you can query just that sheet of that window.

    For example I was able to get the UI elements of the file list pop-up dialog within Affinity Photo after choosing the File > New Focus Merge… menu option and press the "Add" button that brings up the file chooser.

    tell application "System Events"
    tell process "Affinity Photo 2"
    entire contents of sheet 1 of window "New Focus Merge"
    end tell
    end tell

    This provided me valuable information about the UI elements of the file chooser making it easy to interact with it.

    If you target a specific UI element you also can ask for its properties.

    You also can query System Events for conditions about these elements such as whether they exist yet, whether a button is enabled (responds to "return"), etc. This makes it easier to build intelligent pauses into your scripts that wait for a specific UI condition to be true before it continues.

    0

Please sign in to leave a comment.