我试图从Automator运行一个重启我的AirPort Extreme的AppleScript。 Automator脚本是日历警报类型。当我直接从Automator运行脚本时,它工作得很好。当日历触发Automator时,我得到以下内容:
“运行AppleScript”操作遇到错误
我确保脚本本身,Automator等都可以访问安全和隐私 - >可访问性。我尝试从AppleScript中删除任何delay
。我不知所措。我很感激任何有助于解决问题的想法。谢谢!
这是我试图与Automator一起使用的AppleScript:
activate application "AirPort Utility"
delay 4
tell application "System Events"
click image 2 of group 1 of scroll area 1 of window 1 of application process "AirPort Utility"
delay 3
click menu item 3 of menu "Base Station" of menu bar 1 of application process "AirPort Utility"
delay 1
keystroke tab
keystroke tab
keystroke space
end tell
delay 300
tell application "AirPort Utility" to quit
答案 0 :(得分:0)
我在你的脚本中添加了一个try语句,并直接从脚本编辑器运行它,没有任何问题。
activate application "AirPort Utility"
delay 4
tell application "System Events"
try
click image 2 of group 1 of scroll area 1 of window 1 of application process "AirPort Utility"
delay 3
click menu item 3 of menu "Base Station" of menu bar 1 of application process "AirPort Utility"
delay 1
keystroke tab
keystroke tab
keystroke space
end try
end tell
delay 300
tell application "AirPort Utility" to quit
您还可以尝试将脚本编辑器中的脚本保存为应用程序,授予对新应用程序的辅助功能访问权限,然后让Automator在日历事件上运行该新应用程序。
更好的是,为什么不完全绕过Automator?同样,在脚本编辑器中,将该代码导出为应用程序,在系统首选项中授予可访问性访问权限。然后,您可以直接从日历应用程序在日历活动上运行该文件。
<强>更新强>
如果您想避免使用Calendar.app,这里有一个您可能感兴趣的有趣解决方案。以下代码保存为脚本编辑器中的应用程序,允许您插入所需的时间来启动您选择的任何应用程序。 ..
Run_Script_At_Specific_Time()
on Run_Script_At_Specific_Time()
set theTime to time string of (current date)
activate
set requested_time to display dialog ¬
"Please Enter Your Start Time With The Following Format: Hour:Minutes:Seconds" default answer theTime ¬
buttons {"CANCEL", "OK"} ¬
default button ¬
"OK" cancel button ¬
"CANCEL" with title ¬
"Choose App Launch Time" giving up after 30
set requested_time to text returned of requested_time
activate
set chosenApp to choose file with prompt ¬
"Choose The App Or File You Would Like To Run At Your Specified Time" default location (path to applications folder) ¬
invisibles false ¬
multiple selections allowed false ¬
without showing package contents
repeat until theTime is greater than or equal to requested_time -- Added The "Greater Than" Just As A Failsafe
delay 30
set theTime to time string of (current date)
end repeat
tell application "Finder"
open chosenApp
end tell
end Run_Script_At_Specific_Time