I wonder if AppleScript can print a variable in the top menu bar in OSX 10.11 ?
Asked
Active
Viewed 1,288 times
2
-
Can you provide some details? – Allan Jun 29 '16 at 14:30
-
Maybe, but not that I know of. Access so far as I know is one way: using GUI scripting to interact with elements in the menu bar that already exist. I don't know about "writing" to the menu bar. There might be some hackey workarounds, but I'm not sure. – JMY1000 Jun 29 '16 at 15:00
-
Yes thank you, I guess I need to code a swift menu bar app, and then add my applescript in it – Kevin Jun 29 '16 at 18:21
-
@KevinCork I know with Xcode it's possible to display something up there, but I have no idea how to do that. – Bradman175 Jun 29 '16 at 19:26
1 Answers
1
There is a simple way, using AppleScriptObjC as described here:
use framework "Foundation"
use framework "AppKit"
use scripting additions
property StatusItem : missing value
property newMenu : class "NSMenu"
-- myVariable derived from whatever code >>
set myVariable to ">> " & "Output of script: value of variable." & " <<"
set bar to current application's NSStatusBar's systemStatusBar
set StatusItem to bar's statusItemWithLength:-1.0
StatusItem's setTitle: myVariable
set newMenu to current application's NSMenu's alloc()'s initWithTitle:"Custom"
StatusItem's setMenu:newMenu
delay 5
current application's NSStatusBar's systemStatusBar()'s ¬
removeStatusItem:StatusItem
On the original page I posted code that gets a display-dialog's return & puts it onto the menu bar.

clemsam lang
- 1,132
-
Returned:
error "NSWindow drag regions should only be invalidated on the Main Thread!" number -10000
. – Artfaith Oct 13 '22 at 14:11 -
Hi, sadly my elderly MacBook Air ist still running High Sierra 10.13.6. I do not get any errors and the menu bar's output is: " >> Output of script: value of variable. << ". – clemsam lang Oct 14 '22 at 06:53