Created
March 22, 2024 16:18
-
-
Save gingerbeardman/ff346ea8e2704c316682df4f6ea47237 to your computer and use it in GitHub Desktop.
parallel version of script in the Alfred Remove Quarantine workflow
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Helpers | |
function app_as_json { | |
/usr/bin/osascript -l JavaScript -e 'function run(argv) { return JSON.stringify({ | |
title: $(argv[0]).stringByDeletingPathExtension.lastPathComponent.js, | |
subtitle: argv[0], | |
type: "file", | |
icon: { type: "fileicon", path: argv[0] }, | |
arg: argv[0] | |
})}' "${1}" | |
} | |
# Grab all apps as reported by Spotlight | |
[[ "${only_root_applications}" -eq 1 ]] && readonly filter=(-onlyin '/Applications') | |
readonly all_apps=("${(@f)$(/usr/bin/mdfind "${filter[@]}" "kMDItemContentTypeTree == 'com.apple.application-bundle'")}") | |
# Declare an array to store background processes' outputs | |
declare -a json_outputs=() | |
# Separate quarantined apps | |
for app in "${all_apps[@]}" | |
do | |
{ | |
# Initialize local variable to store JSON output | |
local json_item | |
# Skip unquarantined apps | |
/usr/bin/xattr -p 'com.apple.quarantine' "${app}" &> /dev/null || exit | |
# Skip signed and notarized apps, if option is enabled | |
[[ "${ignore_signed}" -eq 1 ]] && /usr/sbin/spctl --assess --type install "${app}" && exit | |
# Create JSON item | |
json_item=$(app_as_json "${app}") | |
# Output JSON item | |
echo "${json_item}" | |
} & | |
done | while IFS= read -r line; do | |
json_outputs+=("$line") | |
done | |
# Wait for all background processes to finish | |
wait | |
# Exit early if nothing to do | |
if [[ "${#json_outputs[@]}" -eq 0 ]] | |
then | |
printf '{ "items": [{ | |
"title": "No quarantined applications found", | |
"subtitle": "Use this workflow’s File Action if you need more granularity" | |
}]}' | |
exit 0 | |
fi | |
# List quarantined apps | |
printf '{ "items": [' | |
printf '%s,' "${json_outputs[@]}" | sed 's/,$//' | |
printf ']}' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment