Как сделать так, чтобы Applescript закрыл диалоговое окно подтверждения - PullRequest
0 голосов
/ 27 мая 2019

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

Это очень просто и работает нормально, но диалоговое окно подтверждения, отправленное ОС ", вы уверены, что хотите выключить компьютер сейчас " с таймером, а не передним окном, поэтому пользователь должен щелкните внутри этого диалогового окна, чтобы активировать его, а затем нажмите нужную кнопку.

Если это диалоговое окно подтверждения будет передним, простой ключ ввода подтвердит выбор. Есть идеи о том, как вывести это диалоговое окно наверх?

tell application "Finder"
set userChoice to my getChoixUser("list") -- choose from list

try
    if (userChoice contains "Veille") then -- sleep
        tell application "Finder" to sleep
    else if (userChoice contains "Eteindre") then -- shut down
        tell application "loginwindow" to «event aevtrsdn»
    else if (userChoice contains "Redémarrer") then -- restart
        tell application "loginwindow" to «event aevtrrst»
    else if (userChoice contains "économiseur") then -- screen saver
        tell application "System Events" to start current screen saver
    end if

on error errMsg
    beep
    tell application "Finder" to display dialog errMsg buttons {"OK"} default button 1 with title scriptName with icon 0
end try

конец сказать

1 Ответ

1 голос
/ 27 мая 2019

Снимите включающий Finder блок Tell и активируйте окно с помощью сценариев GUI

set userChoice to getChoixUser("list") -- choose from list

try
    if (userChoice contains "Veille") then -- sleep
        tell application "Finder" to sleep
    else if (userChoice contains "Eteindre") then -- shut down
        tell application "loginwindow" to «event aevtrsdn»
        focusLoginWindow()
    else if (userChoice contains "Redémarrer") then -- restart
        tell application "loginwindow" to «event aevtrrst»
        focusLoginWindow()
    else if (userChoice contains "économiseur") then -- screen saver
        tell application "System Events" to start current screen saver
    end if

on error errMsg
    beep
    tell application "Finder" to display dialog errMsg buttons {"OK"} default button 1 with title scriptName with icon 0
end try

on focusLoginWindow()
    tell application "System Events" to tell process "loginwindow"
        repeat until exists window 1
            delay 0.2
        end repeat
        set attribute "AXFocused" of window 1 to true
    end tell
end focusLoginWindow
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...