Skip to content

Instantly share code, notes, and snippets.

@MarcBernstein
Last active April 14, 2017 15:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MarcBernstein/bbbf099a87ae21643590078da777d554 to your computer and use it in GitHub Desktop.
Save MarcBernstein/bbbf099a87ae21643590078da777d554 to your computer and use it in GitHub Desktop.
Sets Slack status using new Status API. Save the script somewhere in your $PATH and set it executable.
#!/bin/bash
# Sets Slack status using new Status API.
# Save the script somewhere in your $PATH and set it executable.
slacktoken=<Your auth token, get one here https://api.slack.com/custom-integrations/legacy-tokens>
apiurl="https://slack.com/api/users.profile.set?token="$slacktoken"&profile="
if ! [ $# -eq 0 ] && ! [ $# -eq 2 ]; then
echo "Script takes exactly 0 (remove status ) or 2 arguments (emoji and status (in quotes if more than one word)).";
exit 1;
fi
if [ $# -eq 0 ]
then
status="\"status_text\": \"\", \"status_emoji\": \"\""
else
case $1 in
:*:)
emoji="$1";;
*)
emoji=":$1:";;
esac
status="\"status_text\": \"$2\", \"status_emoji\": \"${emoji}\""
fi
response=$(curl --silent --data-urlencode "profile={$status}" $apiurl)
if ! [[ $response =~ \"ok\":true ]]; then
echo "Setting status failed, check that emoji is valid?";
echo "Response was: $response"
exit 1;
else
if [ $# -eq 0 ]; then
echo "Status is unset."
else
echo "Status set to $2, emoji is $emoji"
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment