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 '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

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.

You must log in to answer this question.

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