How to click "Go" button on go to finder dialog by applescript?
I have below code: "dialogObj" is the dialog of Go to Finder dialog, but the "click button 1 of searchFor" does not work in here.
-- Get the search for pop-up object
set searchFor to first sheet of dialogObj
-- Select all the text in the search field and press delete
key code 0 using command down
key code 51
delay 0.5
--Paste file name
keystroke "v" using {command down}
delay 0.5
-- Click the 'Go' button in the search for pop-up
set textField to value of first text field of first sheet of dialogObj
*click button 1 of searchFor*
delay 1
In macOS Sierra the text field has been replaced with a combo box:
Try
tell 1st sheet of dialogObj
set textField to value of combo box 1
click button "Go"
end
By the way: If you select the entire text you don't need to press Delete. Any pasted or typed text overwrites the selection.
You asked: "How to click "Go" button on go to finder dialog by applescript?"
Did you mean "Go to Folder" dialog, like this:
If so, then a simple RETURN will "click" the Go button:
tell application "System Events"
key code 36
end tell
Related
enter image description here
I have the window of the picture above, save the configuration through stand-alone save, AppleScript can not click Save through click, the following script returns missing value, please ask in AppleScript, how to click static text
tell application "System Events"
tell process "WeChat"
click menu item "Proxy Settings..." of menu "WeChat" of menu bar 1
click radio button "Don't Use" of window "Proxy Settings"
delay 1
set focused to true
click static text "Save" of window "Proxy Settings"
end tell
end tell
```[enter image description here](https://i.stack.imgur.com/ZWJ9V.png)
tell application "System Events"
tell process "WeChat"
click menu item "Proxy Settings..." of menu "WeChat" of menu bar 1
click radio button "Don't Use" of window "Proxy Settings"
delay 1
set focused to true
click static text "Save" of window "Proxy Settings"
end tell
end tell
I don't have/use WeChat, so cannot examine the UI to confirm here, but static text elements—generally speaking—don't often have actions attached to them ("AXPress" is the name of the action that the click command aliases). From a design perspective, static text elements are intended as an inert label for some other UI element that plays a functional role. In this case, it looks like a button element, and its name is probably also "Save". button elements are also good candidates for attaching a whole bunch of actions to.
Therefore, instead of:
click static text "Save" of window "Proxy Settings"
you could try:
click button "Save" of window "Proxy Settings"
If that throws an error, it'll either be because the button element's name is not "Save", or the element is not a button. But you can find out what it is like this:
-- click button "Save" of window "Proxy Settings"
tell window "Proxy Settings" to get (the last UI element ¬
where the name of its actions contains "AXPress")
This will yield a reference to the object you're trying to click, by virtue of its actions necessarily containing one named "AXPress" (i.e. it responds to the click command), and its physical positioning almost certainly inferring it to be the last such UI element.
"Save" is not a button, and only one button can be found through the UI element, this button is a close button, and nothing else.
I have a simple script that automates the command "Export Library" in Music. It does the following:
tell application "System Events"
tell process "Music"
set libmenu to menu item "Library" of menu "File" of menu bar 1
click menu item "Export Library…" of menu of libmenu
tell window 1
click button "Save"
tell sheet 1 to click button "Replace"
end tell
end tell
end tell
(So basically it opens the menu and clicks the obvious buttons, saving me a few clicks). However, after upgrading to Ventura (macOS 13.0), this stopped working. The command click button "Save" is failing with:
Can’t get button \"Save\" of window 1 of process \"Music\"."
I tried to say click button 1 or click button 2 instead, but that doesn't work. I then said name of every button and it printed
{missing value, missing value, missing value}
I couldn't find a good manual for AppleScript, but it does look like something changed in Ventura. Any hints will be appreciated!
Thanks,
OK, I replaced click button "Save" with:
repeat with b in (get buttons)
if name of b is "Save" then
click b
end if
end repeat
Interestingly, I can still click the "Replace" button directly without resorting to a loop.
Thanks!
OK! I found a hint for the answer here: Just add a short delay before trying to click on "Save"!
delay 0.5
click button "Save"
Without the delay, the the dialog doesn't seem to be ready and indeed if you do get buttons you will only see the 3 from the top left corner (close, minimize, zoom). With the delay, get buttons returns 6 buttons, including the "Save".
Relatively new to AppleScript here...
I'm trying to create an AppleScript to automate a File/Save Page As... action in Firefox. Specifically, I need to select "Web Page, complete" from the Save As... dialog instead of the default "All Files" selection in the pop up button at the bottom of the dialog box. (I'm using Firefox and this option specifically because I want to save the current html contents after some JavaScript code has run - to parse out values for subsequent processing).
I've been able to hack my way around this problem by selecting the pop up menu (which has no title) by using:
((pop up buttons of window "Save As") whose description is "All Files")
and by sending the key stroke "w" to select "Web Page, complete" in the pop-up menu.
I'm trying to find a more robust way of doing this instead of relying upon the fact that "w" selects the menu item that I want. I tried:
click menu item "Web Page, complete" of
((pop up buttons of window "Save As") whose description is "All Files")
but that didn't work. In looking at Accessibility Inspector, it looks like there is a menu between the pop up button (drop down list) and the menu item but I can't figure out how to refer to it.
Any help would be appreciated. Here's the full script:
tell application "Firefox" to activate
delay 0.25
tell application "System Events"
tell process "Firefox"
set frontmost to true
click menu item "Save Page As…" of menu "File" of menu bar 1
delay 0.25
repeat until window "Save As" exists
delay 0.5
end repeat
click ((pop up buttons of window "Save As") whose description is "All Files")
delay 0.5
-- This didn't work:
click menu item "Web Page, complete" of ((pop up buttons of window "Save As") whose description is "All Files")
-- This works but only because the first entry is "Web Page, complete"
keystroke "w"
keystroke return
delay 0.5
set outputfilename to "foo3.html" as text
keystroke outputfilename
keystroke return
delay 0.5
end tell
end tell
try this
activate application "Firefox"
tell application "System Events"
tell process "Firefox"
set frontmost to true
click menu item "Save Page As…" of menu "File" of menu bar 1
repeat until window "Save As" exists
delay 0.2
end repeat
tell window "Save As"
tell pop up button 1 of group 1
if value is not "Web Page, complete" then
click
delay 0.5
pick menu item "Web Page, complete" of menu 1
end if
end tell
set outputfilename to "foo3.html"
keystroke outputfilename
click button "Save"
end tell
end tell
end tell
EDIT: I'm trying to save a session file from the Web Proxy Debugging App Charles (http://www.charlesproxy.com/) using AppleScript. Basically, I select "Export", put in a temp name, and then save it. However, after I click on combo box 2, which is the "Format" area, and then try to click on pop up button "XML Session File (.xml)", the Applescript Editor throws an error saying it can't find it.
At the moment I hacked it with the following code, but for some reason it only works on the Applescript Editor and sometimes in Terminal/my code, especially when I am doing other actions at the same time.
tell application "Charles"
activate
end tell
tell application "System Events"
tell process "Charles"
tell menu bar 1
click menu bar item "File"
tell menu "File"
click menu item "Export..."
end tell
end tell
tell window "Save"
keystroke "tempCharles"
delay 0.5
click combo box 2
delay 0.5
key code 125 -- down arrow
delay 0.2
key code 125
delay 0.2
key code 125
delay 0.2
key code 125
delay 0.2
keystroke return
delay 0.4
keystroke return
delay 0.4
keystroke return
end tell
end tell
end tell
I want my code to look something like this
tell window "Save"
keystroke "tempCharles.xml"
delay 3
click combo box 2
tell combo box 2
click pop up button "XML Session File (.xml)"
end tell
click button "Save"
end tell
Any hack is fine too. Before posting, trying running "osascript" on Terminal to check if it works not through AppleScript Editor.
set value of text field 1 of window 1 didn't seem to work either, but you could try just using keystroke:
delay 0.5 -- time to release modifier keys if the script is run with a shortcut like cmd-R
tell application "System Events" to tell process "Charles"
set frontmost to true
click menu item "Save..." of menu 1 of menu bar item "File" of menu bar 1
keystroke "templog" & return
end tell
Yep that worked! I just added
-- Got rid of the "set text" line
keystroke return
delay 1
click button "Save"
That was very subtle and I've seen that before but now I realize better what it is. Thanks a lot!
I'm trying to use AppleScript to click an item in a select box.
When clicking the 'More...' item manually with the mouse a standard OSX file chooser dialog opens up, but when I try to do it using AppleScript, the 'More...' item shows up as the chosen item for the select box, but no dialog shows up.
So far I've tried... (element names came from Automator recorder)
tell application "System Events"
click static text 1 of window 1 of application process "DYMO Word Addin"
-- combo box arrow
click UI Element 1 of combo box 2 of group 1 of window 1 of application process "DYMO Word Addin"
set labelsList to (list 1 of scroll area 1 of combo box 2 of group 1 of window 1 of application process "DYMO Word Addin")
set numLabelsInList to (count text fields of labelsList)
set theTextField to (text field numLabelsInList of labelsList)
if numLabelsInList > 1 then
repeat with z from 1 to (numLabelsInList - 1)
key code 125 -- down arrow
end repeat
end if
-- stuff I've tried
click theTextField
keystroke return
key code 36 -- return
set focused of theTextField to true
set value of attribute "AXFocused" of theTextField to true
perform action "AXConfirm" of theTextField
end tell
... and now I'm out of ideas.
After a bunch more testing, it turns out that the file dialog only opens when the combo box has focus, and that clicking the combo box arrow button and menu items doesn't actually give it focus.
http://lists.apple.com/archives/accessibility-dev/2006/Oct/msg00013.html
After trying all of the methods from that thread to give the element focus, even 'click at' didn't work.
https://apple.stackexchange.com/questions/40141/when-mousekeys-are-on-how-do-i-click-or-move-the-mouse-using-applescript#answer-40859
That answer recommends cliclick as another way to move and click the mouse, which worked.
So in the end I ended up with
click static text 1 of window 1 of application process "DYMO Word Addin"
set labelsComboBox to (combo box 2 of group 1 of window 1 of application process "DYMO Word Addin")
tell labelsComboBox
set {xPosition, yPosition} to position of labelsComboBox
set {xSize, ySize} to size
end tell
set {realXPosition, realYPosition} to {(xPosition + (xSize div 2)) as string, (yPosition + (ySize div 2)) as string}
do shell script "/usr/local/bin/cliclick m:" & realXPosition & "," & realYPosition & " dc:" & realXPosition & "," & realYPosition
-- combo box arrow
click UI element 1 of labelsComboBox
...
Here you can find someone with a similar question and the answer was also cliclick
https://discussions.apple.com/message/17662850#17662850