要在菜单栏中打开“首选项”(Preferences),您可以使用以下AppleScript代码:
tell application "System Events"
tell process "System Preferences"
click menu item "Preferences" of menu "System Preferences" of menu bar 1
end tell
end tell
这段代码使用System Events应用程序来模拟用户单击菜单栏中的“首选项”菜单项。请确保在运行此脚本之前已打开“系统偏好设置”应用程序。
如果您运行此脚本后仍然无法打开“首选项”,可能是因为您的操作系统版本不同,菜单项的名称也可能不同。您可以通过使用下面的代码来列出所有可用的菜单项:
tell application "System Events"
tell process "System Preferences"
get name of every menu item of menu "System Preferences" of menu bar 1
end tell
end tell
运行此脚本后,您将获得打印出的所有菜单项的名称。根据您的操作系统版本和语言设置,可能需要相应地修改代码中的菜单项名称。
希望这个解决方法能够帮助您打开“首选项”菜单项。