Как закрыть окно настроек Safari с помощью AppleScript? - PullRequest
0 голосов
/ 11 июля 2019

Я использую приведенный ниже скрипт для включения меню разработчика.

tell application "Safari"
    tell application "System Events"
        tell process "Safari"
            click menu item "Preferences…" of menu 1 of menu bar item "Safari" of menu bar 1
            click button "Advanced" of toolbar 1 of window 1
            click checkbox "Show Develop menu in menu bar" of group 1 of group 1 of window 1
            -- delay 2
            keystroke "w" using {command down}  -- > not working
        end tell
    end tell
end tell

Как закрыть окно настроек?С keystroke "w" using {command down} я получаю не могу The document cannot be closed while the script is running. ошибка.


Также как включить флажок, только если он не включен?В настоящее время, если я запускаю скрипт дважды, он переключается.

Ответы [ 2 ]

1 голос
/ 12 июля 2019

Этот код AppleScript работает для меня, используя последнюю версию macOS Mojave.

tell application "System Events"
    tell application process "Safari"
        set frontmost to true
    end tell
    keystroke "." using {command down}
end tell
1 голос
/ 11 июля 2019

Просто нажмите первую кнопку первого окна и отметьте value флажка

tell application "Safari"
    tell application "System Events"
        tell process "Safari"
            click menu item "Preferences…" of menu 1 of menu bar item "Safari" of menu bar 1
            click button "Advanced" of toolbar 1 of window 1
            tell checkbox "Show Develop menu in menu bar" of group 1 of group 1 of window 1
                if value is 0 then click it
            end tell
            click button 1 of window 1
        end tell
    end tell
end tell
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...