Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have this simple AppleScript which takes the text in the clipboard and outputs the amount of words and characters used.

What I'm trying to do is passing "display dialog" to Growl or growlnotify. I know how to use growlnotify in the shell - it's great and highly customizable (stick note, assign app icon or an image, etc) - but the point is: I don't know how to do it in AppleScript. I google a bit but now time has passed and I decided to post my question here.

So, here's the script:

set myCount to count (the clipboard)
set myWords to count words of (the clipboard)
set myParas to count paragraphs of (the clipboard)

display dialog "Characters: " & myCount & "
Words: " & myWords & "
Paragraphs: " & myParas


share|improve this question
up vote 1 down vote accepted

There's documentation for it, I provide an example in this answer.

The following works with Growl 1.3.3 on OS X Lion:

tell application "Growl"
    set the allNotificationsList to {"Word Count"}
    set the enabledNotificationsList to {"Word Count"}

    register as application "Word Counter" all notifications allNotificationsList default notifications enabledNotificationsList icon of application "Script Editor"

    set myCount to count (the clipboard)
    set myWords to count words of (the clipboard)
    set myParas to count paragraphs of (the clipboard)
    --       Send a Notification...
    notify with name "Word Count" title "Word Counter" description (myCount as text) & " " & (myWords as text) & " " & (myParas as text) application name "Word Counter"
end tell

Screenshot of notification

Screenshot of application preferences

share|improve this answer
I can't figure out how to pass my display dialog out to your script, so I tried to do it with the example script from the documentations page… but I can't get it to work either. See: – pattulus May 30 '12 at 19:59
@pattulus That's because you don't understand what the script does. First it registers an application — every time the script is called, it doesn't hurt — that will appear in Growl's preferences as a separate configurable item, and then it sends a notification, pretending to originate from that application. Editing my answer with an applicable example... – Daniel Beck May 30 '12 at 20:23
That's correct. I'm not really an AppleScripter, I really have troubles with figuring out the syntax. Thanks all the more for visually breaking it down for me and providing a solution. – pattulus May 30 '12 at 21:49
@pattulus You're welcome. Was about time I bought Growl 1.3 anyway... You can probably also do this as a shell script when you create a service for it, get the clipboard on the command line using pbpaste. – Daniel Beck May 31 '12 at 4:44
set input to the clipboard as text
set output to (number of characters of input & " characters
" & number of words of input & " words
" & number of paragraphs of input & " paragraphs") as text
do shell script "/usr/local/bin/growlnotify " & quoted form of output
-- brew install growlnotify
share|improve this answer
Wow. Thanks a ton - I wouldn't have imagined that it is so easy to append the quoted text. This is great and far easier to grasp and implement for me since I'm more familiar with the shell commands of growlnotify. I give a you three symbolic green check marks for this Lri. – pattulus May 31 '12 at 14:04

You must log in to answer this question.

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