How do I get growlnotify to show a multiple-line message from the command line?

1.2k views Asked by At

Using growlnotify how can I display multiple lines of text from the command line?

Slash-n - \n - like this doesn't seem to work:

growlnotify -t title -m "messageline1\nmessage2"

I just get a message messageline1\nmessage2

2

There are 2 answers

0
martin clayton On BEST ANSWER

The intended escaped newline is not interpreted as such by growl - it's just treated as a literal slash, followed by an 'en'.

You can get the shell to insert a newline in the string this way:

growlnotify -t title -m "messageline1"$'\n'"message2"

See (e.g.) Unix command sh:

Words of the form $'string' are treated specially. The word expands to string, with backslash-escaped characters replaced as specifed by the ANSI C standard.

0
mivk On

I find it easier and much more readable in scripts to use a little function and echo's -e option:

mynotify () {
    for m in "$@"; do
        local msg="$msg\n$m"
    done
    echo -e "$msg" | growlnotify -t "My Title"
}

mynotify "This is line 1" "Line 2" "The 3d line ends with an extra newline\n" "Line 4"