Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

Background

I'd like to be able to display a notification window in OS X from within a script. The script will be running in background, so the notification should not go to the terminal but instead be displayed in a dialog window.

What I found so far

xmessage

On Linux I'd probably use xmessage or one of its variants for this. But on OS X, starting the bulky X server just for this task seems both overkill and too slow for my taste.

Finder dialog

I've found a similar question in this forum thread, where the “accepted” reply suggested this command:

osascript -e 'tell app "Finder" to display dialog "Hey!"'

But on my OS X , the resulting dialog isn't displayed immediately. Instead, the Finder icon starts to bounce, and the dialog becomes visible only after I click on the icon. Too many mouse clicks, too disruptive.

Notifier

There is an answer on Super User which suggests a tool called terminal-notifier. Unfortunately that appears to only work for OS X , so it won't help in my case.

Question

So is there some tool, either included in OS X or freely available, which allows displaying a small dialog to the user without too much overhead?

share|improve this question

2 Answers 2

up vote 1 down vote accepted

One option is to tell a background process like SystemUIServer to display the dialog:

osascript -e 'tell application "SystemUIServer"
display dialog "message"
end
activate application (path to frontmost application as text)'

You can also tell the frontmost application to display a dialog, but it's not shown immediately if the application is not responding. If MPlayer OS X is frontmost, text dialogs don't accept any keyboard input.

osascript -e 'tell application (path to frontmost application as text)
display dialog "message"
end'
share|improve this answer
    
The first approach has the drawback that it will raise all windows of the given application, which I find slightly annoying. But the second approach is the best I've seen so far. Apps not responding should be rare enough that I won't worry about these. –  MvG Nov 30 '12 at 12:18

Try

tell application "System Events" to display dialog "Plug the Digispark into the USB port." buttons {"OK"} with icon caution

Tested on OS X 10.8.2

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.