在 Applescript 中,如果您正在创建应用程序,可以向左侧菜单栏添加一个项目吗?

发布于 2024-11-02 09:03:01 字数 93 浏览 2 评论 0原文

你好,我是 Tate,我有一个问题。在 applescript 中,你能为 mac 上的左侧菜单(应用程序菜单)创建一个默认情况下不存在的项目吗?如果你知道答案,请告诉我。

Hello I’m Tate and I have a Question.In applescript, can you create an item for the left menu (application menu) on mac that is not already there by default? if you know the answer, please tell me.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

远山浅 2024-11-09 09:03:01

我不知道如何将菜单项添加到应用程序菜单栏,但您可以查看 FastScripts ,它提供了使用您喜欢的任何脚本顺序和键盘快捷键来自定义脚本菜单的能力。它可以免费使用任意数量的脚本和最多 10 个键盘快捷键。

另外,虽然我从未使用过它,但 ThisService 显然允许您使用 AppleScript 将项目添加到“服务”菜单在应用程序菜单中。您也可以检查一下。

I don't know of a way to add menu items to the application menu bar, but you might check into FastScripts, which offers the ability to customize a script menu with whatever order of scripts you like and with keyboard shortcuts. It's free for any number of scripts and up to 10 keyboard shortcuts.

Also, although I've never used it, ThisService apparently allows you to use AppleScript to add items to the Services menu in the application menu. You might check it out also.

海拔太高太耀眼 2024-11-09 09:03:01

Automator 可以保存 Applescript,以便它们显示在每个应用程序菜单的“服务”菜单中。只需运行 Automator,创建 Applescript 工作流程并将其另存为服务。您也可以为其分配命令键。

Automator can save Applescripts so that they show up in the Services menu in each Application menu. Just run Automator, create and Applescript workflow and save it as a service. You can assign a command key to it as well.

将军与妓 2024-11-09 09:03:01

这并不简单,但却是可能的。以下脚本应作为保持打开应用程序保存并执行。

-- script: Creating Menus example for AsObjC applications
-- written: by KniazidisR, 19 Sep 2022 17:10:25

-- IMPORTANT: save and run this script as Stay-Open application
-- If you will execute the script as is from Script Editor of Script Debugger,
-- it will erase its menu items. Only after restarting the script editor
-- the menu items will restore. smile 

use AppleScript version "2.4"
use scripting additions
use framework "Foundation"
use framework "AppKit"


-- init new menu bar to build menus from scratch
set menubar to current application's NSMenu's alloc()'s init()

-- clear predefined menus
set menuBarItem to current application's NSMenuItem's new()
menubar's addItem:menuBarItem
current application's NSApp's setMainMenu:menubar
current application's NSApp's mainMenu()'s removeAllItems()

