Script to set Safari homepage on Mac
Configuring the homepage allows you to control what will be displayed when a user launches the browser. Here is a custom script that will help you set the homepage for macOS devices. Remotely execute it using the Execute Custom Script action from the Hexnode console.
Configure default Safari homepage
Use the script below to set the default homepage for the currently logged-in user on a macOS device:
sudo killall -z -m "Safari" -signal
# Loop through each user to set homepage prefs
for user in $(ls /Users | grep -v Shared | grep -v npsparcc | grep -v ".localized"); do
### Safari ###
# Use defaults command to set Safari homepage
su - "$user" -c "defaults write com.apple.Safari HomePage $homepage"
su - "$user" -c "defaults write com.apple.Safari NewWindowBehavior -int 0"
su - "$user" -c "defaults write com.apple.Safari NewTabBehavior -int 0"
su - "$user" -c "defaults read com.apple.Safari"
echo "Set new Safari homepage to $homepage for $user."
Replace the URL mentioned in the script with your desired homepage URL. The
homepage URL in the script becomes the default homepage in the
com.apple.Safari.plist file. The
homepage URL is launched automatically when a new tab or window is opened on the browser.