Advertisement
Guest User

Search URLs Handlers on Mac OS X

a guest
Jan 18th, 2011
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.38 KB | None | 0 0
  1. #!/usr/bin/env bash
  2.  
  3. #########
  4. #
  5. # searchURLHandlers.sh
  6. #       Name : searchURLHandlers
  7. #       Version : 2.0
  8. #       Created : 2011-01-18
  9. #       Modified : 2011-01-18
  10. #
  11. #########
  12. #
  13. # Search for each app known by Spotlight if a CFBundleURLTypes key
  14. # is present in Info.plist and displays if yes
  15. #
  16. #########
  17. #
  18. # Version history :
  19. #                  
  20. #       2011-01-18 1.0 :    initial release
  21. #       2011-01-18 2.0 :    added filters for apps without URLs Handlers and to clean output
  22. #
  23. #########
  24.  
  25. PATH="/bin:/sbin:/usr/bin:/usr/sbin"
  26. export PATH
  27.  
  28.  
  29. VERSION="searchURLHandlers v2.0 2011-01-18"
  30.  
  31. ERRORLOG="/tmp/searchURLHandleerror.log"
  32. PLISTBUDDY="/usr/libexec/PlistBuddy"
  33. OLDIFS=$IFS
  34. IFS=$(echo -en "\n\b")
  35.  
  36. for i in $(mdfind "kMDItemContentTypeTree == "com.apple.application-bundle"" | grep app); do
  37.     if [[ -f $i/Contents/Info.plist ]]; then
  38.         NBARRAYS=$($PLISTBUDDY -c "print :CFBundleURLTypes" ${i}/Contents/Info.plist 2>$ERRORLOG | awk -F '=' '/CFBundleURLSchemes = /{print $2}' | wc -l)
  39.         if [[ $NBARRAYS -gt 0 ]]; then
  40.             echo "$i"
  41.             for (( nb = 0; nb < $NBARRAYS; nb++ )); do
  42.                 $PLISTBUDDY -c "print :CFBundleURLTypes:$nb:CFBundleURLName" ${i}/Contents/Info.plist 2>$ERRORLOG
  43.                 $PLISTBUDDY -c "print :CFBundleURLTypes:$nb:CFBundleURLSchemes" ${i}/Contents/Info.plist 2>$ERRORLOG | egrep -v "{|}" | tr -d "\n" && echo
  44.             done
  45.             echo -e "\n"
  46.         fi
  47.     fi
  48. done
  49.  
  50. rm $ERRORLOG
  51. IFS=$OLDIFS
  52.  
  53. exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement