Сегодня мне понадобилось написать программу, которая ловит окошко от NetAuthAgent и нажимает там единственную кнопку – OK.
На поиск необходимого пути решения ушло 2 часа (из-за незнания области и библиотек).
Далее привожу эволюции скрипта (причем все работают!!!)
вариант Сишника
set names to “”
tell application “System Events”
repeat with proc in processes
set pn to name of proc
if pn is equal to “NetAuthAgent” then
set b to count of every window of proc
if b is equal to 1 then
tell application “NetAuthAgent”
activate
delay 0.3
tell application “System Events” to keystroke space
end tell
end if
end if
end repeat
end tell
Напоминает Паскаль и 1С
Теперь это постепенно мутируем в мак-вариант.
tell application “System Events”
set proc to first process whose name is “NetAuthAgent”
set b to count of every window of proc
if b is equal to 1 then
tell application “NetAuthAgent”
activate
delay 0.3
tell application “System Events” to keystroke space
end tell
end if
end tell
Более яблочно, но все равно еще пахнет паскалем.
tell application “System Events”
if (count of every window of the (first process whose name is “NetAuthAgent”)) is equal to 1 then
tell application “NetAuthAgent”
activate
delay 0.3
tell application “System Events” to keystroke space
end tell
end if
end tell
Вот уже полноценный яблочный вариант.
Хотя… нет! У нас там закралась грамматическая ошибка! Условие не по-английски звучит!
))
Итак, правим грамматику.
if (count of every window of the (first process whose name is “NetAuthAgent”)) is equal to 1 then
Меняем на
if (count of windows of the (first process whose name is “NetAuthAgent”)) is equal to 1 then
И результат :
tell application “System Events”
if (count of windows of the (first process whose name is “NetAuthAgent”)) is equal to 1 then
tell application “NetAuthAgent”
activate
delay 0.3
tell application “System Events” to keystroke space
end tell
end if
end tell
Перл… Паскаль… 1С застрелились