## Open an applescript display dialog via command line bash script

I wrote an rsync based backup script for my parents’ Mac. I set it up as a cron job that backs up their hard drive to an external once a week. The only problem is that if they don’t have the external plugged in then the script has no way of letting them know that no back up took place. Since the whole point of the script was to make backing up something that just happens in the background without necessary thought I can’t expect them to read a log file etc. Instead I came up with a way for my bash script to talk to them through the GUI. So here’s my little bash script that takes a single argument which gets turned into a display box using applescript.


#!/bin/bash
# ./display-dialog.sh "Hello, world."
# Opens dialog using applescript saying "Hello, world."
#

temp_app="/tmp/$(basename$0)..app"
osacompile -e "display dialog \"$1\"" -x -o$temp_app
open \$temp_app


Know in my script or from the command line, I can issue:


./display-dialog.sh "Hey, the back up external drive is not plugged in!"


and my parents will see: