-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuninstall.sh
More file actions
executable file
·51 lines (42 loc) · 1.81 KB
/
uninstall.sh
File metadata and controls
executable file
·51 lines (42 loc) · 1.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/bin/bash
# Uninstall Screenshot Renamer.
# Works both as a normal user (CLI uninstall) and as root (pkg postinstall).
set -e
# Detect context: running as root (pkg postinstall) vs normal user
if [ "$(id -u)" -eq 0 ]; then
CURRENT_USER=$( /usr/bin/stat -f "%Su" /dev/console )
USER_HOME=$( /usr/bin/dscl . -read /Users/"$CURRENT_USER" NFSHomeDirectory | /usr/bin/awk '{print $NF}' )
CURRENT_USER_UID=$( /usr/bin/id -u "$CURRENT_USER" )
AS_USER=(/usr/bin/sudo -u "$CURRENT_USER")
LAUNCHCTL_CMD=(/bin/launchctl asuser "$CURRENT_USER_UID" /bin/launchctl)
else
USER_HOME="$HOME"
AS_USER=()
LAUNCHCTL_CMD=(launchctl)
fi
LAUNCH_AGENT_PLIST="$USER_HOME/Library/LaunchAgents/nz.glen.screenshot-renamer.plist"
echo "Screenshot Renamer Uninstall"
echo "============================"
echo
# Unload and remove Launch Agent
if [ -f "$LAUNCH_AGENT_PLIST" ]; then
echo "Unloading Launch Agent..."
"${LAUNCHCTL_CMD[@]}" unload "$LAUNCH_AGENT_PLIST" 2>/dev/null || true
rm "$LAUNCH_AGENT_PLIST"
echo "Removed $LAUNCH_AGENT_PLIST"
fi
# Remove watcher script and timestamp file
rm -f "$USER_HOME/Library/Scripts/rename-new-screenshots.sh"
rm -f "$USER_HOME/Library/Scripts/.rename-screenshot-lastrun"
echo "Removed watcher script"
# Reset screenshot location to default Desktop
echo "Resetting screenshot location to Desktop..."
"${AS_USER[@]}" defaults write com.apple.screencapture location "$USER_HOME/Desktop"
killall SystemUIServer 2>/dev/null || true
# Clean up any leftover staging from pkg install. May fail if invoked
# without root (e.g. direct CLI run) — harmless either way.
rm -rf /usr/local/share/screenshot-renamer 2>/dev/null || true
echo
echo "Done."
echo "The 'Rename Screenshot' Shortcut and screenshots directory were not removed."
echo "Delete them manually if you no longer need them."