Applescript 打开后点击系统菜单栏中的项目

问题描述 投票:0回答:2

我可以使用此代码打开蓝牙下拉菜单项,但我不知道如何实际单击菜单中的任何项目。

tell application "System Events" to tell process "ControlCenter"
    click menu bar item "Bluetooth" of menu bar 1
end tell

单击打开的蓝牙菜单中的某个内容的命令是什么?

applescript
2个回答
1
投票

以下 AppleScript 代码应该可以完成您想要实现的目标。只需将代码中的 “Mac Pro” 部分替换为您要单击的项目的名称即可。

tell application "System Events" to tell process "ControlCenter"
    click menu bar item "Bluetooth" of menu bar 1
    repeat until exists of checkbox 1 of scroll area 1 of window 1
        delay 0.1
    end repeat
    click checkbox "Mac Pro" of scroll area 1 of window 1
    key code 53 -- Press escape key
end tell

以下 AppleScript 代码将返回复选框的名称,以便您可以轻松了解在第一个代码中使用的选项。

tell application "System Events" to tell process "ControlCenter"
    click menu bar item "Bluetooth" of menu bar 1
    repeat until exists of checkbox 1 of scroll area 1 of window 1
        delay 0.1
    end repeat
    set checkBoxNames to name of checkboxes of scroll area 1 of window 1
end tell

0
投票

如何向此脚本添加命令以在菜单栏中打开已激活应用程序的窗口。

现在应用程序在栏菜单中启动,但窗口未打开。这可以吗?

tell application "System Events"
get name of every process whose name is "Scrap Paper"
if result is not {} then
    tell application "Scrap Paper"
        quit
    end tell
else
    tell application "Scrap Paper"
        activate
    end tell
end if

结束告诉

© www.soinside.com 2019 - 2024. All rights reserved.