Skip to content

Commit 3a68f1d

Browse files
authored
Merge pull request #15 from hazcod/feat/new
feat(maclaunch): add periodic, logouthook, emond
2 parents 3cd00ab + 82ae6c5 commit 3a68f1d

2 files changed

Lines changed: 91 additions & 5 deletions

File tree

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ It does **not** alter the contents in any way or moves the file, so it should wo
4242

4343
The name you provide can either be specific to that service or function as a filter to work on multiple services simultaneously.
4444

45+
It can also use the environment variable `ML_SYSTEM=no` to skip anything system-related item.
46+
4547
## Installation
4648

4749
Installation can be done straight from [my Homebrew tap](https://github.com/hazcod/homebrew-hazcod) via `brew install hazcod/homebrew-hazcod/maclaunch` or just copy `maclaunch.sh` to your filesystem.
@@ -54,6 +56,8 @@ To list all your services: `maclaunch list`
5456

5557
To list all enabled services: `maclaunch list enabled`
5658

59+
To list all enabled services, ignoring internal ones: `ML_SYSTEM=no maclaunch list enabled`
60+
5761
To list all disabled services: `maclaunch list disabled`
5862

5963
To list all your services including system services: `maclaunch list system`

maclaunch.sh

Lines changed: 87 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env bash
22

3-
startup_dirs=(/Library/LaunchAgents /Library/LaunchDaemons ~/Library/LaunchAgents ~/Library/LaunchDaemons)
3+
startup_dirs=(/Library/LaunchAgents /Library/LaunchDaemons ~/Library/LaunchAgents ~/Library/LaunchDaemons /etc/emond.d/rules/)
44
system_dirs=(/System/Library/LaunchAgents /System/Library/LaunchDaemons)
55

66
RED='\033[0;31m'
@@ -13,6 +13,10 @@ BOLD='\033[1m'
1313
#--------------------------------------------------------------------------------------------------------------------------------------
1414
#
1515

16+
function isSystemItemsDisabled() {
17+
[[ "${ML_SYSTEM}" == "no" ]]
18+
}
19+
1620
function join_by { local IFS="$1"; shift; echo "$*"; }
1721

1822
function usage {
@@ -76,9 +80,69 @@ function listCronJobs {
7680
done
7781
}
7882

83+
function listPeriodic() {
84+
local filter="$1"
85+
86+
if isSystemItemsDisabled; then
87+
return
88+
fi
89+
90+
find /etc/periodic -type f | while IFS= read -r name; do
91+
mode="daily"
92+
93+
if [[ ${name} =~ /etc/periodic/weekly ]]; then
94+
mode="weekly"
95+
elif [[ ${name} =~ /etc/periodic/monthly ]]; then
96+
mode="monthly"
97+
fi
98+
99+
if [ -n "$filter" ] && ! [[ "$name" =~ $filter ]]; then
100+
continue
101+
fi
102+
103+
echo -e "${BOLD}> ${name}${NC}"
104+
echo -e " Type : periodic"
105+
echo -e " User : $(whoami)"
106+
echo -e " Launch: ${YELLOW}${mode}${NC}"
107+
echo " File : ${name}"
108+
done
109+
}
110+
111+
function enablePeriodic() {
112+
local filter="$1"
113+
114+
find /etc/periodic -type f | while IFS= read -r name; do
115+
116+
if [ -n "$filter" ] && ! [[ "$name" =~ $filter ]]; then
117+
continue
118+
fi
119+
120+
echo -e "${BOLD}${YELLOW}Warning: enable individual periodic scripts in /etc/defaults/periodic.conf${NC}"
121+
return
122+
done
123+
}
124+
125+
function disablePeriodic() {
126+
local filter="$1"
127+
128+
find /etc/periodic -type f | while IFS= read -r name; do
129+
130+
if [ -n "$filter" ] && ! [[ "$name" =~ $filter ]]; then
131+
continue
132+
fi
133+
134+
echo -e "${BOLD}${YELLOW}Warning: disable individual periodic scripts in /etc/defaults/periodic.conf${NC}"
135+
return
136+
done
137+
}
138+
79139
function listKernelExtensions {
80140
local filter="$1"
81141

142+
if isSystemItemsDisabled; then
143+
return
144+
fi
145+
82146
getKernelExtensions | while IFS= read -r kextLine; do
83147

84148
kextLoaded="$(echo "$kextLine" | cut -d ' ' -f 3)"
@@ -257,15 +321,26 @@ function listLaunchItems {
257321

258322
# add system dirs too if we supplied the system parameter
259323
if [ "$filter" == "system" ]; then
260-
itemDirectories=("${itemDirectories[@]}" "${system_dirs[@]}")
261-
filter=""
324+
if ! isSystemItemsDisabled; then
325+
itemDirectories=("${itemDirectories[@]}" "${system_dirs[@]}")
326+
filter=""
327+
fi
262328
fi
263329

264330
# login hooks
265-
if loginhooks=$(defaults read com.apple.loginwindow LoginHook 2>/dev/null); then
331+
if loginHooks=$(defaults read com.apple.loginwindow LoginHook 2>/dev/null); then
266332
echo -e "${RED}${BOLD}Warning: you have Login Hooks!${NC}"
267333
echo -e "${RED}Remove them (with sudo) from /var/root/Library/Preferences/com.apple.loginwindow"
268-
echo -e "${loginhooks}${NC}"
334+
echo -e "${loginHooks}${NC}"
335+
echo
336+
echo
337+
fi
338+
339+
# logout hooks
340+
if logoutHooks=$(defaults read com.apple.loginwindow LogoutHook 2>/dev/null); then
341+
echo -e "${RED}${BOLD}Warning: you have Login Hooks!${NC}"
342+
echo -e "${RED}Remove them (with sudo) from /var/root/Library/Preferences/com.apple.loginwindow"
343+
echo -e "${logoutHooks}${NC}"
269344
echo
270345
echo
271346
fi
@@ -315,6 +390,10 @@ function listLaunchItems {
315390
fi
316391

317392
load_items=("${GREEN}${BOLD}disabled")
393+
394+
# check if enabled is set to false in the plist
395+
elif echo "${content}" | tr -d '\n' | tr -d '\t' | tr -d ' ' | grep -q 'enabled</key><false'; then
396+
load_items=("${GREEN}${BOLD}disabled")
318397

319398
# if it's not disabled, list the startup triggers
320399
else
@@ -469,6 +548,7 @@ case "$1" in
469548
listLaunchItems "$1" "$2"
470549
listKernelExtensions "$2"
471550
listSystemExtensions "$2"
551+
listPeriodic "$2"
472552
;;
473553

474554
"disable")
@@ -479,6 +559,7 @@ case "$1" in
479559
disableLaunchItems "$2"
480560
disableKernelExtensions "$2"
481561
disableSystemExtensions "$2"
562+
disablePeriodic "$2"
482563
;;
483564

484565
"enable")
@@ -489,6 +570,7 @@ case "$1" in
489570
enableLaunchItems "$2"
490571
enableKernelExtensions "$2"
491572
enableSystemExtensions "$2"
573+
enablePeriodic "$2"
492574
;;
493575

494576
*)

0 commit comments

Comments
 (0)