| 1 | #!/bin/bash |
| 2 | |
| 3 | ## unquarantine.command |
| 4 | # Basic script for fixing apps that get blocked by Gatekeeper on Macs, especially Apple Silicon Macs. |
| 5 | # "This app my harm your mac" or other such messages. |
| 6 | # Make the script executable (chmod +x) then double-click it, and follow the directions |
| 7 | # |
| 8 | |
| 9 | echo "Drag an app (or other file) from Finder into this window, then press Enter." |
| 10 | echo "Optionally type flags immediately before it, no space needed: c = clear all extended attrs, s = force re-sign (e.g. 'cs' then drag)." |
| 11 | echo "The dropped path must be absolute (starting with /), as Finder drag-and-drop provides by default." |
| 12 | echo "Press Ctrl+C to quit." |
| 13 | |
| 14 | while true; do |
| 15 | echo |
| 16 | read -r -p "> " line |
| 17 | [ -z "$line" ] && continue |
| 18 | |
| 19 | if [[ "$line" =~ ^[[:space:]]*(c|s|cs|sc)?[[:space:]]*(/.*)$ ]]; then |
| 20 | flags="${BASH_REMATCH[1]}" |
| 21 | path_part="${BASH_REMATCH[2]}" |
| 22 | else |
| 23 | echo "Couldn't parse that — the dropped path must be absolute (start with /)." |
| 24 | continue |
| 25 | fi |
| 26 | |
| 27 | # Terminal inserts dropped paths as backslash-escaped shell words. |
| 28 | eval "files=($path_part)" |
| 29 | |
| 30 | any_ok=false |
| 31 | for f in "${files[@]}"; do |
| 32 | if [ ! -e "$f" ]; then |
| 33 | echo "Not found: $f" |
| 34 | continue |
| 35 | fi |
| 36 | |
| 37 | if [[ "$flags" == *c* ]]; then |
| 38 | echo "Clearing all extended attributes from: $f" |
| 39 | xattr -cr "$f" |
| 40 | else |
| 41 | echo "Removing quarantine attribute from: $f" |
| 42 | xattr -d com.apple.quarantine -r "$f" |
| 43 | fi |
| 44 | |
| 45 | if [[ "$flags" == *s* ]]; then |
| 46 | echo "Force re-signing: $f" |
| 47 | codesign --force --deep --sign - "$f" |
| 48 | elif codesign -dv "$f" &>/dev/null; then |
| 49 | echo "Already signed." |
| 50 | else |
| 51 | echo "Not signed — ad-hoc signing: $f" |
| 52 | codesign --force --deep --sign - "$f" |
| 53 | fi |
| 54 | |
| 55 | any_ok=true |
| 56 | done |
| 57 | |
| 58 | $any_ok && echo "Done." |
| 59 | done |
| 60 |
ergosteur / Mac Scripts
Last active 1 month ago
Scripts for use on macOS