Skip to content

Instantly share code, notes, and snippets.

@hjhart
Created August 1, 2014 00:31
Show Gist options
  • Save hjhart/dae8551ee62bd2d09051 to your computer and use it in GitHub Desktop.
Save hjhart/dae8551ee62bd2d09051 to your computer and use it in GitHub Desktop.
Log out user from Slack.app and reopen Slack.app
#!/bin/bash
shut_down_slack() {
RELAUNCH_SLACK=0
local process_pattern='[S]lack.app'
local process_identifier='Slack'
ps -e | grep "$process_pattern" > /dev/null
if [ $? -eq 0 ]; then
echo "Slack is open! Closing Slack in 5 seconds."
sleep 5
killall "$process_identifier"
RELAUNCH_SLACK=1
else
echo "${process_name} is not open."
fi
}
delete_local_data_for_slack() {
echo "Deleting Slacks login data!"
defaults delete com.tinyspeck.slackmacgap
rm -rf ~/Library/Application\ Support/Slack/
rm -rf ~/Library/Containers/com.tinyspeck.slackmacgap/
rm -rf ~/Library/Preferences/com.tinyspeck.slackmacgap.plist
}
reopen_slack() {
local application_filepath=~/Applications/Slack.app
sleep 1
if [ $RELAUNCH_SLACK -eq 1 ]; then
echo "Reopening ${application_filepath}"
open "$application_filepath"
else
echo "${application_filepath} was not running. Not reopening"
fi
}
main() {
shut_down_slack
delete_local_data_for_slack
reopen_slack
}
main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment