【问题标题】:AppleScript to click Wi-Fi icon with option downAppleScript 单击带有选项的 Wi-Fi 图标
【发布时间】:2017-10-25 19:25:29
【问题描述】:

我想在按下选项键的情况下单击 Wi-Fi 图标,以显示 Mac 上可用的额外选项。如何使用 AppleScript 自动化它?

我尝试使用key down optionclick menu item,但在揭示特殊选项时没有运气。

有什么方法可以实现吗?

【问题讨论】:

    标签: macos applescript osascript


    【解决方案1】:

    目前无法使用 AppleScript 按住键进行单击。按键操作仅适用于其他按键操作,因为 AppleScript 点击操作实际上并不执行“点击”,而是直接操作元素。

    【讨论】:

    • 那么我没有办法自动化这个吗?
    【解决方案2】:

    如果您不介意使用第 3 方实用程序,这里有一个使用 cliclick 的示例 AppleScript 脚本

    tell application "System Events"
        tell application process "SystemUIServer"
            set theWiFiProperties to item 1 of (get properties of every menu bar item of menu bar 1 whose description starts with "Wi-Fi")
        end tell
        set theXpos to (item 1 of position in theWiFiProperties) + ((item 1 of size in theWiFiProperties) / 2) as integer
        set theYpos to (item 2 of position in theWiFiProperties) + ((item 2 of size in theWiFiProperties) / 2) as integer
    end tell
    tell current application
        do shell script "/path/to/cliclick kd:alt c:" & theXpos & "," & theYpos & " ku:alt"
    end tell
    
    • 注意:/path/to/cliclick 更改为cliclick 可执行文件的实际pathname

    它是如何工作的:

    theWiFiProperties 变量 被设置为Wi-Fiproperties menu extra 然后是变量 theXpostheYpos 被设置为 position 一起是 菜单栏上Wi-Fi menu extracenter /em>。

    这个info然后用在do shell scriptcommand中使用cliclick按下option键,点击指定的x,y 坐标并让 option 键向上。

    【讨论】:

      【解决方案3】:

      您可以使用 Automator 并使用“Watch me do”记录该过程,然后将自动化工作流程保存为应用程序或听写命令。

      在 Automator 中,我将 watch me do action 保存为应用程序。我将这个新应用程序命名为“Extended_Wifi.app”。然后我必须在系统偏好设置中添加这个应用程序才能控制我的电脑。

      就个人而言,我更喜欢使用 Scripteditor 而不是 Automator,因为我很大一部分人觉得使用 Automator 是在作弊。但在一天结束时,我能够将 Automator 动作保存为应用程序,并且它运行良好,但是在 Scripteditor 中,我无法让 AppleScript 版本的动作正常运行。

      这是一个快速 .gif,显示 Automator 应用程序正常工作。

      【讨论】:

      • 我试过这个。当我执行 automator 生成的代码时,它只需单击,但不会显示其他选项。
      • 在 Automator 中,当我使用 watch me do 开始录制时,我按住选项键并在单击菜单栏中的 Wi-Fi 图标时按住它
      • 我也是这样做的。之后,我试图将事件复制到脚本编辑器中,以便它为此生成 applescript。执行该applescript时,它不会显示额外的选项。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多