I wonder if AppleScript can print a variable in the top menu bar in OSX 10.11 ?

  • Can you provide some details?
    – Allan
    Jun 29, 2016 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, 2016 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, 2016 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, 2016 at 19:26

1 Answer 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 ¬

On the original page I posted code that gets a display-dialog's return & puts it onto the menu bar.

  • Returned: error "NSWindow drag regions should only be invalidated on the Main Thread!" number -10000.
    – Artfaith
    Oct 13, 2022 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. << ". Oct 14, 2022 at 6:53

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .