Applescript Can';无法间歇性抛出进程的窗口1

Applescript Can';无法间歇性抛出进程的窗口1,applescript,Applescript,我有一个applescript保存为常开应用程序,通常可以正常工作。但是,在一些奇怪的情况下,它会抛出错误: 系统事件出错:无法获取进程“FaceTime”的窗口1。索引无效。(-1719) 通常在FaceTime应用程序关闭时发生,但并不总是如此。奇怪 有谁能建议我如何消除这种情况或编写更好的代码来避免这种情况 这是我的密码: on idle if application "FaceTime" is running then tell application "System Event

我有一个applescript保存为常开应用程序,通常可以正常工作。但是,在一些奇怪的情况下,它会抛出错误: 系统事件出错:无法获取进程“FaceTime”的窗口1。索引无效。(-1719) 通常在FaceTime应用程序关闭时发生,但并不总是如此。奇怪

有谁能建议我如何消除这种情况或编写更好的代码来避免这种情况

这是我的密码:

on idle
if application "FaceTime" is running then
    tell application "System Events"
        tell process "FaceTime"
            if get value of attribute "axFullScreen" of window 1 = false then
                set FullscreenButton to a reference to (button "Full Screen" of window 1)
                if FullscreenButton exists then
                    click FullscreenButton
                end if
            end if
        end tell

    end tell
end if
return 3
结束空闲

辞职 继续退出
结束退出

将空闲块中的所有代码放入一个try-and-Error块中。如果抛出错误,将捕获它

try 
    -- your code 
on error err 
    log err
end try 
在“告诉进程面对面时间”之后,添加一行测试(窗口计数)>0,然后执行您的操作。否则,它意味着没有打开任何窗口,那么脚本将什么也不做,但不会出错。