Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

cellularmitosis

macrumors regular
Original poster
Mar 6, 2010
185
267
I'm recently tinkering with MacPorts and Gentoo, both of which involve very long-running builds.

This is my setup for receiving a push notification on my phone when a long job finishes.

Pushover​


I use the Pushover iPhone app: https://pushover.net/

You can use it for free for 30 days, after which you have to make a one-time $5 in-app purchase.

To send a push, you need a user key and an application token.

You are assigned a user key when you register at https://pushover.net/, and you get an application token when you register an "application" at https://pushover.net/.

Surprisingly, their API doesn't force you to use HTTPS, which means it even works from a stock Tiger or Leopard install.

The bash script:​


Here is a notify.sh script which uses curl:

Code:
#!/bin/bash

# notify.sh: send a push notification from the command-line.
# ./notify.sh "a message"

set -e

# if you need an SSL-capable curl on OS X Tiger or Leopard (PowerPC),
# unpack this tarball into /opt:
# http://leopard.sh/binpkgs/tigersh-deps-0.1.tiger.g3.tar.gz
export PATH="/opt/tigersh-deps-0.1/bin:$PATH"

APP_TOKEN="XXX"
USER_KEY="YYY"

url=https://api.pushover.net/1/messages.json

curl -fsS -X POST \
    -H "Content-Type: application/json" \
    -d "{ \"token\": \"$APP_TOKEN\", \"user\": \"$USER_KEY\", \"message\": \"$1\" }" \
    $url \
    > /dev/null

Installing curl with SSL:​


The above script uses an HTTPS URL, and assumes you have a modern version of curl installed.

If you need a modern curl on PowerPC Tiger or Leopard, you can install one like this:

Code:
sudo -i
mkdir -p /opt
cd /opt
curl http://leopard.sh/binpkgs/tigersh-deps-0.1.tiger.g3.tar.gz | gunzip | tar x

Alternatively, you can simply change the "https" to "http" if you aren't concerned about someone possibly snooping your key.

Usage:​


To use this script, you'd do something like:

Code:
sudo port -v install gcc14 ; notify.sh "gcc14 done"

However, if you control+z that port job to suspend it, it will immediately run notify.sh. If you need to be able to suspend and resume the job, you can instead do:

Code:
bash -c "sudo port -v install gcc14 ; notify.sh 'gcc14 done'"

The Python script:​


Here's a notify.py script which uses python to do the same thing:

Code:
#!/usr/bin/env python3

# notify.py: send a push notification from the command-line.
# ./notify.py "a message"

import sys
import urllib.request
import urllib.parse

APP_TOKEN="XXX"
USER_KEY="YYY"

url = "https://api.pushover.net/1/messages.json"

data = {
    "token": APP_TOKEN,
    "user": USER_KEY,
    "message": sys.argv[-1]
}

body = urllib.parse.urlencode(data).encode("utf-8")
urllib.request.urlopen(url, data=body).read().decode("utf-8")
 
  • Like
Reactions: redheeler
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.