Skip to content

Commit 04e0d4d

Browse files
authored
Merge pull request #26 from hazcod/fix/ventura
Feature: Ventura LoginItem support
2 parents f3ea30c + eb91b57 commit 04e0d4d

File tree

1 file changed

+52
-3
lines changed

1 file changed

+52
-3
lines changed

maclaunch.sh

Lines changed: 52 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,19 +40,19 @@ function getScriptUser {
4040
local scriptPath="$1"
4141

4242
# if it's in LaunchAgents, it's ran as the user
43-
if echo "$scriptPath" | grep -q "LaunchAgent"; then
43+
if echo "$scriptPath" | grep -sqi "LaunchAgent"; then
4444
whoami
4545
return
4646
fi
4747

4848
# if there is no UserName key, it's ran as root
49-
if ! grep -q '<key>UserName</key>' "$scriptPath"; then
49+
if ! grep -sqi '<key>UserName</key>' "$scriptPath"; then
5050
echo "root"
5151
return
5252
fi
5353

5454
# if UserName key is present, return the custom user
55-
grep '<key>UserName</key>' -C1 "$scriptPath" | tail -n1 | cut -d '>' -f 2 | cut -d '<' -f 1
55+
grep -si '<key>UserName</key>' -C1 "$scriptPath" | tail -n1 | cut -d '>' -f 2 | cut -d '<' -f 1
5656
}
5757

5858
function getKernelExtensions {
@@ -311,6 +311,53 @@ function disableSystemExtensions {
311311
done
312312
}
313313

314+
function getDisabledLoginItems {
315+
cat /var/db/com.apple.xpc.launchd/disabled.* | grep -is '<key>' -A1 | grep -is '<true' -B1 | grep -is '<key>' | cut -d '>' -f 2 | cut -d '<' -f 1
316+
}
317+
318+
function listLoginItems {
319+
local filter="$1"
320+
321+
runAsUser="$(whoami)"
322+
323+
disabledLoginItems=$(getDisabledLoginItems)
324+
325+
# for every plist found
326+
while IFS= read -r -d '' plistPath; do
327+
328+
loginItems=$(cat "$plistPath" | grep key | cut -d '>' -f 2 | cut -d '<' -f 1)
329+
330+
for loginItem in ${loginItems[@]}; do
331+
332+
if [ -n "$filter" ] && [ "$filter" != "enabled" ] && [ "$filter" != "disabled" ]; then
333+
if [[ "$loginItem" != *"$filter"* ]]; then
334+
continue
335+
fi
336+
fi
337+
338+
local launchState=""
339+
for disabledLoginItem in ${disabledLoginItems[@]}; do
340+
if [[ "$loginItem" == "$disabledLoginItem" ]]; then
341+
launchState="${GREEN}${BOLD}disabled"
342+
break
343+
fi
344+
done
345+
346+
if [ -z "" ]; then
347+
launchState="${YELLOW}LoginItem"
348+
fi
349+
350+
echo -e "${BOLD}> ${loginItem}${NC}${startup_type}"
351+
echo " Type : LoginItem"
352+
echo -e " User : ${runAsUser}"
353+
echo -e " Launch: ${launchState}${NC}"
354+
echo " File : ${plistPath}"
355+
356+
done
357+
358+
done< <(find /var/db/com.apple.xpc.launchd -iname "loginitems.*.plist" -print0 2>/dev/null)
359+
}
360+
314361
function listLaunchItems {
315362
local filter="$2"
316363

@@ -545,6 +592,7 @@ case "$1" in
545592
usage
546593
fi
547594

595+
listLoginItems "$2"
548596
listCronJobs "$2"
549597
listLaunchItems "$1" "$2"
550598
listKernelExtensions "$2"
@@ -557,6 +605,7 @@ case "$1" in
557605
usage
558606
fi
559607

608+
disableLoginItems "$2"
560609
disableLaunchItems "$2"
561610
disableKernelExtensions "$2"
562611
disableSystemExtensions "$2"

0 commit comments

Comments
 (0)