您好,感谢您抽出宝贵时间提供帮助。
我在AppleScript中的编码经验有限。我想要做的是创建一个将打开,设置为全屏,然后安排我经常使用的几个应用程序的脚本。我在脚本中添加了一些逻辑,以便在应用程序已经打开时帮助流程。但我遇到的问题是在For Next循环期间,当我试图将应用程序设置为全屏时,应用程序日历未激活,然后我得到“系统事件出错:无法获取窗口流程“日历”中的1个。索引无效。“错误。这是因为日历窗口尚未编制索引,但如果我在“激活”后延迟大约1-2秒,则脚本通常会运行。但是肯定有一种方法可以命令脚本在尝试运行Fullscreen线之前索引Calendars的窗口吗?我想删除延迟代码行,以便脚本可以更快地运行。任何人都可以提供一些想法或解决方案吗?
set app1 to "Maps"
set app2 to "Safari"
set app3 to "Mail"
set app4 to "Calendar"
set app5 to "Contacts"
set thelist to {app1, app2, app3, app4, app5}
repeat with i in thelist
if application i is running then
tell application i
activate
delay 0.5
end tell
tell application "System Events" to tell process i
set value of attribute "AXFullScreen" of window 1 to true
end tell
else
end if
end repeat
答案 0 :(得分:0)
应用程序完成启动后,Windows即可使用。你得等一等。但你可以把它限制在必要的时间:
而不是等待固定的延迟,请执行以下操作
repeat
try
tell application "System Events" to tell process i
set value of attribute "AXFullScreen" of window 1 to true
exit repeat
end tell
end try
delay 0.01
end repeat
这种方法一直试用直到它起作用然后退出。