mirror of
https://github.com/MLBZ521/MacAdmin.git
synced 2026-02-03 05:53:26 +00:00
v1.1.0 = Updates to console user, Python, & misc other logic
+ Updated logic that determines the current console user to no longer use the old Python method + Python3 compatibility; allow setting of a custom Python binary path + Renamed script + Miscellaneous code improvements
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
#!/bin/bash
|
||||
|
||||
###################################################################################################
|
||||
# Script Name: set_DefaultApplications.sh
|
||||
# Script Name: Set-DefaultApplications.sh
|
||||
# By: Zack Thompson / Created: 8/17/2017
|
||||
# Version: 1.0 / Updated: 8/17/2017 / By: ZT
|
||||
# Version: 1.1.0 / Updated: 3/17/2022 / By: ZT
|
||||
#
|
||||
# Description: This script will aid in setting the default applications on a Mac.
|
||||
#
|
||||
@@ -13,10 +13,8 @@
|
||||
#
|
||||
###################################################################################################
|
||||
|
||||
/bin/echo
|
||||
/bin/echo "Configuring Default Applications on this machine..."
|
||||
/bin/echo
|
||||
/bin/echo "***** Staging Configurations *****"
|
||||
echo -e "\nConfiguring Default Applications on this machine...\n"
|
||||
echo "***** Staging Configurations *****"
|
||||
|
||||
##################################################
|
||||
# Define JSS Variables
|
||||
@@ -36,7 +34,10 @@ webURLs=(https http)
|
||||
webExts=(public.html)
|
||||
|
||||
# Get the current user
|
||||
currentUser=$(/usr/bin/python -c 'from SystemConfiguration import SCDynamicStoreCopyConsoleUser; import sys; username = (SCDynamicStoreCopyConsoleUser(None, None, None) or [None])[0]; username = [username,""][username in [u"loginwindow", None, u""]]; sys.stdout.write(username + "\n");')
|
||||
currentUser=$( /usr/sbin/scutil <<< "show State:/Users/ConsoleUser" | /usr/bin/awk '/Name :/ && ! /loginwindow/ { print $3 }' )
|
||||
|
||||
# Set custom Python binary path
|
||||
python_binary="/opt/ManagedFrameworks/Python.framework/Versions/Current/bin/python3"
|
||||
|
||||
# Declare an array to add each Python scriptlet
|
||||
pythonScripts=()
|
||||
@@ -45,129 +46,128 @@ pythonScripts=()
|
||||
# Staging predefined Mail and Calendar identifiers
|
||||
# First make sure the variable is not empty.
|
||||
if [[ -n "$jssMailApp" ]]; then
|
||||
/bin/echo "Staging Mail URL Schemes and Calendar extensions..."
|
||||
if [[ ${jssMailApp} == "Outlook" ]]; then
|
||||
/bin/echo "Outlook for Mac was selected."
|
||||
echo "Staging Mail URL Schemes and Calendar extensions..."
|
||||
if [[ "${jssMailApp}" == "Outlook" ]]; then
|
||||
echo "Outlook for Mac was selected."
|
||||
mailApp="com.microsoft.Outlook"
|
||||
calApp="com.microsoft.Outlook"
|
||||
elif [[ ${jssMailApp} == "Parallels Outlook" ]]; then
|
||||
/bin/echo "A Parallels instance of Outlook was selected."
|
||||
elif [[ "${jssMailApp}" == "Parallels Outlook" ]]; then
|
||||
echo "A Parallels instance of Outlook was selected."
|
||||
# This will build the Parallels instance to get the identifier.
|
||||
# Set the base location
|
||||
parallelsDir=$("/Users/${currentUser}/Applications \(Parallels\)")
|
||||
parallelsDir="/Users/${currentUser}/Applications \(Parallels\)"
|
||||
# Get the Parallels Instance Identifier
|
||||
parallelsInstance=$(ls ${parallelsDir} | grep Applications)
|
||||
parallelsInstance=$(/bin/ls "${parallelsDir}" | /usr/bin/grep "Applications")
|
||||
# Get the Application Bundle ID
|
||||
parallelsOutlook=$("${parallelsDir}/${parallelsInstance}/Microsoft Outlook.app/Contents/Info.plist CFBundleIdentifier")
|
||||
parallelsOutlook="${parallelsDir}/${parallelsInstance}/Microsoft Outlook.app/Contents/Info.plist CFBundleIdentifier"
|
||||
|
||||
mailApp="${parallelsOutlook}"
|
||||
calApp="${parallelsOutlook}"
|
||||
|
||||
elif [[ ${jssMailApp} == "Apple Mail" ]]; then
|
||||
/bin/echo "Apple Mail was selected."
|
||||
elif [[ "${jssMailApp}" == "Apple Mail" ]]; then
|
||||
echo "Apple Mail was selected."
|
||||
mailApp="com.apple.mail"
|
||||
calApp="com.apple.ical"
|
||||
else
|
||||
/bin/echo "A custom mail application was selected."
|
||||
mailApp=${jssMailApp}
|
||||
calApp=${jssMailApp}
|
||||
echo "A custom mail application was selected."
|
||||
mailApp="${jssMailApp}"
|
||||
calApp="${jssMailApp}"
|
||||
fi
|
||||
|
||||
# Staging Mail and Calendar Applications Scriptlets
|
||||
# Set default application for a "URL://" scheme
|
||||
for mailURL in ${mailURLs[@]}; do
|
||||
py_mailURL="print (\"Configuring Mail URL Schemes\")
|
||||
for mailURL in "${mailURLs[@]}"; do
|
||||
py_mailURL="print(\"Configuring Mail URL Schemes\")
|
||||
from LaunchServices import LSSetDefaultHandlerForURLScheme
|
||||
LSSetDefaultHandlerForURLScheme(\"${mailURL}\", \"${mailApp}\")"
|
||||
pythonScripts+=("$py_mailURL")
|
||||
pythonScripts+=("${py_mailURL}")
|
||||
done
|
||||
|
||||
# Set default application for ".extension"
|
||||
for mailExt in ${mailExts[@]}; do
|
||||
py_mailExt="print (\"Configuring Mail and Calendar extensions\")
|
||||
for mailExt in "${mailExts[@]}"; do
|
||||
py_mailExt="print(\"Configuring Mail and Calendar extensions\")
|
||||
from LaunchServices import LSSetDefaultRoleHandlerForContentType
|
||||
LSSetDefaultRoleHandlerForContentType(\"${mailExt}\", 0xFFFFFFFF, \"${calApp}\")"
|
||||
pythonScripts+=("$py_mailExt")
|
||||
pythonScripts+=("${py_mailExt}")
|
||||
done
|
||||
fi
|
||||
|
||||
##################################################
|
||||
# Staging predefine Web Browser identifiers
|
||||
# First make sure the variable is not empty.
|
||||
if [[ -n "$jssBrowser" ]]; then
|
||||
/bin/echo "Staging Web Browser URL Schemes and Calendar extensions..."
|
||||
if [[ ${jssBrowser} == "Chrome" ]]; then
|
||||
/bin/echo "Chrome was selected."
|
||||
if [[ -n "${jssBrowser}" ]]; then
|
||||
echo "Staging Web Browser URL Schemes and Calendar extensions..."
|
||||
if [[ "${jssBrowser}" == "Chrome" ]]; then
|
||||
echo "Chrome was selected."
|
||||
browser="com.google.Chrome"
|
||||
elif [[ ${jssBrowser} == "Firefox" ]]; then
|
||||
/bin/echo "Firefox was selected."
|
||||
elif [[ "${jssBrowser}" == "Firefox" ]]; then
|
||||
echo "Firefox was selected."
|
||||
browser="org.mozilla.firefox"
|
||||
elif [[ ${jssBrowser} == "Safari" ]]; then
|
||||
/bin/echo "Safari was selected."
|
||||
elif [[ "${jssBrowser}" == "Safari" ]]; then
|
||||
echo "Safari was selected."
|
||||
browser="com.apple.Safari"
|
||||
else
|
||||
/bin/echo "A custom browser was selected."
|
||||
browser=${jssBrowser}
|
||||
echo "A custom browser was selected."
|
||||
browser="${jssBrowser}"
|
||||
fi
|
||||
|
||||
# Staging Web Browser Scriptlets
|
||||
# Set default application for a "URL://" scheme
|
||||
for webURL in ${webURLs[@]}; do
|
||||
py_webURL="print (\"Configuring Web Browser URL Schemes\")
|
||||
for webURL in "${webURLs[@]}"; do
|
||||
py_webURL="print(\"Configuring Web Browser URL Schemes\")
|
||||
from LaunchServices import LSSetDefaultHandlerForURLScheme
|
||||
LSSetDefaultHandlerForURLScheme(\"${webURL}\", \"${browser}\")"
|
||||
pythonScripts+=("$py_webURL")
|
||||
pythonScripts+=("${py_webURL}")
|
||||
done
|
||||
|
||||
# Set default application for ".extension"
|
||||
for webExt in ${webExts[@]}; do
|
||||
py_webExt="print (\"Configuring Web Browser extensions\")
|
||||
for webExt in "${webExts[@]}"; do
|
||||
py_webExt="print(\"Configuring Web Browser extensions\")
|
||||
from LaunchServices import LSSetDefaultRoleHandlerForContentType
|
||||
LSSetDefaultRoleHandlerForContentType(\"${webExt}\", 0xFFFFFFFF, \"${browser}\")"
|
||||
pythonScripts+=("$py_webExt")
|
||||
pythonScripts+=("${py_webExt}")
|
||||
done
|
||||
fi
|
||||
|
||||
##################################################
|
||||
# Staging Custom Application Scriptlets
|
||||
|
||||
if [[ -n "$jssURLScheme1" || -n "$jssURLApp1" ]]; then
|
||||
if [[ -n "${jssURLScheme1}" || -n "${jssURLApp1}" ]]; then
|
||||
# Set default application for a "URL://" scheme
|
||||
/bin/echo "Staging custom URL Scheme 1..."
|
||||
py_customURL="print (\"Configuring custom URL Scheme 1\")
|
||||
echo "Staging custom URL Scheme 1..."
|
||||
py_customURL="print(\"Configuring custom URL Scheme 1\")
|
||||
from LaunchServices import LSSetDefaultHandlerForURLScheme
|
||||
LSSetDefaultHandlerForURLScheme(\"${jssURLScheme1}\", \"${jssURLApp1}\")"
|
||||
pythonScripts+=("$py_customURL")
|
||||
pythonScripts+=("${py_customURL}")
|
||||
fi
|
||||
|
||||
if [[ -n "$jssExt1" || -n "$jssExtApp1" ]]; then
|
||||
if [[ -n "${jssExt1}" || -n "${jssExtApp1}" ]]; then
|
||||
# Set default application for ".extension"
|
||||
/bin/echo "Staging custom extensions 1..."
|
||||
py_customExt1="print (\"Configuring custom extensions 1\")
|
||||
echo "Staging custom extensions 1..."
|
||||
py_customExt1="print(\"Configuring custom extensions 1\")
|
||||
from LaunchServices import LSSetDefaultRoleHandlerForContentType
|
||||
LSSetDefaultRoleHandlerForContentType(\"${jssExt1}\", 0xFFFFFFFF, \"${jssExtApp1}\")"
|
||||
pythonScripts+=("$py_customExt1")
|
||||
pythonScripts+=("${py_customExt1}")
|
||||
fi
|
||||
|
||||
|
||||
if [[ -n "$jssExt2" || -n "$jssExtApp2" ]]; then
|
||||
if [[ -n "${jssExt2}" || -n "${jssExtApp2}" ]]; then
|
||||
# Set default application for ".extension"
|
||||
/bin/echo "Staging custom extensions 2..."
|
||||
py_customExt2="print (\"Configuring custom extensions 2\")
|
||||
echo "Staging custom extensions 2..."
|
||||
py_customExt2="print(\"Configuring custom extensions 2\")
|
||||
from LaunchServices import LSSetDefaultRoleHandlerForContentType
|
||||
LSSetDefaultRoleHandlerForContentType(\"${jssExt2}\", 0xFFFFFFFF, \"${jssExtApp2}\")"
|
||||
pythonScripts+=("$py_customExt2")
|
||||
pythonScripts+=("${py_customExt2}")
|
||||
fi
|
||||
|
||||
##################################################
|
||||
# Now do the work...
|
||||
|
||||
/bin/echo "***** Applying configurations... *****"
|
||||
echo "***** Applying configurations... *****"
|
||||
|
||||
for pythonScript in "${pythonScripts[@]}"; do
|
||||
sudo -u $currentUser -H /usr/bin/python -c "${pythonScript}"
|
||||
/usr/bin/sudo -u "${currentUser}" -H "${python_binary}" -c "${pythonScript}"
|
||||
done
|
||||
|
||||
/bin/echo "Script Complete!"
|
||||
|
||||
exit 0
|
||||
echo "Script Complete!"
|
||||
exit 0
|
||||
Reference in New Issue
Block a user