Я пишу AppleScript, который запускает Netflix в стиле приложения.Он проверяет, открыт ли Netflix на какой-либо вкладке, и если это так, он «активирует» это окно (фокусируется на нем), а затем устанавливает его на вкладке Netflix.Если Netflix не открыт, он откроется в новом окне.
Я получаю странную ошибку: «Ошибка обработчика событий Apple».Что вызывает эту ошибку?
Вот полный код:
set netflixIsOpen to false
tell application "Safari"
repeat with i from 1 to (count of windows)
repeat with j from 1 to (count of (tabs of window i))
set theURL to URL of tab j of window i
if theURL contains ".netflix.com/" then
-- display dialog "netflix found!"
set netflixIsOpen to true
set miniaturized of window i to false
activate window i
tell window i
set current tab to tab j
-- if not logged in, then go to the homepage
if theURL does not contain "movies.netflix.com/" then
set URL of tab j to "http://movies.netflix.com/WiHome"
end if
end tell
exit repeat
end if
end repeat
end repeat
if not netflixIsOpen then
make new document with properties {URL:"http://movies.netflix.com/WiHome"}
end if
end tell
Редактировать: Ошибка фокусировки на "(количество (вкладок окна i))".
Вот отладка:
count every tab of window 2
--> error number -10000
Result:
error "Safari got an error: AppleEvent handler failed." number -10000
Было открыто только одно окно.Кажется, что AppleScript всегда считает одно дополнительное окно.Почему это происходит и как это можно исправить?