How Do I Run Script on Selected File in File Open Dialog?

Hey Jim,

You're SOL – insofar as normal scripting goes.

While there is an accessibility property for the file-url you can't get its value with AppleScript.

AppleScript just beeps irritatingly at you and throws this error:

System Events got an error: AppleEvent handler failed.
Num: -10000

If you look at the file object in the open dialog with UI Browser or the Accessibility Inspector you'll see this junk:

AXURL	file:///.file/id=6571367.12732750

So our caustic friend's idea is probably the most viable one for normal users.

For more advanced users:

You can get the file name, and if it's unique enough you could find it quickly by scripting Spotlight.

tell application "System Events"
      tell application process "Safari"
         tell window "Open"
            tell group 1
               tell splitter group 1
                  tell splitter group 1
                     tell scroll area 1
                        tell outline 1
                           tell row 4
                              tell UI element 1
                                 tell text field 1
                                    set fileName to attribute "AXFileName"'s value
                                 end tell
                              end tell
                           end tell
                        end tell
                     end tell
                  end tell
               end tell
            end tell
         end tell
      end tell
   end tell

set shCMD to "mdfind 'kMDItemFSName == \"" & fileName & "\"'"
set filePath to do shell script shCMD

Also – since you have Default Folder – you can find the current location of the dialog with AppleScript.

Unfortunately the only utility I know of that offers the ability is Default Folder.

So – file name plus container folder gets you a path.

Here are some hints for working with Default Folder:

AppleScripting Default Folder

-Chris