Last active
December 3, 2019 11:35
-
-
Save danielrotaermel/5c51d2ce17e6245a1d83fd0699abb4e8 to your computer and use it in GitHub Desktop.
switch between 2 splice users
This file contains hidden or 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 | |
# script to switch between splice users | |
# get currently logged in user | |
current_username=`security find-generic-password -s "Digital Creations Inc:Splice:credentials" 2> /dev/null | grep -o 'acct.*' | cut -f3- -d\" | rev | cut -c 2- | rev` | |
current_token=`security find-generic-password -s "Digital Creations Inc:Splice:credentials" -w 2> /dev/null` | |
# get saved switcher accounts | |
saved_username=`security find-generic-password -a "saved-user" -s "splice-account-switcher" 2> /dev/null | grep -o 'acct.*' | cut -f3- -d\" | rev | cut -c 2- | rev` | |
saved_token=`security find-generic-password -s "splice-account-switcher" -w 2> /dev/null` | |
# save current account if it wasnt saved before | |
if [[ $saved_token == "" ]] | |
then | |
# save current password to a new keychain entry | |
security add-generic-password -a "saved-user" -s "splice-account-switcher" -w "`security find-generic-password -s "Digital Creations Inc:Splice:credentials" -w`" -U | |
echo "saved current user to temporary keychain item" | |
echo "now sign out of yout current user in splice and sign in with your second one" | |
#sleep 1s | |
open -a splice | |
sleep 0.5s | |
# sign out current splice user | |
osascript <<EOF | |
tell application "System Events" | |
tell process "Splice" | |
set frontmost to true | |
click menu item "Log out" of menu "Splice" of menu bar 1 | |
end tell | |
end tell | |
EOF | |
else | |
if [[ $saved_token != $current_token ]] | |
then | |
# stop splice if its currently running | |
osascript -e 'quit app "splice"' | |
sleep 0.5s | |
# update current splice user | |
security add-generic-password -a "$current_username" -s "Digital Creations Inc:Splice:credentials" -w "$saved_token" -U | |
# update saved splice user | |
security add-generic-password -a "saved-user" -s "splice-account-switcher" -w "$current_token" -U | |
echo "switched user" | |
# start splice | |
open -a splice | |
else | |
# do nothing | |
echo "nothing to switch here" | |
fi | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment