Skip to content

Commit

Permalink
Merge pull request #26 from hazcod/fix/ventura
Browse files Browse the repository at this point in the history
Feature: Ventura LoginItem support
  • Loading branch information
hazcod authored Nov 15, 2022
2 parents f3ea30c + eb91b57 commit 04e0d4d
Showing 1 changed file with 52 additions and 3 deletions.
55 changes: 52 additions & 3 deletions maclaunch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 '<key>UserName</key>' "$scriptPath"; then
if ! grep -sqi '<key>UserName</key>' "$scriptPath"; then
echo "root"
return
fi

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

function getKernelExtensions {
Expand Down Expand Up @@ -311,6 +311,53 @@ function disableSystemExtensions {
done
}

function getDisabledLoginItems {
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
}

function listLoginItems {
local filter="$1"

runAsUser="$(whoami)"

disabledLoginItems=$(getDisabledLoginItems)

# 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

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 " Type : LoginItem"
echo -e " User : ${runAsUser}"
echo -e " Launch: ${launchState}${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"

Expand Down Expand Up @@ -545,6 +592,7 @@ case "$1" in
usage
fi

listLoginItems "$2"
listCronJobs "$2"
listLaunchItems "$1" "$2"
listKernelExtensions "$2"
Expand All @@ -557,6 +605,7 @@ case "$1" in
usage
fi

disableLoginItems "$2"
disableLaunchItems "$2"
disableKernelExtensions "$2"
disableSystemExtensions "$2"
Expand Down

0 comments on commit 04e0d4d

Please sign in to comment.