Intro
This post will step through how to configure OSMC to send push notifications to your device (iOS, Android, Desktop) based on a range of triggers. There are many ways you could use this script, I’ve included a couple of examples.
All steps below should work on any system, but they have been tested on a Raspberry Pi 2 running OSMC 2015.07-1.
1. Register for Pushover
- Register for a Pushover account at www.pushover.net. You get a 7 day trial for free, after that there is a one-off cost of $4.99 USD per receiving platform.
- Install the Pushover app on your receiving platform of choice.
- Create a new Application within the Pushover web interface. You can call the app whatever you like but “OSMC” makes sense. I use this icon for the app to keep it looking consistent:
- Make a note of your User Key and your newly created application’s API Key – you will need
these to send notifications.
2. Create the notification script
Create a file /home/osmc/push.sh
with the following content:
#!/bin/bash
# Uses the Pushover API to send the first command line parameter as a push notification
curl -s \
--form-string "token=YOUR_APPLICATION_API_KEY" \
--form-string "user=YOUR_USER_API_KEY" \
--form-string "message=$1" \
https://api.pushover.net/1/messages.json > /dev/null
- Insert your own User Key and Application API Key from above.
- Make the script executable by running
chmod +x /home/osmc/push.sh
It is possible to send more complicated notifications than a simple message. Read the Pushover API documentation for details.
3. Test the notification script
The script will take the first command line parameter passed to it and send it out as a
notification. To test the script, run
/home/osmc/push.sh “YOUR NOTIFICATION IN HERE”
Note the quotes around the notification text. You should receive the notification you typed on your device. Make sure this is working before you set up any other triggers.
4. Set up some triggers
Now you have a working push script, you can set up triggers to notify you on whatever events you choose. Two examples are below.
4.1 Push a notification when OSMC upgrades packages
This will notify when packages have been upgraded within the system using apt
. (I realise that technically, this trigger will fire on other dpkg
actions, but for the majority of users the only time dpkg
is executed is when the system is upgrading packages).
Create the file /etc/apt/apt.conf.d/99-post-update
with the following content:
Dpkg::Post-Invoke {"/home/osmc/push.sh 'Packages have been upgraded'";};
When the system upgrades packages you should get a notification.
4.2 Push a notification when a new video is added to your media directory
This will notify when a new file is added to a directory of your choosing (including sub-directories).
First, install the inotify
package:
sudo apt-get install inotify-tools
Create a new file /home/osmc/folderwatch.sh
with the following content:
#!/bin/bash
# Pushes a notification when a file is created in WATCHDIR
# The test for a file is that it has an extension ("something.anything")
# Neeeds inotify-tools package installed
# Uses separate script push.sh to interact with Pushover API
# Sleeps for 5 seconds after each notification to avoid flooding on multiple small file creation
WATCHDIR="/path/to/your/watch/directory"
echo "Starting folderwatch..."
while true
do
inotifywait -q -r -e create --format %f "$WATCHDIR" |
while read FILE; do
if [[ $FILE == *.* ]]; then
MESSAGE="${FILE%.*} is ready to watch"
/home/osmc/push.sh "$MESSAGE"
echo "Push notification sent: $MESSAGE"
sleep 5
fi
done
done
Make this script executable:
chmod +x /home/osmc/folderwatch.sh
Create a new file /etc/systemd/system/folderwatch.service
with the following content:
[Unit]
Description=Watch a folder and notify when files are created
[Service]
Type=simple
ExecStart=/home/osmc/folderwatch.sh | systemd-cat -t folderwatch
[Install]
WantedBy=multi-user.target
Start the service by running:
sudo systemctl daemon-reload
sudo systemctl enable folderwatch
sudo systemctl start folderwatch
Copy a video file into your watch directory and you should get a notification sent to your
device.