# 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](https://www.hexnode.com/mobile-device-management/help/how-to-run-scripts-on-mac-using-hexnode-mdm/) action from the Hexnode console.

 Disclaimer:The sample scripts provided below are adapted from third-party open source sites.

 

Configure default Safari homepage 
----------------------------------

Use the script below to set the default homepage for the currently logged-in user on a macOS device:

Script to set Safari homepage

homepage="www.hexnode.com" 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." done 

   1

2

3

4

5

6

7

8

9

10

11

12

13

14

  homepage="www.hexnode.com"

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."

done 

   

 

  

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.

 Notes:- It is recommended to manually validate the script execution on a system before executing the action in bulk.
- Hexnode will not be responsible for any damage/loss to the system on the behavior of the script.