gpt4 book ai didi

macos - 使用 Automator 重新启动 Apple AirPort Extreme

转载 作者:行者123 更新时间:2023-12-05 07:45:19 24 4
gpt4 key购买 nike

我正在尝试从 Automator 运行一个 applescript 来重启我的 AirPort Extreme。 Automator 脚本是一种日历警报类型。当我直接从 Automator 运行脚本时,它工作得很好。当日历触发 Automator 时,我得到以下信息:

The action ”Run AppleScript“ encountered an error

我已确保脚本本身、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

最佳答案

我在您的脚本中添加了一个 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?同样,在脚本编辑器中,将该代码导出为应用程序,在系统首选项中授予辅助访问权限。然后,您可以直接从日历应用程序在日历事件上运行该文件。

enter image description here

更新

如果您想避免使用 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

enter image description here

enter image description here

关于macos - 使用 Automator 重新启动 Apple AirPort Extreme,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41775955/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com