Using safari on this website I can get applescript to change the input values for R G and B but I cannot Applescript to update the screen to reflect the new color. The screen only changes when you tab out of the box.
tell text field 1 of group 1 of group 4 of group 4 of UI element 1 of scroll
area 1 of group 1 of group 1 of tab group 1 of splitter group 1 of window "RGB
Color Codes Chart"
set value to item i of red1
end tell
The above code changes the value in safari of that cell but I cannot get Safari to update its screen.
Related
I'm trying to get the position of a UI element from the Notification Center. I can do so when I get a list of coordinates (an x and y posn) and then reference each one individually. However when I try to do it directly, I get a type coercion error.
System Events got an error: Can’t make item 1 of position of group 1 of UI element 1 of scroll area 1 of window "Notification Center" of process "Notification Center" into type specifier..
Here's the example code:
activate application "NotificationCenter"
tell application "System Events"
tell process "Notification Center"
-- works
set xyPositions to position of group 1 of UI element 1 of scroll area 1 of window "Notification Center"
set xPos to item 1 of xyPositions
-- fails with error
set xPos to item 1 of position of group 1 of UI element 1 of scroll area 1 of window "Notification Center"
end tell
end tell
I'd like to know what's going on, since the two methods seem equivalent.
They look equivalent but they are not:
set xyPositions to position of group 1 of UI element 1 of scroll area 1 of window "Notification Center"
is really shorthand for:
set xyPositions to get position of group 1 of UI element 1 of scroll area 1 of window "Notification Center"
When AppleScript sees an object specifier, it determines if that specifier points to a property or element(s) of a local AppleScript value (string, list, record, etc) or a remote application (in this case, System Events).
If the specifier points to an application, and the specifier isn’t already a parameter to an application command (move, duplicate, delete, etc), AppleScript automatically performs a get command (aka “implicit get”) to resolve that object specifier. In your example, this returns the value of the position property, which is an AppleScript list. The second line then works as you’d expect:
set xPos to item 1 of xyPositions
as AppleScript extracts the first item of that list.
When you combine the two lines into one, you are telling the application to get item 1 of the position property:
set xPos to [get] item 1 of position of group 1 of UI element 1 of scroll area 1 of window "Notification Center"
However the application doesn’t know how to do this—it can only access objects within its object model. It doesn’t know how to manipulate the contents of primitive strings, lists, records, etc; only AppleScript can do that. Thus the application command fails.
If you wish to combine the two lines into one, you must use an explicit get command to resolve the application specifier before manipulating its result:
set xPos to item 1 of (get position of group 1 of UI element 1 of scroll area 1 of window "Notification Center")
Yes, it’s confusing. But that’s AppleScript for you: it tries to be “simple” and “helpful” to make it easy for non-experts to use, but really all it does is obfuscate what’s actually going on underneath that superficially friendly syntax. When it works, it’s like arcane magic. When it confounds, it’s like arcane magic. So it goes.
safari->preferences->websites->Page Zoom-> click on "when visiting other websites" and make this to 100% if option ranges in number from 50% to 200%
Need an applscript for this.
click on this to see the image where i am looking for the zoom setting to 100%
AppleScript 1: Set Safari default Page Zoom to 100%
tell application "System Events" to tell application process "Safari"
set frontmost to true
keystroke "," using command down -- Open Safari Preferences window
click button "Websites" of toolbar 1 of window 1
-- Need for seeing, selecting or clicking groups (or panes) under Websites window
tell group 1 of group 1 of window "Websites"
select row 5 of table 1 of scroll area 1 of group 1
-- group 1: left pane. row 5: Page Zoom
click pop up button of group 2
-- group 2: right pane. Revealed from the command "UI element" in AppleScript 2 below
click menu item "100%" of menu 1 of pop up button of group 2
end tell
keystroke "w" using {shift down, command down}
-- Or, keystroke "w" using command down: close Preferences window
end tell
MacOS 11.6.8 Big Sur
Explanation: see comments after -- on each lines.
Add a line "delay 1" between action command (Eg: keystroke, click and select) lines if your Mac needs.
You may script changes of Safari and other apps' Preferences in a similar way.
AppleScript 2: Find out all UI elements after some UI actions
To find out which UI elements (such as window, toolbar, button, group, scroll area, table, row, pop up button, menu, menu item) are available after some UI actions, put the command "UI element" under their parent UI element in Script Editor (NOT Automator). Eg:
tell application "System Events" to tell application process "Safari"
set frontmost to true
keystroke "," using command down
click button "Websites" of toolbar 1 of window 1 -- Need
UI element of group 2 of group 1 of group 1 of window "Websites"
end tell
Result: (below the script in Script Editor)
--> {static text "Control the page zoom level on the websites below:" ...,
group 1 ...,
pop up button 1 of group 2 of group 1 of group 1 of window "Websites" of application process "Safari" of application "System Events",
-- Useful in AppleScript 1 above
static text "When visiting other websites:" ...,
button "Remove" ...}
Attention: the action command 'click button "Websites" ...' is required to display the UI elements after it.
Note: Pls encourage new contributor and vote up if you find this answer useful. Thanks!
I have a checkbox in the following hierarchy:
Outline->Row->Cell->Checkbox
This is how it looks in accessibility inspector:
I need to click on it.
So, I tried:
click checkbox 1 of cell 1 of row 3 of outline 1 of scroll area 2 of splitter group 1 of tab group 1 of window 1
This gives the error:
Expected end of line, etc. but found number.
If I try to select the row like this:
select row 3 of outline 1 of scroll area 2 of splitter group 1 of tab group 1 of window 1
The row is getting selected.
Also, I can read the properties of the row like so:
get properties row 3 of outline 1 of scroll area 2 of splitter group 1 of tab group 1 of window 1
but not the properties of the checkbox/cell using:
get properties of checkbox 1 of cell 1 of row 3 of outline 1 of scroll area 2 of splitter group 1 of tab group 1 of window 1
I'm an absolute n00b at applescript, I have no, I idea what is going wrong.
Can anyone help?
PS: I am trying to turn off the screenshot shortcuts with in system preferences.
It's choking on the specifier for AXCell. Cell doesn't work. Just use UI Element 1:
tell application "System Events"
tell process "System Preferences"
click checkbox 1 of UI element 1 of row 3 of outline 1 of scroll area 2 of splitter group 1 of tab group 1 of window 1
end tell
end tell
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
Is there any way (or are there any tools) to batch change the source of a Table Occurrence from a local file to an externally sourced file?
Situation: I manage a hosted database with hundreds of Table Occurrences of 15 or so tables. Some of my users access the database with slow internet connections. While many of the tables need to be updated for the entire workgroup, some data on other tables and UI information is mostly static.
I'd like to take a copy of the database, change the Table Occurrences of the tables which must be shared from a Local File source to an External Source (of the existing server.) I can do this by hand, but it would require thousands of clicks and be prone to inaccuracy. Much better if I can automate the process. (To specify, say, that all Occurrences of my Sales Table move from Local File to External Source.)
I realize that I might be able to so something with AppleScript's UI Scripting if there's not a better way to do it.
No answers so far, so I wrote this yesterday. It's dirty, long-winded and doesn't catch errors but it'll do the job and is something to build off of for the future.
--to prepare to run this script, you should already have the External Data Source set up
--you should also open the Manage > Database menu and select the "Relationships" tab
--set newDataSource to the name of the new external data source
set newDataSource to ""
--obtain tableOccurrences from TableNames ( Get ( FileName ) ) in the Data Viewer and copy the list into the tableOccurrences variable below
--note that tableOccurrences will be a return-separated list which is quite long when set
set tableOccurrences to ""
--a list of which tables should be moved from the local file to the hosted file. Note that these should be proper table names not table occurrences
set tablesToReplace to {"table1", "table2", ..., "tableN"}
tell application "FileMaker Pro Advanced"
activate
end tell
set AppleScript's text item delimiters to {return}
set j to the number of text items of tableOccurrences
repeat until j < 1
tell application "System Events"
tell application Process "FileMaker Pro Advanced"
keystroke text item j of tableOccurrences
keystroke "o" using command down
delay 1
set i to 1
repeat until ((i > (count of rows of table 1 of scroll area 1 of window 1)) or selected of row i of table 1 of scroll area 1 of window 1)
set i to i + 1
end repeat
if (i <= (count of rows of table 1 of scroll area 1 of window 1) and name of static text of row i of table 1 of scroll area 1 of window 1 is in tablestoReplace) then
set currentMasterTable to name of static text of row i of table 1 of scroll area 1 of window 1
set currentOccurrenceName to value of text field 1 of window 1
click pop up button 1 of window 1
tell menu 1 of pop up button 1 of window 1
click menu item newDataSource
end tell
set k to 1
set tableSelected to false
repeat until tableSelected or k > (count of rows of table 1 of scroll area 1 of window 1)
if name of static text of row k of table 1 of scroll area 1 of window 1 = currentMasterTable then
select row k of table 1 of scroll area 1 of window 1
set tableSelected to true
end if
set k to k + 1
end repeat
set value of text field 1 of scroll area 1 of window 1 to currentOccurrenceName
click button "OK" of window 1
else
click button "Cancel" of window 1
end if
end tell
end tell
set j to j - 1
end repeat