How do you work backward and get the button from other people code - applescript

Let say this was the code provided? How do I get to see the “list 1 of group 2 of group 1 of group 1)? I understand that you would need to use the accessibility inspector but I have no clue how to do it. Hope someone can help out. Thank you!!!
tell application "System Events"
--mission control starten
tell application "Mission Control" to launch
delay 0.25
tell process "Dock"
set countSpaces to count buttons of list 1 of group 2 of group 1 of group 1
--new space
click button 1 of group 2 of group 1 of group 1
--switch to new space
repeat until (count buttons of list 1 of group 2 of group 1 of group 1) = (countSpaces + 1)
end repeat
click button (countSpaces + 1) of list 1 of group 2 of group 1 of group 1
end tell
delay 0.25
tell application "Calendar" to launch
tell application "Reminders" to launch
end tell

Related

Is there a way to incorporate keystrokes when website fails to load?

I don't know a lot about AppleScript but I have the following computer generated code that I got from automator on Mac. It automates sequential clicks of the same two images on Safari. Sometimes the website gets overloaded and it throws an error 508 for resource limit reached, causing the script to fail as there's no links available for it to click.
My question is whether there's a way to refresh the website every time it throws back the error (by pressing "Command+R" or similar) so that the script may continue running.
Please feel free to re-write the code if it needs help elsewhere
set timeoutSeconds to 120.0
set firstClick to "click image 1 of group 1 of UI Element 38 of UI Element 1 of scroll area 1 of group 1 of group 1 of tab group 1 of splitter group 1 of window \"Inventory - game.net\" of application process \"Safari Technology Preview\""
set secondClick to "click image 1 of UI Element 2 of group 25 of UI Element 1 of scroll area 1 of group 1 of group 1 of tab group 1 of splitter group 1 of window \"Inventory - game.net\" of application process \"Safari Technology Preview\""
repeat 40000 times
my doWithTimeout(firstClick, timeoutSeconds)
delay (random number from 0.2 to 0.75)
my doWithTimeout(secondClick, timeoutSeconds)
delay (random number from 0.2 to 0.75)
end repeat
on doWithTimeout(uiScript, timeoutSeconds)
set endDate to (current date) + timeoutSeconds
repeat
try
run script "tell application \"System Events\"
" & uiScript & "
end tell"
exit repeat
on error errorMessage
if ((current date) > endDate) then
error "Can not " & uiScript
end if
end try
end repeat
end doWithTimeout

How do I double click on an image/or link to initiate installation? APPLESCRIPT [Please view image]

I am trying to automate the installation of slack. I run the .dmg then must double click the "Slack" icon to start the install. using the '''click''' function on images is not really doable im guessing.. I see that the URL this image calls on is file:///Volumes/Slack.app/Slack.app/ Do I need to call on this link perhaps ? How can I get the same results of double clicking on the image.
Accessibility Inspector Screenshot
tell application "Finder"
set myFolder to container of (path to me) as alias
end tell
tell application "Finder"
open document file "Slack-4.3.3-macOS.dmg" of myFolder
end tell
tell application "System Events"
tell process "Finder"
click image "Slack" of group 1 of list 1 of list 1 of scroll area 1 of splitter group 1 of splitter group 1 of window "Slack"
end tell
end tell
Accessibility Inspector Screenshot
If you are still interested in doing this job by clicking the image in AppleScript, you can try code below:
tell application "System Events"
tell its application process "Finder"
tell image "Slack.app" of group 1 of list 1 of list 1 of scroll area 1 of splitter group 1 of splitter group 1 of window "Slack.app"
ignoring application responses
perform action "AXShowMenu"
end ignoring
end tell
end tell
end tell
delay 0.3
do shell script "killall System\\ Events"
delay 0.1
tell application "System Events"
tell its application process "Finder"
tell image "Slack.app" of group 1 of list 1 of list 1 of scroll area 1 of splitter group 1 of splitter group 1 of window "Slack.app"
--key code 125 --also can try use arrow key to select item in context menu
keystroke "Open"
delay 0.2
keystroke return
end tell
end tell
end tell
I test this code on my MacOS 10.12.6, it works OK. Even though it's easy to use terminal command to do this job, this method involves some very useful AS knowledge point.
1st : perform action "AXOpen" and "AXShowMenu"
2nd : show context menu and select menu item
3rd : deal with system delay
If it doesn't have delay issue, you can try the code below, which is more simpler,(also works on my machine):
tell application "System Events"
tell its application process "Finder"
tell image "Slack.app" of group 1 of list 1 of list 1 of scroll area 1 of splitter group 1 of splitter group 1 of window "Slack.app"
perform action "AXShowMenu"
delay 0.3
keystroke "Open"
delay 0.2
keystroke return
end tell
end tell
end tell

Unable to click checkbox of System Preferences by AppleScript, although it doesn't show errors

