我已经自动使用“ applescript”和“ Calendar”打印每周日历。有一个滚动区域,其中包含复选框。您如何遍历滚动区域中的每个复选框并取消选中它?
https://gist.github.com/spuder/c92dd0637ce85b6960b81e1415d7c52e
这行得通,但是易碎,因为行是硬编码的。
-- Click the “<fill in title>” checkbox.
delay 0.5
set timeoutSeconds to 2.0
set uiScript to "click checkbox 1 of row 2 of outline 1 of scroll area 1 of window \"Print\" of application process \"Calendar\""
my doWithTimeout(uiScript, timeoutSeconds)
-- Click the “<fill in title>” checkbox.
delay 1
set timeoutSeconds to 2.0
set uiScript to "click checkbox 1 of row 3 of outline 1 of scroll area 1 of window \"Print\" of application process \"Calendar\""
my doWithTimeout(uiScript, timeoutSeconds)
-- Click the “<fill in title>” checkbox.
delay 1
set timeoutSeconds to 2.0
set uiScript to "click checkbox 1 of row 4 of outline 1 of scroll area 1 of window \"Print\" of application process \"Calendar\""
my doWithTimeout(uiScript, timeoutSeconds)
看来应该有效,但它不会取消选中任何框
delay 1
set timeoutSeconds to 2.0
set uiScript to "click checkbox 1 of every row of outline 1 of scroll area 1 of window \"Print\" of application process \"Calendar\""
my doWithTimeout(uiScript, timeoutSeconds)
答案 0 :(得分:3)
这对于使用最新版本的macOS Mojave的我来说有效
tell application "Calendar"
activate
reopen
end tell
tell application "System Events" to tell application process "Calendar"
if not (exists of window "Print") then keystroke "p" using command down
repeat while not (exists of window "Print")
delay 0.1
end repeat
set everyCheckboxRef to a reference to every checkbox of rows of outline 1 ¬
of scroll area 1 of window 1
repeat with i from 1 to count of everyCheckboxRef
set thisCheckbox to item i of everyCheckboxRef
if value of thisCheckbox is 1 then perform action "AXPress" of thisCheckbox
end repeat
end tell
答案 1 :(得分:2)
以下示例 AppleScript 代码是一种实现方法,它取消选中< 日历应用程序中打印 对话框框中的strong>日历 部分:
-- # Check to see if Calendar is open and act accordingly.
if running of application "Calendar" then
-- # Calendar is already open however, make sure the main window is showing not minimized.
tell application "Calendar"
if not (visible of window "Calendar") then set visible of window "Calendar" to true
activate -- # Bring the main window forward.
end tell
else
-- # Calendar is not open, so open it.
tell application "Calendar"
activate
-- # Wait for main window before proceeding.
repeat until exists window "Calendar"
delay 0.1
end repeat
end tell
end if
-- # Open the Print dialog box.
tell application "System Events" to keystroke "p" using command down
-- # Make sure the Print dialog box is showing before proceeding.
tell application "Calendar"
repeat until exists window "Print"
delay 0.1
end repeat
end tell
-- # Uncheck all checkboxes in the Calendars scroll area of the Print dialog box.
tell application "System Events"
tell outline 1 of scroll area 1 of window "Print" of application process "Calendar"
repeat with i from 1 to (count rows)
tell row i
if (count UI element) > 0 then
click checkbox 1
end if
end tell
end repeat
end tell
end tell
注意:示例 AppleScript 代码就是这样,并且不包含任何其他适当的错误处理。用户有责任添加适当,需要或想要的任何错误处理。在 try
中查看error
声明和AppleScript Language Guide 声明。另请参见Working with Errors。此外,UI脚本可能需要根据需要,需要或需要使用delay
命令。