I'm looking for a script and/or macro to call the file chooser (file open dialogue box) and choose a file. The path of the file should be placed on the clipboard.
Has nothing to do with System Events; it’s a part of the Standard Additions OSAX. The reason for using SEV is to provide a context for the choose file dialog to open. I prefer to use the Keyboard Maestro Engine for this, since it’s already running.
Note also that this script restores the previous app’s context, instead of invisibly leaving you hanging in System Events.
set frontApp to path to frontmost application as text
tell application "Keyboard Maestro Engine"
activate
set fileList to choose file with multiple selections allowed
repeat with i in fileList
set contents of i to POSIX path of (contents of i)
end repeat
set AppleScript's text item delimiters to linefeed
set fileList to fileList as text
set the clipboard to fileList
end tell
tell application frontApp to activate
This script allows one or more files to be chosen from the dialog.
The syntax also allows for a few more options as well:
set theResult to choose file with prompt text ¬
of type list of text default location alias ¬
invisibles boolean ¬
multiple selections allowed boolean ¬
showing package contents boolean