Errors
I had written the code below, and it seems to work until it select the row.
However, click checkbox doesn't work even though it doesn't give any errors.
tell application "System Preferences"
activate
reveal anchor "shortcutsTab" of pane id "com.apple.preference.keyboard"
end tell
tell application "System Events"
tell application process "System Preferences"
repeat while not (window 1 exists)
end repeat
tell window 1
repeat while not (rows of table 1 of scroll area 1 of splitter group 1 of tab group 1 exists)
end repeat
repeat with current_row in (rows of table 1 of scroll area 1 of splitter group 1 of tab group 1)
if value of static text 1 of current_row is equal to "Input Sources" then
select current_row
exit repeat
end if
end repeat
repeat while not (rows of outline 1 of scroll area 2 of splitter group 1 of tab group 1 exists)
end repeat
repeat with current_row in rows of outline 1 of scroll area 2 of splitter group 1 of tab group 1
if name of UI element 2 of current_row is equal to "Select next source in input menu" then
select current_row
click checkbox of current_row
exit repeat
end if
end repeat
end tell
end tell
end tell
What I have tried
I wrote below alternatively, but they all not work.
set value of checkbox of selected_row
set checkbox of selected_row to true
References
I searched many articles, but it doesn't solve.
How to click a checkbox of a drop-down tab in System Preferences
http://hints.macworld.com/article.php?story=20040317131326880
Any help is appreciated.
Change:
click checkbox of current_row
To:
click checkbox of UI element 1 of current_row
Tested your script on macOS Mojave, making the change shown above, and it worked as desired.

Can't get a menu (or menu item) of a pop up button in Logic Pro X using AppleScript

so basically i want to write an AppleScript that launches a plugin in Logic Pro X, but even after clicking the pop up button, it can't reach the menu (therefore none of the menu items (plug-ins))
this is the menu
here is what i have tried, i found where the "Audio FX" pop up button is and i can click it, but i want to know if there is any way to reach menu 1 of it? according to automator's watch-me-do it should be there but for some reason i can't get into the menu
tell application "Logic Pro X" to activate
tell application "System Events"
tell process "Logic Pro X"
set frontmost to true
tell (first window whose subrole is "AXStandardWindow")
tell group "Audio FX" of group 1 of group 1 of list 1 of list 1 of group 2
tell pop up button 1
click
click menu item 3 of menu 1
end tell
end tell
end tell
end tell
end tell
so the error that i get is this:
error "System Events got an error: Can’t get menu 1 of pop up button 1 of group \"Audio FX\" of group 1 of group 1 of list 1 of list 1 of group 2 of window 1 of process \"Logic Pro X\" whose subrole = \"AXStandardWindow\". Invalid index." number -1719
I agree with #Ted Wrigley 's comment about it may be an issue of race condition. Something like this may work for you.
tell application "Logic Pro X" to activate
tell application "System Events"
tell process "Logic Pro X"
set frontmost to true
tell (first window whose subrole is "AXStandardWindow")
tell group "Audio FX" of group 1 of group 1 of list 1 of list 1 of group 2
repeat while not (exists of pop up button 1)
delay 0.1
end repeat
tell pop up button 1
click
repeat while not (exists of menu item 3 of menu 1)
delay 0.1
end repeat
click menu item 3 of menu 1
end tell
end tell
end tell
end tell
end tell

How to download a new voice for say's function with AppleScript?

I'm searching a method to install different voices (2 to be exact) on the system preferences.
The voices are "Alex" for an english voice and "Thomas" for a french voice.
I've tried directly by console but didn't succeed, that's why I've turned to the AppleScript language, but I never used this language.
The code I've for the moment is
set osver to system version of (system info)
if osver is equal to "10.6.8" then
display dialog ("Downloading voices is only available in OS X Lion and higher")
else
tell application "System Preferences"
activate
reveal (pane id "com.apple.preference.speech")
end tell
try
tell application "System Events"
click radio button 2 of tab group 1 of window 1 of process "System Preferences"
repeat until (exists pop up button of tab group 1 of window 1 of process "System Preferences")
delay 2
end repeat
delay 2
click pop up button 1 of tab group 1 of window 1 of process "System Preferences"
delay 2
click menu item -1 of menu 1 of pop up button of tab group 1 of window 1 of process "System Preferences"
delay 2
end tell
on error
display dialog ("An error happend")
end try
end if
This program is opening the voice window but the display dialog appears every time whatever the index I put.
If you have another idea to download the voices, or if you can help me to understand what is not working, I will be grateful.
This worked for me in 10.9:
tell application "System Preferences"
reveal anchor "TTS" of pane id "com.apple.preference.speech"
activate
end tell
tell application "System Events" to tell window 1 of process "System Preferences"
tell pop up button 1 of tab group 1
click
click menu item "Customize..." of menu 1
end tell
delay 1
repeat with r in UI element 1 of rows of table 1 of scroll area 1 of sheet 1
if exists static text 1 of r then
if {"Alex", "Thomas"} contains value of static text 1 of r then
if value of checkbox 1 of r is 0 then click checkbox 1 of r
end if
end if
end repeat
click button "OK" of sheet 1
end tell
It took multiple seconds to run the script though.

Resources