From 8bf15f99a6fcf6cf4add49b29f0704831fdac20b Mon Sep 17 00:00:00 2001 From: Michael <30936296+mtan93@users.noreply.github.com> Date: Tue, 16 Apr 2024 16:59:47 +0100 Subject: [PATCH] Create logout-all.sh --- Mac/logout-all.sh | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 Mac/logout-all.sh diff --git a/Mac/logout-all.sh b/Mac/logout-all.sh new file mode 100644 index 0000000..877d3b7 --- /dev/null +++ b/Mac/logout-all.sh @@ -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"