【问题标题】:Restarting Apple AirPort Extreme with Automator使用 Automator 重新启动 Apple AirPort Extreme
【发布时间】:2017-06-06 04:02:58
【问题描述】:

我正在尝试从 Automator 运行一个 AppleScript,以重新启动我的 AirPort Extreme。 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

【问题讨论】:

  • 您是否添加了日历应用程序和机场实用程序以在可访问性首选项中也允许访问?也可能在 AppleScript 中的所有击键之间添加延迟?
  • 谢谢。我添加了机场实用程序。将添加日历应用程序。另外,我尝试在击键之间添加一些延迟。我会回来报告的。

标签: macos applescript automator


【解决方案1】:

我在您的脚本中添加了一条 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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-12-27
    • 1970-01-01
    • 1970-01-01
    • 2023-03-31
    • 1970-01-01
    • 2010-11-01
    • 2019-12-24
    • 1970-01-01
    相关资源
    最近更新 更多