Last active
December 30, 2020 17:09
-
-
Save retpolanne/07f02259fd02cea61473449c2b18ea67 to your computer and use it in GitHub Desktop.
Slack script that changes your status to AFK or Working Remotely
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
usage="$(basename "$0") [OPTIONS] -- changes your Slack status to AFK or Working Remotely | |
[OPTIONS]: | |
-h|--help This help message | |
--afk Changes your Slack profile to AFK | |
--remote Changes your Slack profile to Working Remotely | |
--token Your Slack token (see https://api.slack.com/legacy/custom-integrations/legacy-tokens) | |
" | |
if [[ $# == 0 ]]; then | |
echo "$usage" | |
exit | |
fi | |
while [[ $# -gt 0 ]]; do | |
key="$1" | |
case $key in | |
-h|--help) | |
echo "$usage" | |
exit | |
;; | |
--afk) | |
AFK=1 | |
REMOTE=0 | |
shift | |
;; | |
--remote) | |
REMOTE=1 | |
AFK=0 | |
shift | |
;; | |
--token) | |
SLACK_TOKEN=$2 | |
shift | |
shift | |
;; | |
esac | |
done | |
if [ "$REMOTE" == "1" ]; then | |
SLACK_TEXT="Working remotely" | |
SLACK_EMOJI=":house_with_garden:" | |
fi | |
if [ "$AFK" == "1" ]; then | |
SLACK_TEXT="AFK" | |
SLACK_EMOJI=":keyboard:" | |
fi | |
curl -X POST "https://slack.com/api/users.profile.set" \ | |
-H "Content-Type: application/json" \ | |
-H "Authorization: Bearer ${SLACK_TOKEN}" \ | |
--data '{ | |
"profile": { | |
"status_text": "'"${SLACK_TEXT}"'", | |
"status_emoji": "'"${SLACK_EMOJI}"'", | |
"status_expiration": 0 | |
} | |
}' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can call this script via Apple's Script editor, if you want to keep it handy on your Mac's menu bar.