Skip to content

Instantly share code, notes, and snippets.

@martin-v
Last active November 13, 2018 22:29
Show Gist options
  • Save martin-v/d1ae01dfbfe3f8beebd95425db880e37 to your computer and use it in GitHub Desktop.
Save martin-v/d1ae01dfbfe3f8beebd95425db880e37 to your computer and use it in GitHub Desktop.
Set slack status based on wifi name
#!/bin/bash
#
# Add the script to your crontab, e.g.
## */20 6-22 * * 1-5 $HOME/bin/slack-status/slack.sh >> $HOME/bin/slack-status/cron.log 2>&1
set -o nounset
set -o errexit
set -o pipefail
STATUS_VAILD_FOR=1260 # 20min cron + 1min puffer
# Get it from https://api.slack.com/custom-integrations/legacy-tokens
TOKEN=xoxp-...
TIME=$( date +%s )
EXPIRE=$(( TIME + STATUS_VAILD_FOR ))
SSID=$( /usr/sbin/iwgetid -r )
if [ "$SSID" == 'ReTest' ]
then
STATUS='Working%20at%20office'
EMOJI=':office:'
else
STATUS='Working%20remotely'
EMOJI=':house_with_garden:'
fi
# {"status_text": "$STATUS", "status_emoji": "$EMOJI", "status_expiration": "$EXPIRE" }
PROFILE="%7B%22status_text%22%3A%20%22$STATUS%22%2C%20%22status_emoji%22%3A%20%22$EMOJI%22%2C%20%22status_expiration%22%3A%20%22$EXPIRE%22%20%7D"
curl --silent --show-error --fail -X POST "https://slack.com/api/users.profile.set?profile=$PROFILE&token=$TOKEN" #--output /dev/null
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment