AppleScriptで作るステータスメニューは、プログラムで動的に作るケースが圧倒的に多いところですが、Xcode上でCocoa Applicationを作成する場合にはXIBで(=XcodeのInterface Builder上で)作ったほうが簡単だし使い勝手がいいので、作成方法を確認しておきました。
▲Interface Builder上でメニューをCocoa binding(Xcode 16.3)
AppleScript名:AppDelegate.applescript |
— — AppDelegate.applescript — statusMenuFromXIB — — Created by Takaaki Naganoya2 on 2025/03/27. — — script AppDelegate property parent : class "NSObject" — IBOutlets property theWindow : missing value property theStatMenu : missing value –xib上で作っておいたメニュー。Cocoa Binding on applicationWillFinishLaunching:aNotification set theIcon to current application’s NSImage’s imageNamed:(current application’s NSImageNameComputer) set statusItem to (current application’s NSStatusBar’s systemStatusBar())’s statusItemWithLength:(current application’s NSVariableStatusItemLength) statusItem’s setTitle:("PIYOMARU") statusItem’s setImage:theIcon statusItem’s setHighlightMode:true statusItem’s setMenu:theStatMenu statusItem’s popUpStatusItemMenu:theStatMenu end applicationWillFinishLaunching: on applicationShouldTerminate:sender — Insert code here to do any housekeeping before your application quits return current application’s NSTerminateNow end applicationShouldTerminate: end script |