【发布时间】:2018-01-10 23:12:27
【问题描述】:
您好,感谢您抽出宝贵时间提供帮助。
我在 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
【问题讨论】: