diff --git a/maclaunch.sh b/maclaunch.sh
index ebfbebe..6cc3d4a 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,53 @@ 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
+
+ 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"
@@ -545,6 +592,7 @@ case "$1" in
usage
fi
+ listLoginItems "$2"
listCronJobs "$2"
listLaunchItems "$1" "$2"
listKernelExtensions "$2"
@@ -557,6 +605,7 @@ case "$1" in
usage
fi
+ disableLoginItems "$2"
disableLaunchItems "$2"
disableKernelExtensions "$2"
disableSystemExtensions "$2"