Skip to content

Instantly share code, notes, and snippets.

@harryi3t
Created January 10, 2017 10:59
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save harryi3t/f5f98f13a67ff8b9710fd6dba297b5a5 to your computer and use it in GitHub Desktop.
Save harryi3t/f5f98f13a67ff8b9710fd6dba297b5a5 to your computer and use it in GitHub Desktop.
set the slack status as away on screen lock and back to active on screen unlock
#/bin/bash
TOKEN='put your token here. Get a new from https://api.slack.com/docs/oauth-test-tokens'
dbus-monitor --session type='signal',interface='com.canonical.Unity.Session' | while true
do
read x
if echo "$x" | grep -q Locked; then
echo "set yourself away at $(date)"
curl -X GET -H "Cache-Control: no-cache" "https://slack.com/api/users.setPresence?token=$TOKEN&presence=away"
elif echo "$x" | grep -q Unlocked; then
echo "set yourself active at $(date)"
curl -X GET -H "Cache-Control: no-cache" "https://slack.com/api/users.setPresence?token=$TOKEN&presence=auto"
fi
done
@mdadils
Copy link

mdadils commented Feb 14, 2023

Getting dbus-monitor: command not found.
How to make it work for Mac-based systems? I really appreciate any help you can provide.

@Xaraxia
Copy link

Xaraxia commented Feb 20, 2023

Getting dbus-monitor: command not found. How to make it work for Mac-based systems? I really appreciate any help you can provide.

You can't - dbus is Linux specific. You would need to work out how you can detect presence in Mac.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment