From 763316b994b6859e54ec4eec868843e5660bbaff Mon Sep 17 00:00:00 2001 From: Niels Hofmans Date: Tue, 15 Nov 2022 08:43:14 +0100 Subject: [PATCH 1/2] feat: add Ventura loginItem support --- maclaunch.sh | 36 +++++++++++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/maclaunch.sh b/maclaunch.sh index ebfbebe..ec90cab 100755 --- a/maclaunch.sh +++ b/maclaunch.sh @@ -40,19 +40,19 @@ function getScriptUser { local scriptPath="$1" # if it's in LaunchAgents, it's ran as the user - if echo "$scriptPath" | grep -q "LaunchAgent"; then + if echo "$scriptPath" | grep -sqi "LaunchAgent"; then whoami return fi # if there is no UserName key, it's ran as root - if ! grep -q 'UserName' "$scriptPath"; then + if ! grep -sqi 'UserName' "$scriptPath"; then echo "root" return fi # if UserName key is present, return the custom user - grep 'UserName' -C1 "$scriptPath" | tail -n1 | cut -d '>' -f 2 | cut -d '<' -f 1 + grep -si 'UserName' -C1 "$scriptPath" | tail -n1 | cut -d '>' -f 2 | cut -d '<' -f 1 } function getKernelExtensions { @@ -311,6 +311,35 @@ function disableSystemExtensions { done } +function listLoginItems { + local filter="$1" + + runAsUser="$(whoami)" + + # for every plist found + while IFS= read -r -d '' plistPath; do + + loginItems=$(cat "$plistPath" | grep key | cut -d '>' -f 2 | cut -d '<' -f 1) + + for loginItem in ${loginItems[@]}; do + + if [ -n "$filter" ] && [ "$filter" != "enabled" ] && [ "$filter" != "disabled" ]; then + if [[ "$loginItem" != *"$filter"* ]]; then + continue + fi + fi + + echo -e "${BOLD}> ${loginItem}${NC}${startup_type}" + echo -e " Type : ${YELLOW}LoginItem${NC}" + echo -e " User : ${runAsUser}" + echo -e " Launch: ?${NC}" + echo " File : ${plistPath}" + + done + + done< <(find /var/db/com.apple.xpc.launchd -iname "loginitems.*.plist" -print0 2>/dev/null) +} + function listLaunchItems { local filter="$2" @@ -545,6 +574,7 @@ case "$1" in usage fi + listLoginItems "$2" listCronJobs "$2" listLaunchItems "$1" "$2" listKernelExtensions "$2" From eb91b579651f419652430db159fabcbe9476ab19 Mon Sep 17 00:00:00 2001 From: Niels Hofmans Date: Tue, 15 Nov 2022 09:05:38 +0100 Subject: [PATCH 2/2] feat: detect LoginItem disabled state --- maclaunch.sh | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/maclaunch.sh b/maclaunch.sh index ec90cab..6cc3d4a 100755 --- a/maclaunch.sh +++ b/maclaunch.sh @@ -311,10 +311,16 @@ function disableSystemExtensions { done } +function getDisabledLoginItems { + cat /var/db/com.apple.xpc.launchd/disabled.* | grep -is '' -A1 | grep -is '' | cut -d '>' -f 2 | cut -d '<' -f 1 +} + function listLoginItems { local filter="$1" runAsUser="$(whoami)" + + disabledLoginItems=$(getDisabledLoginItems) # for every plist found while IFS= read -r -d '' plistPath; do @@ -328,11 +334,23 @@ function listLoginItems { continue fi fi + + local launchState="" + for disabledLoginItem in ${disabledLoginItems[@]}; do + if [[ "$loginItem" == "$disabledLoginItem" ]]; then + launchState="${GREEN}${BOLD}disabled" + break + fi + done + + if [ -z "" ]; then + launchState="${YELLOW}LoginItem" + fi echo -e "${BOLD}> ${loginItem}${NC}${startup_type}" - echo -e " Type : ${YELLOW}LoginItem${NC}" + echo " Type : LoginItem" echo -e " User : ${runAsUser}" - echo -e " Launch: ?${NC}" + echo -e " Launch: ${launchState}${NC}" echo " File : ${plistPath}" done @@ -587,6 +605,7 @@ case "$1" in usage fi + disableLoginItems "$2" disableLaunchItems "$2" disableKernelExtensions "$2" disableSystemExtensions "$2"