Hacker News new | ask | show | jobs
by maerF0x0 2023 days ago
I use the following in Bash.

    function notifyme() {
       MSG=${1:-'Terminal is done'}
       TITLE=${2:-"Done!"}
       osascript -e "display notification \"${MSG}\" with title \"${TITLE}\""
    }
I use it like:

bin/start-unit-tests; notifyme

5 comments

I wrote https://notica.us to do something similar. It needs a web browser open, but works over SSH and to your phone.
I do something similar, but it is networked so when a compile is done on my dev machine, my main desktop shows a notification using terminal-notifier.

It's very old and very hacky. There are probably apps that do this so much better.

  /Applications/terminal-notifier.app/Contents/MacOS/terminal-notifier -group not -title "$t" -subtitle "$st" -message "$m" -execute "$HOME/bin/gospace 1"
gospace ends up doing:

  osascript -e 'tell application "System Events" to key code 18 using option down'
which presses option-1 which switches to space 1
This is really nice!

Here is an attempt at fish port:

   function notifyme
     set MSG $argv[1] "Terminal is done"
     set TITLE $argv[2] "Done!"
     osascript -e "display notification \"$MSG[1]\" with title \"$TITLE[1]\""
   end

disclaimer: this is first fish function I ever write so might not be the best way to do default values; I'm using hack from https://unix.stackexchange.com/a/88682
Too late to edit, but was rereading this and i forgot that I made optional args too. For example i sometimes leave my self next instructions

   notifyme "Now you can commit and push code"
   notifyme "Now you can commit and push code" "Tests complete"
This is so simple and so cool!