how to get the context menu after perform AXShowMenu in AppleScript - macos

my code like this
tell button 1 of window 1
perform action "AXShowMenu"
delay 0.2
end tell
after the menu is shown, how to get the menu? many thanks

It's the items of menu 1 of the drop down button:
tell button 1 of window 1
click
delay 0.2
get every menu item of menu 1
--click menu item "name" of menu 1
end tell

Related

Applescript Click item in system menu bar after opening it

I can open the bluetooth dropdown menu item with this code but I don't know how to actually click on any of the items in the menu.
tell application "System Events" to tell process "ControlCenter"
click menu bar item "Bluetooth" of menu bar 1
end tell
What would be a command to click on something in the open bluetooth menu?
This following AppleScript code should accomplish what you are trying to achieve. Just replace the "Mac Pro" part of the code with the name of the item you want to click.
tell application "System Events" to tell process "ControlCenter"
click menu bar item "Bluetooth" of menu bar 1
repeat until exists of checkbox 1 of scroll area 1 of window 1
delay 0.1
end repeat
click checkbox "Mac Pro" of scroll area 1 of window 1
key code 53 -- Press escape key
end tell
This following AppleScript code will return the names of the checkboxes so you can easily know your options to use in the first code.
tell application "System Events" to tell process "ControlCenter"
click menu bar item "Bluetooth" of menu bar 1
repeat until exists of checkbox 1 of scroll area 1 of window 1
delay 0.1
end repeat
set checkBoxNames to name of checkboxes of scroll area 1 of window 1
end tell

How can I choose a menu item from dropdown menu using AppleScript (Big Sur OS)

For Catalina I would only do something like this in Preview
click pop up button 3
click menu item "Study Edge" of menu 1 of pop up button 3
But for Big Sur this no longer works :(
After adding splitter group which is now needed for Big Sur my code looks as follows:
tell sheet 1
tell splitter group 1
click pop up button 3
click menu item "Study Edge" of menu 1 of pop up button 3
end tell
click menu button "PDF"
repeat until exists menu 1 of menu button "PDF"
delay 0.02
end repeat
click menu item "Save as PDF" of menu 1 of menu button "PDF"
end tell
But it is not able to find the menu item "Study Edge"

Setting a Popup Buttons Value from Applescript

I'm trying to set an external applications settings with an applescript. I currently have
tell application "System Events"
tell process "Pro Tools"
click menu item "Save Copy In..." of menu "File" of menu bar 1
tell pop up button 4 of window "Save Copy In..."
click
set value to "AIFF"
end tell
end tell
end tell
But nothing happens at the set value point. Any help would be gratefully received! Attached is a screenshot of where I'm stuck at.
I think you just need to wait until the "Save Copy In..." window appears. Try this code, which adds a delay loop looking for the window.
tell application "System Events"
tell process "Pro Tools"
tell menu bar 1's menu "File"
click menu item "Save Copy In..."
end tell
repeat until (exists window "Save Copy In...")
delay 0.1
end repeat
tell window "Save Copy In..."'s pop up button 4
click
-- the menu does not appear inthe PUB's view heirarchy until after it's clicked
tell menu 1
click menu item "AIFF" -- 'pick' should work too
end tell
end tell
end tell
end tell
Try to insert a short delay to make sure the menu is available and rather than setting the value pick the menu item.
tell application "System Events"
tell process "Pro Tools"
click menu item "Save Copy In..." of menu "File" of menu bar 1
tell pop up button 4 of window "Save Copy In..."
click
delay 0.2
pick menu item "AIFF" of menu 1
end tell
end tell
end tell
The command pick is not documented, it's a synonym of click.

UI automation, appleScript Keyboard shortcuts for non-menued items Preview?

I am trying to create a keyboard shortcut action for Preview, namely Draw and Sketch. However, they are are the NON-menued items, which means can't get it done in System Preference I see someone done it from inspiration, it is possible, but when I try to follow alone, here is my code so far and please help me complete this. here are the action.
Here is the error I am facing now
after some researches, does the UI/accessibility inspector help?
activate application "Preview"
delay 0.4
set the menuItem to "Draw"
tell application "System Events"
try
tell application process "Preview" to click radio button menuItem of radio group 1 of splitter group 1 of window 1
on error
try
tell application process "Preview" to click radio button menuItem of radio group 1 of window 1
on error errorM
display dialog errorM
end try
end try
end tell
ideally, trying to make it to work when all bars are hidden,
but if not possible. can we make it to work vwith mark up bar is shown. as below.
This work for me using the latest version of macOS Mojave
tell application "Preview" to activate
repeat while application "Preview" is not running
delay 0.2
end repeat
tell application "System Events"
try
click menu item "Show Markup Toolbar" of menu 1 of menu bar item "View" of menu bar 1 of application process "Preview"
end try
delay 0.5
try
click menu item "Show Toolbar" of menu 1 of menu bar item "View" of menu bar 1 of application process "Preview"
end try
delay 0.5
repeat while not (exists of toolbar 1 of window 1 of application process "Preview")
delay 0.2
end repeat
set description2 to a reference to every checkbox of toolbar 1 of window 1 of application process "Preview"
set theCheckboxes to description of description2
if item 1 of theCheckboxes is "Draw" then
set checkBoxDraw to 1
else
set checkBoxDraw to 2
end if
if item 1 of theCheckboxes is "Sketch" then
set checkBoxSketch to 1
else
set checkBoxSketch to 2
end if
delay 1
-- Below, insert either checkBoxSketch for "Sketch" or checkBoxDraw for "Draw"
click checkbox checkBoxDraw of toolbar 1 of window 1 of application process "Preview"
end tell
-- without these next following lines, the toolbar "Draw" or "Sketch" do not appear to be selected
tell application "Preview" to tell window 1
set visible to false
set visible to true
end tell
delay 3

AppleScript toggling checkmarks beside menu items

This is an extension of a previous question
Applescript: on clicking Menu Bar item via gui script
On the highlighted menu item below for the f.lux menu bar, if you click it, there will be a checkmark indicating that the "Disable for an hour" feature has been enabled. What I'm trying to do is write a GUI AppleScript for f.lux where the user can decide to toggle the check mark by typing a keyword in Alfred followed by a 1 or a 0 where 1 serves to enable the "Disable for an hour" and 0, serves to keep it unchecked.
This is a screen shot of the menu bar for f.lux
I am however having a hard time figuring out what attribute to adjust for the "Disable for an hour" menu item in order to toggle the checkmark. Here is the code, but I get an unexpected token error when compiling it via applescript editor. So far what I'm trying to do is target the "menu item mark character" attribute indicated by the arrow in screenshot above, but I'm not sure if this is the right approach to toggle the "Disable for an hour" item. Can someone please give me advice?
on alfred_script(q)
set myOption to q as integer
ignoring application responses
tell application "System Events" to tell process "Flux"
click menu bar item 1 of menu bar 2
end tell
end ignoring
do shell script "killall System\\ Events"
delay 0.1
tell application "System Events" to tell process "Flux"
tell menu bar item 1 of menu bar 2
if myOption is 1 then
set ✓ to value of attribute "AXMenuItemMarkChar" of menu item "Disable for an hour" of menu 1
else if myOption is 0 then
set nil to value of attribute "AxMenuItemMarkChar" of menu item "Disable for an hour" of menu 1
end if
end tell
end tell
end alfred_script
This seems to work:
tell application "System Events" to tell process "Flux"
tell menu bar item 1 of menu bar 2
set v to (value of attribute "AXMenuItemMarkChar" of menu item "Disable for an hour" of menu 1) as string
if (v = "" and myOption = 1) or (v is not equal to "" and myOption = 0) then
click menu item "Disable for an hour" of menu 1
else
key code 53
end if
end tell
end tell

Resources