-- make and edit App name's menu 
set asstMenuItem to menubar's addItemWithTitle:"" action:(missing value) keyEquivalent:""
set asstMenu to current application's NSMenu's alloc()'s init()
menubar's setSubmenu:asstMenu forItem:asstMenuItem
set preferencesMenuItem to asstMenu's addItemWithTitle:"Preferences" action:"actionHandler:" keyEquivalent:""
(preferencesMenuItem's setTarget:me)
set quitMenuItem to asstMenu's addItemWithTitle:"Quit" action:"actionHandler:" keyEquivalent:"q"
(quitMenuItem's setTarget:me)

-- make and edit "File" menu 
set asstMenuItem to menubar's addItemWithTitle:"" action:(missing value) keyEquivalent:""
set asstMenu to current application's NSMenu's alloc()'s initWithTitle:"File"
menubar's setSubmenu:asstMenu forItem:asstMenuItem
set openMenuItem to asstMenu's addItemWithTitle:"Open" action:"actionHandler:" keyEquivalent:"o"
(openMenuItem's setTarget:me)
set saveMenuItem to asstMenu's addItemWithTitle:"Save" action:"actionHandler:" keyEquivalent:"s"
(saveMenuItem's setTarget:me)
set saveAsMenuItem to asstMenu's addItemWithTitle:"Save As..." action:"actionHandler:" keyEquivalent:"a"
(saveAsMenuItem's setTarget:me)
set printMenuItem to asstMenu's addItemWithTitle:"Print..." action:"actionHandler:" keyEquivalent:"p"
(printMenuItem's setTarget:me)

-- make and edit "Edit" menu
set asstMenuItem to menubar's addItemWithTitle:"" action:(missing value) keyEquivalent:""
set asstMenu to current application's NSMenu's alloc()'s initWithTitle:"Edit"
menubar's setSubmenu:asstMenu forItem:asstMenuItem
set openMenuItem to asstMenu's addItemWithTitle:"Copy" action:"actionHandler:" keyEquivalent:"c"
(openMenuItem's setTarget:me)
set saveMenuItem to asstMenu's addItemWithTitle:"Paste" action:"actionHandler:" keyEquivalent:"v"
(saveMenuItem's setTarget:me)
set saveAsMenuItem to asstMenu's addItemWithTitle:"Undo" action:"actionHandler:" keyEquivalent:"u"
(saveAsMenuItem's setTarget:me)
set printMenuItem to asstMenu's addItemWithTitle:"Redo" action:"actionHandler:" keyEquivalent:"r"
(printMenuItem's setTarget:me)


on actionHandler:sender
    set theTitle to title of sender as string
    if theTitle is "Quit" then quit
    display dialog "The \"" & theTitle & "\" menu item pressed"
end actionHandler:

It isn't simple, but is possible. Following script should be saved and executed as stay-open application.

-- script: Creating Menus example for AsObjC applications
-- written: by KniazidisR, 19 Sep 2022 17:10:25

-- IMPORTANT: save and run this script as Stay-Open application
-- If you will execute the script as is from Script Editor of Script Debugger,
-- it will erase its menu items. Only after restarting the script editor
-- the menu items will restore. smile 

use AppleScript version "2.4"
use scripting additions
use framework "Foundation"
use framework "AppKit"


-- init new menu bar to build menus from scratch
set menubar to current application's NSMenu's alloc()'s init()

-- clear predefined menus
set menuBarItem to current application's NSMenuItem's new()
menubar's addItem:menuBarItem
current application's NSApp's setMainMenu:menubar
current application's NSApp's mainMenu()'s removeAllItems()

-- make and edit App name's menu 
set asstMenuItem to menubar's addItemWithTitle:"" action:(missing value) keyEquivalent:""
set asstMenu to current application's NSMenu's alloc()'s init()
menubar's setSubmenu:asstMenu forItem:asstMenuItem
set preferencesMenuItem to asstMenu's addItemWithTitle:"Preferences" action:"actionHandler:" keyEquivalent:""
(preferencesMenuItem's setTarget:me)
set quitMenuItem to asstMenu's addItemWithTitle:"Quit" action:"actionHandler:" keyEquivalent:"q"
(quitMenuItem's setTarget:me)

-- make and edit "File" menu 
set asstMenuItem to menubar's addItemWithTitle:"" action:(missing value) keyEquivalent:""
set asstMenu to current application's NSMenu's alloc()'s initWithTitle:"File"
menubar's setSubmenu:asstMenu forItem:asstMenuItem
set openMenuItem to asstMenu's addItemWithTitle:"Open" action:"actionHandler:" keyEquivalent:"o"
(openMenuItem's setTarget:me)
set saveMenuItem to asstMenu's addItemWithTitle:"Save" action:"actionHandler:" keyEquivalent:"s"
(saveMenuItem's setTarget:me)
set saveAsMenuItem to asstMenu's addItemWithTitle:"Save As..." action:"actionHandler:" keyEquivalent:"a"
(saveAsMenuItem's setTarget:me)
set printMenuItem to asstMenu's addItemWithTitle:"Print..." action:"actionHandler:" keyEquivalent:"p"
(printMenuItem's setTarget:me)

-- make and edit "Edit" menu
set asstMenuItem to menubar's addItemWithTitle:"" action:(missing value) keyEquivalent:""
set asstMenu to current application's NSMenu's alloc()'s initWithTitle:"Edit"
menubar's setSubmenu:asstMenu forItem:asstMenuItem
set openMenuItem to asstMenu's addItemWithTitle:"Copy" action:"actionHandler:" keyEquivalent:"c"
(openMenuItem's setTarget:me)
set saveMenuItem to asstMenu's addItemWithTitle:"Paste" action:"actionHandler:" keyEquivalent:"v"
(saveMenuItem's setTarget:me)
set saveAsMenuItem to asstMenu's addItemWithTitle:"Undo" action:"actionHandler:" keyEquivalent:"u"
(saveAsMenuItem's setTarget:me)
set printMenuItem to asstMenu's addItemWithTitle:"Redo" action:"actionHandler:" keyEquivalent:"r"
(printMenuItem's setTarget:me)


on actionHandler:sender
    set theTitle to title of sender as string
    if theTitle is "Quit" then quit
    display dialog "The \"" & theTitle & "\" menu item pressed"
end actionHandler:
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文