Applescript установите все флажки в области прокрутки - PullRequest
0 голосов
/ 21 января 2019

Я автоматизировал печать еженедельного календаря с помощью «applecript» и «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)

enter image description here

Похоже, должно работать, но не снимать флажки

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)

Ответы [ 2 ]

0 голосов
/ 22 января 2019

Это работает для меня, используя последнюю версию 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
0 голосов
/ 21 января 2019

Следующий пример AppleScript код - это один из способов снять отметку со всех флажков в календарях раздел диалогового окна Print в приложении Calendar :

    --  # 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 . См. Также Работа с ошибками . Кроме того, для сценариев пользовательского интерфейса может потребоваться использование delay команды в зависимости от ситуации, необходимости или необходимости.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...