Advertisement
ucomesdag

forklift-default

May 3rd, 2022 (edited)
912
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.47 KB | None | 0 0
  1. #!/usr/bin/env bash
  2.  
  3. # Copyright (C) 2022 Uco Mesdag
  4. # Description:  Set and unset ForkLift as the default file viewer instead of
  5. #               the Finder.
  6. # Usage:        forklift-default
  7.  
  8. file=~/Library/Preferences/com.apple.LaunchServices/com.apple.launchservices.secure.plist
  9.  
  10. # Remove entries to prevent duplicates
  11. plutil -convert xml1 $file
  12. sed -i ':a;N;s/\n/&/4;Ta;/com\.binarynights\.ForkLift-3/!{P;D};:b;N;s/\n/&/;Tb;d' $file
  13. sed -i ':a;N;s/\n/&/4;Ta;/com\.apple\.finder/!{P;D};:b;N;s/\n/&/;Tb;d' $file
  14. plutil -convert binary1 $file
  15.  
  16. if [[ "$(defaults read -g NSFileViewer 2>/dev/null)" = "com.binarynights.ForkLift-3" ]]; then
  17.   echo "Resetting FileViewer to Finder.."
  18.   defaults delete -g NSFileViewer
  19.   defaults write com.apple.LaunchServices/com.apple.launchservices.secure LSHandlers -array-add '{LSHandlerContentType="public.folder";LSHandlerRoleAll="com.apple.finder";}'
  20.   osascript -e 'tell app "System Events" to display notification "Finder is now the default file viewer again." with title "FileViewer changed"'
  21. else
  22.   echo "Setting FileViewer to ForkLift.."
  23.   defaults write -g NSFileViewer -string com.binarynights.ForkLift-3;
  24.   defaults write com.apple.LaunchServices/com.apple.launchservices.secure LSHandlers -array-add '{LSHandlerContentType="public.folder";LSHandlerRoleAll="com.binarynights.ForkLift-3";}'
  25.   osascript -e 'tell app "System Events" to display notification "Forklift is now the default file viewer." with title "FileViewer changed"'
  26. fi
  27.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement