Create logout-all.sh

This commit is contained in:
Michael
2024-04-16 16:59:47 +01:00
committed by GitHub
parent 3e229e29cf
commit 8bf15f99a6

31
Mac/logout-all.sh Normal file
View File

@@ -0,0 +1,31 @@
#!/bin/bash
# SOURCES USER INFO FOR RUNASUSER COMMAND BELOW
currentUser=$( echo "show State:/Users/ConsoleUser" | scutil | awk '/Name :/ { print $3 }' )
uid=$(id -u "$currentUser")
TSUSER=$(echo $currentUser)
# SIMPLIFIES RUN AS USER COMMAND FOR STANDARD USER ACCOUNTS WITHOUT SUDO RIGHTS
runAsUser() {
if [ "$currentUser" != "loginwindow" ]; then
launchctl asuser "$uid" sudo -u "$currentUser" "$@"
else
echo
echo "no user logged in"
echo
exit 1
fi
}
# Your list variable
list=$(runAsUser /Applications/Tailscale.app/Contents/MacOS/Tailscale switch --list)
# Loop over each line in the list
while read -r line; do
# Extract the ID using awk
id=$(echo "$line" | awk '{print $1}')
# Echo the ID
runAsUser /Applications/Tailscale.app/Contents/MacOS/Tailscale switch $id
sleep 2
runAsUser /Applications/Tailscale.app/Contents/MacOS/Tailscale logout
done <<< "$list"