Last active
April 26, 2022 12:34
-
-
Save soundsnw/d1274cc074d72919e5891d22b91733fd to your computer and use it in GitHub Desktop.
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
#!/bin/bash | |
export PATH=/usr/bin:/bin:/usr/sbin:/sbin | |
# | |
# Check if Preview.app is the default PDF reader and change it back if it isn't | |
# | |
# Get OS version and logged in user | |
osVersion=$(/usr/bin/sw_vers -productVersion | awk -F. '{print $2}') | |
loggedInUser=$(scutil <<<"show State:/Users/ConsoleUser" | awk '/Name :/ && ! /loginwindow/ { print $3 }') | |
# Check if Preview.app is the default PDF reader, exit gracefully if it is | |
if [[ ! $(/usr/bin/sudo -u "$loggedInUser" /usr/local/orgutils/swda getUTIs | grep com.adobe.pdf | grep Preview) ]]; then | |
echo "Preview.app is not the default PDF reader." | |
else | |
echo "Preview.app is the default PDF reader" | |
exit 0 | |
fi | |
# Check OS version and change PDF reader to Preview.app (in a new location on Catalina) | |
if [[ "$osVersion" -ge 15 ]]; then | |
/usr/bin/sudo -u "loggedInUser" /usr/local/orgutils/swda setHandler --UTI com.adobe.pdf --app /System/Applications/Preview.app | |
else | |
/usr/bin/sudo -u "loggedInUser" /usr/local/orgutils/swda setHandler --UTI com.adobe.pdf --app /Applications/Preview.app | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment