Is there a way to have AppleScript output displayed in the menubar?

Solution 1:

As a generality, without a third party program, such as Growl, there is no built in way to do this.

However, you could write a script or other program such as one I found here that provides the menulet service for you. I'm sure that Growl integration would be much easier to accomplish.

Solution 2:

There isn't a built in way to do this in OS X. However, using Growl, you can have notifications. Here's a sample script for that:

--Make sure Growl is running
tell application "System Events"
    set isRunning to (count of (every process whose bundle identifier is "com.Growl.GrowlHelperApp")) > 0
end tell

if isRunning then
    tell application id "com.Growl.GrowlHelperApp"
        set the allNotificationsList to ¬
            {"Test Notification", "Another Test Notification"}
        --Notifications can be enabled in System Preferences>Growl>Applications>Display Options
        set the enabledNotificationsList to ¬
            {"Test Notification"}
        register as application ¬
            "Growl AppleScript Sample" all notifications allNotificationsList ¬
            default notifications enabledNotificationsList ¬
                    -- Set the icon. You can use any icon from any application
            icon of application "AppleScript Editor"

        notify with name ¬
            "Test Notification" title ¬
            "Test Notification" description ¬
            "This is a test AppleScript notification." application name "Growl AppleScript Sample"

        notify with name ¬
            "Another Test Notification" title ¬
            "Another Test Notification :) " description ¬
            "Alas — you won't see me until you enable me..." application name "Growl AppleScript Sample"

    end tell
end if

That should display this:

And if you have the other notification enabled too:

More advanced techniques are described here.

Solution 3:

Since AppleScriptObjC is part of macOS it is possible to use its "Foundation" framework (incl. NSMenu's methods) to achieve what was probably not possible in 2012.

I found an interesting script to create custom menus from within AppleScript; from this I extracted suitable code to place text in macOS's menu bar. In fact it uses just a menu's "title" for inserting some content.

In order to demonstrate this I implemented a very basic dialog script that asks users for text input (waiting 6 sec.) which is then displayed in the menu bar temporarily (5 sec.).
Here it is:

use framework "Foundation"
use framework "AppKit"
use scripting additions
property StatusItem : missing value
property newMenu : class "NSMenu"

display dialog "Write something:" default answer "" giving up after 6
set myText to text returned of the result
if myText is "" then set myText to "TOOOOO slow … try again !"
set myText to ">>    " & myText & "    <<"

set bar to current application's NSStatusBar's systemStatusBar
set StatusItem to bar's statusItemWithLength:-1.0
StatusItem's setTitle:myText
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  

This AppleScript code can be used in any script of yours. (Its "dialog" part is optional…)

user3439894 helped with closing my "menu", see last line of the script. Thanks a lot!