-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrun_onchange_import_plists.sh
executable file
·40 lines (32 loc) · 1.13 KB
/
run_onchange_import_plists.sh
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
#!/bin/bash
PLISTS_DIR="$HOME/.local/share/chezmoi/.plists"
# List of processes to restart
PROCESSES_TO_RESTART=(
"Rectangle"
# Add more process names here, e.g.:
# "AnotherApp"
# "SomeApp"
)
# Ensure the directory exists
if [ ! -d "$PLISTS_DIR" ]; then
echo "Error: Directory $PLISTS_DIR does not exist."
exit 1
fi
# Import all .plist files in the directory
for PLIST_FILE in "$PLISTS_DIR"/*.plist; do
# Check if the file exists to handle empty directories
if [ ! -f "$PLIST_FILE" ]; then
echo "No plist files found in $PLISTS_DIR."
exit 0
fi
DOMAIN=$(basename "$PLIST_FILE" .plist)
echo "Importing $DOMAIN preferences from $PLIST_FILE..."
defaults import "$DOMAIN" "$PLIST_FILE"
done
# Restart all specified processes
for PROCESS_NAME in "${PROCESSES_TO_RESTART[@]}"; do
echo "Restarting $PROCESS_NAME..."
pkill "$PROCESS_NAME" 2>/dev/null || echo "Process $PROCESS_NAME not running."
open -a "$PROCESS_NAME" 2>/dev/null || echo "Failed to restart $PROCESS_NAME. App may not be installed."
done
echo "All plist files have been successfully imported and processes restarted."