Does anyone know how to specify the full path of a file to be saved from the standard file dialog box? All I’ve come up with is a cludge of scripting “SHIFT-CMD-G”, using image recognition to find the light blue background color for the text, and then scripting a right-click-paste. Any ideas? Thank you.
Post your script so we can see what you’re doing.
Thank you for your reply. I’m getting to the macOS save dialog box via another dialog box, but I don’t that matters here. I’ve commented below to hopefully convey what I’m doing. (Forget the image recognition bit.) I’m stuck where a miracle occurs. Thank you again.
-- Open the RX's Export dialog box, and the macOS save dialog box.
tell application "System Events”
tell process "iZotope RX 10”
-- Choose "Export"; using the item number because title does not work this item.
click menu item 10 of menu 1 of menu bar item "File" of menu bar 1
delay 0.1
-- Click the OK button in the Export dialog box. This produces the standard macOS Save dialog.
click button 2 of group 1 of group 1 of window 1
delay 0.1
-- Press the key shortcut to bring up the macOS path selection floating window.
keystroke "G" using {command down, shift down}
-- Set the folder path to "~/Documents/"
-- [A MIRACLE OCCURS]
-- Set the file name. Use "Window 1" because there are two windows with the same name as the one we want.
set fileName to a reference to button 8 of group 2 of group 3 of window 1
tell fileName
set focused to true
set value to "Test File"
end tell
delay 0.1
-- Save the file
click button "Save" of window 1
end tell
end tell
Assuming that it’s specifically the Documents folder that you’re after, from within the save/open dialogues, command-shift-O will set its focus to the Documents folder.
@notsteve
If I understand you correctly I did a example with Script Editor.
It would be easy to adapt to your example.
-- This example will save document to desktop
set thePath to POSIX path of (path to desktop)
set filename to "abc"
tell application "System Events" to tell application process "Script Editor"
set frontmost to true
tell menu bar item "File" of menu bar 1
click menu item "Save As…" of menu 1
end tell
tell window 1
tell sheet 1
click text field 1
end tell
key code 5 using {command down, shift down}
delay 1
keystroke thePath
keystroke return
tell sheet 1
click text field 1
keystroke filename
end tell
tell sheet 1
click (every button whose name is "Save")
end tell
end tell
end tell
That is amazing - thank you so much! And I can see now how to interact with that text field. Cheers!!!
I had no idea - thank you for the tip!
You could also use the property value from text field UI element.
set {filename, extension} to {"abcdef", ".scpt"}
tell application "System Events" to tell application process "Script Editor"
set frontmost to true
tell menu bar item "File" of menu bar 1
click menu item "Save As…" of menu 1
end tell
tell window 1
tell text field 1 of sheet 1
set value to filename & extension
end tell
end tell
end tell
Thank you again for your continued help!
Could you please explain how the path gets in there? (I’m surprised that Apple doesn’t let you paste in a full path into a file dialog box.)
Also, could you please tell me what a "sheet’ is? (Google keeps showing me Numbers scripting.) When I monitored all the windows in UI Browser, I indeed saw a “sheet” at one point in a group. So, I know it’s real…
If you know how AppKit framework works you could find this.
Or
You could search for the UI element that contains its info. UI element group could contain other group and so on… but sheet couldn’t contain other sheet.
If you made save dialog delegate you could use AppKit methods to get path when the dialog is open.
In your case the text field do not allow slashes in the file name. So we need to use Go to Folder that is part of Finder. To get it we use keyboard shortcut shift+command+G
Now we could set the path to folder and the save dialog delegate will update its path to folder.
Its not different from the approach to get content from ~/Library a folder in home folder that is hidden. Its not possible point and click and hidden directory but its possible to use Go to Folder path to hidden folder.
Here is example from Github from the user @Red-Menace to make save dialog box.
Here is information from Apple’s Human Interface Guidelines about sheet.
In the context of Numbers, a sheet is a ‘page’ within a Numbers document. You can find out (a little) more via Script Editor - File - Open Dictionary then choose Numbers and search for ‘sheet’.
A typical AppleScript that uses Numbers might be structured something like this:
tell application "Numbers"
tell document 1
tell sheet 1
-- do stuff
end tell
end tell
end tell
It doesn’t look as though the term has any meaning when scripting isotope.
@hubert0 @notsteve
Sheet in this context is in modal world not object in Numbers. The defination is prevents interaction with the parent view. When user click Save as… in menu bar the context of the front most view is modal sheet. It ask the user for actions or dismiss.
Sheet
Modal view
Thank you once again - I understand now.