Skip to content

Commit d6f4ce3

Browse files
committed
fix(maclaunch): add ML_SYSTEM env and fix disabled check
1 parent 4dd2941 commit d6f4ce3

2 files changed

Lines changed: 25 additions & 2 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: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#!/usr/bin/env bash
22

3+
env_system_no_var="ML_SYSTEM"
34
startup_dirs=(/Library/LaunchAgents /Library/LaunchDaemons ~/Library/LaunchAgents ~/Library/LaunchDaemons /etc/emond.d/rules/)
45
system_dirs=(/System/Library/LaunchAgents /System/Library/LaunchDaemons)
56

@@ -13,6 +14,10 @@ BOLD='\033[1m'
1314
#--------------------------------------------------------------------------------------------------------------------------------------
1415
#
1516

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

1823
function usage {
@@ -79,6 +84,10 @@ function listCronJobs {
7984
function listPeriodic() {
8085
local filter="$1"
8186

87+
if isSystemItemsDisabled; then
88+
return
89+
fi
90+
8291
find /etc/periodic -type f | while IFS= read -r name; do
8392
mode="daily"
8493

@@ -131,6 +140,10 @@ function disablePeriodic() {
131140
function listKernelExtensions {
132141
local filter="$1"
133142

143+
if isSystemItemsDisabled; then
144+
return
145+
fi
146+
134147
getKernelExtensions | while IFS= read -r kextLine; do
135148

136149
kextLoaded="$(echo "$kextLine" | cut -d ' ' -f 3)"
@@ -309,8 +322,10 @@ function listLaunchItems {
309322

310323
# add system dirs too if we supplied the system parameter
311324
if [ "$filter" == "system" ]; then
312-
itemDirectories=("${itemDirectories[@]}" "${system_dirs[@]}")
313-
filter=""
325+
if ! isSystemItemsDisabled; then
326+
itemDirectories=("${itemDirectories[@]}" "${system_dirs[@]}")
327+
filter=""
328+
fi
314329
fi
315330

316331
# login hooks
@@ -376,6 +391,10 @@ function listLaunchItems {
376391
fi
377392

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

380399
# if it's not disabled, list the startup triggers
381400
else

0 commit comments

Comments
 (0)