在 Apple Script 中,可通过以下示例代码向菜单栏中添加返回功能:
on addBackMenu()
tell application "System Events"
tell process "SystemUIServer"
-- find the first menu bar and get the menu items
set menuBar to menu bar 1
set menuItems to menu bar items of menuBar
-- go through each menu item in reverse order and add a "Back" menu item
repeat with i from (count of menuItems) to 1 by -1
set menuItem to item i of menuItems
set menuTitle to name of menuItem
if menuTitle is not equal to "" then
set newMenuItem to make new menu item at beginning of menu items of menuItem with properties {title:"Back", enabled:true, action:"myBackFunction"}
set name of newMenuItem to "Back"
return
end if
end repeat
end tell
end tell
end addBackMenu
on myBackFunction()
-- Handle the "Back" menu item clicked event here
end myBackFunction
该代码将在菜单栏中的每个具有标题的菜单项后添加一个 "Back" 选项。您可以在 myBackFunction()
中处理返回操作的代码。
注意:这段代码必须在脚本运行时才能够在菜单栏中显示。您可以在 Apple Script 编辑器中运行此代码。