以下是一个示例代码,演示如何使用AppleScript来点击特定的菜单栏项目:
-- 打开菜单栏项目
tell application "System Events" to tell process "SystemUIServer"
-- 替换“Apple”为你想要点击的菜单栏项目的名称
set theMenuItem to menu bar item "Apple" of menu bar 1
click theMenuItem
end tell
-- 点击菜单栏项目中的子菜单项目
tell application "System Events" to tell process "SystemUIServer"
-- 替换“About This Mac”为你想要点击的子菜单项目的名称
set theMenuItem to menu item "About This Mac" of menu 1 of menu bar item "Apple" of menu bar 1
click theMenuItem
end tell
在上面的示例中,首先使用tell application "System Events" to tell process "SystemUIServer"
来告诉系统事件来自于SystemUIServer进程。然后,使用menu bar item
来定位到要点击的菜单栏项目,并使用click
命令来模拟点击。如果要点击菜单栏项目中的子菜单项目,可以使用menu item
命令来定位到子菜单项目。