├── README.md ├── macOS_LidAndPlug_Power_Settings_de.sh ├── macOS_LidAndPlug_Power_Settings_en.sh ├── macOS_LidAndPlug_Power_Settings_fr.sh └── macbookpro_startup_icon.png /README.md: -------------------------------------------------------------------------------- 1 | # macOS lid and plug Powers Settings 2 | 3 | This script allows to choose the behavior of an Apple Silicon Macbook Pro/Air when a power cable is connected or the lid opened. 4 | More info here: https://support.apple.com/120622 5 | It requires SwiftDialog (https://github.com/swiftDialog) 6 | 7 | English and French version are provided. Feel free to modify for your own languages. 8 | 9 | German version provided by Markus Kachel (https://github.com/allandanton/macos_lid_and_plug_powersettings) 10 | 11 | This script requires root, so the best way to use it is to add it to your Self Service in Jamf Pro to allow the user to run it as they wish. You should scope only to Apple Silicon MacBook (Air/Pro). 12 | 13 | mac_power_settings_1 14 | 15 | mac_power_settings_2 16 | 17 | -------------------------------------------------------------------------------- /macOS_LidAndPlug_Power_Settings_de.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Author:Guillaume Gète 4 | # 01/02/2025 5 | 6 | # German translation 17/02/2025 by Markus Kachel 7 | 8 | # Allows to choose the behavior of an Apple Silicon Macbook Pro/Air when a power cable is connected or the lid opened. More info here: https://support.apple.com/120622 9 | # Requires SwiftDialog (https://github.com/swiftDialog) 10 | # v1.0 11 | 12 | # Requires an Apple Silicon processor 13 | 14 | if [ ! "$(uname -p)" = "arm" ]; then 15 | echo "This script runs only on Apple Silicon Macs." 16 | exit 1 17 | fi 18 | 19 | # Requires at least macOS 15 to run 20 | 21 | if [ "$(sw_vers --productVersion | cut -c 1-2 )" -lt "15" ]; then 22 | echo "This script requires at least macOS version 15." 23 | exit 1 24 | fi 25 | 26 | # Variables 27 | 28 | # Text displayed when the user wants the Mac to start when the Mac's display is opened 29 | 30 | lidOpenedDialog="wenn ich das Display des Macs aufklappe" 31 | 32 | # Text displayed when the user wants the Mac to start when power cable is plugged 33 | 34 | powerPluggedDialog="wenn ich das Netzteil anschließe" 35 | 36 | dialogButton1="Einstellungen anwenden" 37 | dialogButton2="Abbruch" 38 | titleDialog="Einschalt-Einstellungen" 39 | messageDialog="Ihr Mac kann sich automatisch beim Einstecken des Netzteils oder Aufklappen des Displays einschalten.\n\nWenn Sie dieses Verhalten ändern wollen, aktivieren oder deaktivieren sie die folgenden Optionen und klicken anschlie0end auf *$dialogButton1*.\n\n **Diesen Mac automatisch einschalten...**" 40 | 41 | 42 | successMessage="Die Einstellungen wurden angewendet." 43 | 44 | # Get current settings from BootPreference in NVRAM 45 | 46 | if nvram BootPreference 47 | then 48 | 49 | case $(nvram BootPreference) in 50 | "BootPreference %00") 51 | echo "Startup when connecting to power : FALSE - Startup when opening lid : FALSE" 52 | currentPlugSetting="false" 53 | currentLidSetting="false" 54 | ;; 55 | "BootPreference %01") 56 | echo "Startup when connecting to power : TRUE - Startup when opening lid : FALSE" 57 | currentPlugSetting="true" 58 | currentLidSetting="false" 59 | ;; 60 | "BootPreference %02") 61 | echo "Startup when connecting to power : FALSE - Startup when opening lid : TRUE" 62 | currentPlugSetting="false" 63 | currentLidSetting="true" 64 | ;; 65 | esac 66 | 67 | else 68 | # If there is an error, the BootPreference is missing, so it means both settings are ON. 69 | echo "Startup when connecting to power : TRUE - Startup when opening lid : TRUE" 70 | currentPlugSetting="true" 71 | currentLidSetting="true" 72 | fi 73 | 74 | 75 | #==================================================================# 76 | #--------------------# Installing SwiftDialog #--------------------# 77 | #==================================================================# 78 | 79 | # Requires the SwiftDialog framework. It will be installed if missing. Comment or remove if you prefer to push your own version of SwiftDialog. 80 | 81 | dialogPath="/usr/local/bin/dialog" 82 | dialogURL=$(curl --silent --fail "https://api.github.com/repos/bartreardon/swiftDialog/releases/latest" | awk -F '"' "/browser_download_url/ && /pkg\"/ { print \$4; exit }") 83 | 84 | if [ ! -e "$dialogPath" ]; then 85 | echo "SwiftDialog must be installed." 86 | curl -L "$dialogURL" -o "/tmp/dialog.pkg" 87 | installer -pkg /tmp/dialog.pkg -target / 88 | 89 | if [ ! -e "$dialogPath" ]; then 90 | echo "An error occured. SwiftDialog could not be installed." 91 | exit 1 92 | else 93 | echo "Swiftdialog is available. Moving on…" 94 | fi 95 | else 96 | echo "Swiftdialog is available. Moving on…" 97 | fi 98 | 99 | ## Create the settings for the dialog. This is required to set up some specific settings with checkboxes. 100 | 101 | tmpJson=$(mktemp "/tmp/dialogfile.XXXXXX") 102 | chmod 644 "$tmpJson" 103 | 104 | cat > "$tmpJson" < "$newPowerSettings" 132 | 133 | case $? in 134 | 0) 135 | # Get the values from the results 136 | 137 | lidOpenedSetting=$(grep "$lidOpenedDialog" "$newPowerSettings" | awk '{print $NF}' | sed 's/\"//g' ) 138 | 139 | powerPluggedSetting=$(grep "$powerPluggedDialog" "$newPowerSettings" | awk '{print $NF}' | sed 's/\"//g' ) 140 | 141 | echo "$lidOpenedSetting" 142 | echo "$powerPluggedSetting" 143 | 144 | 145 | if [ "$lidOpenedSetting" = "false" ] && [ "$powerPluggedSetting" = "false" ]; then 146 | nvram BootPreference=%00 147 | elif [ "$lidOpenedSetting" = "false" ] && [ "$powerPluggedSetting" = "true" ]; then 148 | nvram BootPreference=%01 149 | elif [ "$lidOpenedSetting" = "true" ] && [ "$powerPluggedSetting" = "false" ]; then 150 | nvram BootPreference=%02 151 | elif [ "$lidOpenedSetting" = "true" ] && [ "$powerPluggedSetting" = "true" ]; then 152 | nvram -d BootPreference 153 | fi 154 | 155 | dialog -m "$successMessage" --bannertitle "$titleDialog" --icon "SF=power.circle.fill,colour=green,animation=pulse" --style centered -s --bannerimage colour=green --bannerheight 50 --button1text "OK" 156 | 157 | ;; 158 | 2) 159 | echo "Pressed Cancel Button (button 2)" 160 | ;; 161 | esac 162 | 163 | # Cleanup 164 | rm -f "$tmpJson" "$newPowerSettings" 165 | 166 | exit 0 167 | -------------------------------------------------------------------------------- /macOS_LidAndPlug_Power_Settings_en.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Author:Guillaume Gète 4 | # 01/02/2025 5 | 6 | # Allows to choose the behavior of an Apple Silicon Macbook Pro/Air when a power cable is connected or the lid opened. More info here: https://support.apple.com/120622 7 | # Requires SwiftDialog (https://github.com/swiftDialog) 8 | # v1.0 9 | 10 | # Requires an Apple Silicon processor 11 | 12 | if [ ! "$(uname -p)" = "arm" ]; then 13 | echo "This script runs only on Apple Silicon Macs." 14 | exit 1 15 | fi 16 | 17 | # Requires at least macOS 15 to run 18 | 19 | if [ "$(sw_vers --productVersion | cut -c 1-2 )" -lt "15" ]; then 20 | echo "This script requires at least macOS version 15." 21 | exit 1 22 | fi 23 | 24 | # Variables 25 | 26 | # Text displayed when the user wants the Mac to start when the Mac's display is opened 27 | 28 | lidOpenedDialog="When the Mac's lid is opened" 29 | 30 | # Text displayed when the user wants the Mac to start when power cable is plugged 31 | 32 | powerPluggedDialog="When I plug a power cable" 33 | 34 | dialogButton1="Apply these settings" 35 | dialogButton2="Cancel" 36 | titleDialog="Power settings" 37 | messageDialog="Your Mac can start when you plug a power cable or if you open the lid. \n\nIf you want to change this behavior, check or uncheck the following settings and click on *$dialogButton1*. \n\n **Automatically power on the Mac :**" 38 | 39 | 40 | successMessage="The settings have been applied." 41 | 42 | # Get current settings from BootPreference in NVRAM 43 | 44 | if nvram BootPreference 45 | then 46 | 47 | case $(nvram BootPreference) in 48 | "BootPreference %00") 49 | echo "Startup when connecting to power : FALSE - Startup when opening lid : FALSE" 50 | currentPlugSetting="false" 51 | currentLidSetting="false" 52 | ;; 53 | "BootPreference %01") 54 | echo "Startup when connecting to power : TRUE - Startup when opening lid : FALSE" 55 | currentPlugSetting="true" 56 | currentLidSetting="false" 57 | ;; 58 | "BootPreference %02") 59 | echo "Startup when connecting to power : FALSE - Startup when opening lid : TRUE" 60 | currentPlugSetting="false" 61 | currentLidSetting="true" 62 | ;; 63 | esac 64 | 65 | else 66 | # If there is an error, the BootPreference is missing, so it means both settings are ON. 67 | echo "Startup when connecting to power : TRUE - Startup when opening lid : TRUE" 68 | currentPlugSetting="true" 69 | currentLidSetting="true" 70 | fi 71 | 72 | 73 | #==================================================================# 74 | #--------------------# Installing SwiftDialog #--------------------# 75 | #==================================================================# 76 | 77 | # Requires the SwiftDialog framework. It will be installed if missing. Comment or remove if you prefer to push your own version of SwiftDialog. 78 | 79 | dialogPath="/usr/local/bin/dialog" 80 | dialogURL=$(curl --silent --fail "https://api.github.com/repos/bartreardon/swiftDialog/releases/latest" | awk -F '"' "/browser_download_url/ && /pkg\"/ { print \$4; exit }") 81 | 82 | if [ ! -e "$dialogPath" ]; then 83 | echo "SwiftDialog must be installed." 84 | curl -L "$dialogURL" -o "/tmp/dialog.pkg" 85 | installer -pkg /tmp/dialog.pkg -target / 86 | 87 | if [ ! -e "$dialogPath" ]; then 88 | echo "An error occured. SwiftDialog could not be installed." 89 | exit 1 90 | else 91 | echo "Swiftdialog is available. Moving on…" 92 | fi 93 | else 94 | echo "Swiftdialog is available. Moving on…" 95 | fi 96 | 97 | ## Create the settings for the dialog. This is required to set up some specific settings with checkboxes. 98 | 99 | tmpJson=$(mktemp "/tmp/dialogfile.XXXXXX") 100 | chmod 644 "$tmpJson" 101 | 102 | cat > "$tmpJson" < "$newPowerSettings" 130 | 131 | case $? in 132 | 0) 133 | # Get the values from the results 134 | 135 | lidOpenedSetting=$(grep "$lidOpenedDialog" "$newPowerSettings" | awk '{print $NF}' | sed 's/\"//g' ) 136 | 137 | powerPluggedSetting=$(grep "$powerPluggedDialog" "$newPowerSettings" | awk '{print $NF}' | sed 's/\"//g' ) 138 | 139 | echo "$lidOpenedSetting" 140 | echo "$powerPluggedSetting" 141 | 142 | 143 | if [ "$lidOpenedSetting" = "false" ] && [ "$powerPluggedSetting" = "false" ]; then 144 | nvram BootPreference=%00 145 | elif [ "$lidOpenedSetting" = "false" ] && [ "$powerPluggedSetting" = "true" ]; then 146 | nvram BootPreference=%01 147 | elif [ "$lidOpenedSetting" = "true" ] && [ "$powerPluggedSetting" = "false" ]; then 148 | nvram BootPreference=%02 149 | elif [ "$lidOpenedSetting" = "true" ] && [ "$powerPluggedSetting" = "true" ]; then 150 | nvram -d BootPreference 151 | fi 152 | 153 | dialog -m "$successMessage" --bannertitle "$titleDialog" --icon "SF=power.circle.fill,colour=green,animation=pulse" --style centered -s --bannerimage colour=green --bannerheight 50 --button1text "OK" 154 | 155 | ;; 156 | 2) 157 | echo "Pressed Cancel Button (button 2)" 158 | ;; 159 | esac 160 | 161 | # Cleanup 162 | rm -f "$tmpJson" "$newPowerSettings" 163 | 164 | exit 0 165 | -------------------------------------------------------------------------------- /macOS_LidAndPlug_Power_Settings_fr.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Author:Guillaume Gète 4 | # 01/02/2025 5 | 6 | # Allows to choose the behavior of an Apple Silicon Macbook Pro/Air when a power cable is connected or the lid opened. More info here: https://support.apple.com/120622 7 | # Requires SwiftDialog (https://github.com/swiftDialog) 8 | # v1.0 9 | 10 | # Requires an Apple Silicon processor 11 | 12 | if [ ! "$(uname -p)" = "arm" ]; then 13 | echo "This script runs only on Apple Silicon Macs." 14 | exit 1 15 | fi 16 | 17 | # Requires at least macOS 15 to run 18 | 19 | if [ "$(sw_vers --productVersion | cut -c 1-2 )" -lt "15" ]; then 20 | echo "This script requires at least macOS version 15." 21 | exit 1 22 | fi 23 | 24 | # Variables 25 | 26 | # Text displayed when the user wants the Mac to start when the Mac's display is opened 27 | 28 | lidOpenedDialog="Quand l'écran du Mac est ouvert" 29 | 30 | # Text displayed when the user wants the Mac to start when power cable is plugged 31 | 32 | powerPluggedDialog="Quand je branche un cable d'alimentation" 33 | 34 | dialogButton1="Appliquer ces réglages" 35 | dialogButton2="Annuler" 36 | titleDialog="Réglages d'alimentation" 37 | messageDialog="Votre Mac peut être démarré lorsque vous branchez un câble d'alimentation ou lorsque vous ouvrez l'écran. \n\nSi vous souhaitez changer ce comportement, cochez ou décochez les réglages suivants et cliquez sur *$dialogButton1*. \n\n **Allumer automatiquement le Mac :**" 38 | 39 | 40 | successMessage="Les nouveaux réglages ont été appliqués." 41 | 42 | # Get current settings from BootPreference in NVRAM 43 | 44 | if nvram BootPreference 45 | then 46 | 47 | case $(nvram BootPreference) in 48 | "BootPreference %00") 49 | echo "Startup when connecting to power : FALSE - Startup when opening lid : FALSE" 50 | currentPlugSetting="false" 51 | currentLidSetting="false" 52 | ;; 53 | "BootPreference %01") 54 | echo "Startup when connecting to power : TRUE - Startup when opening lid : FALSE" 55 | currentPlugSetting="true" 56 | currentLidSetting="false" 57 | ;; 58 | "BootPreference %02") 59 | echo "Startup when connecting to power : FALSE - Startup when opening lid : TRUE" 60 | currentPlugSetting="false" 61 | currentLidSetting="true" 62 | ;; 63 | esac 64 | 65 | else 66 | # If there is an error, the BootPreference is missing, so it means both settings are ON. 67 | echo "Startup when connecting to power : TRUE - Startup when opening lid : TRUE" 68 | currentPlugSetting="true" 69 | currentLidSetting="true" 70 | fi 71 | 72 | 73 | #==================================================================# 74 | #--------------------# Installing SwiftDialog #--------------------# 75 | #==================================================================# 76 | 77 | # Requires the SwiftDialog framework. It will be installed if missing. Comment or remove if you prefer to push your own version of SwiftDialog. 78 | 79 | dialogPath="/usr/local/bin/dialog" 80 | dialogURL=$(curl --silent --fail "https://api.github.com/repos/bartreardon/swiftDialog/releases/latest" | awk -F '"' "/browser_download_url/ && /pkg\"/ { print \$4; exit }") 81 | 82 | if [ ! -e "$dialogPath" ]; then 83 | echo "SwiftDialog must be installed." 84 | curl -L "$dialogURL" -o "/tmp/dialog.pkg" 85 | installer -pkg /tmp/dialog.pkg -target / 86 | 87 | if [ ! -e "$dialogPath" ]; then 88 | echo "An error occured. SwiftDialog could not be installed." 89 | exit 1 90 | else 91 | echo "Swiftdialog is available. Moving on…" 92 | fi 93 | else 94 | echo "Swiftdialog is available. Moving on…" 95 | fi 96 | 97 | ## Create the settings for the dialog. This is required to set up some specific settings with checkboxes. 98 | 99 | tmpJson=$(mktemp "/tmp/dialogfile.XXXXXX") 100 | chmod 644 "$tmpJson" 101 | 102 | cat > "$tmpJson" < "$newPowerSettings" 130 | 131 | case $? in 132 | 0) 133 | # Get the values from the results 134 | 135 | lidOpenedSetting=$(grep "$lidOpenedDialog" "$newPowerSettings" | awk '{print $NF}' | sed 's/\"//g' ) 136 | 137 | powerPluggedSetting=$(grep "$powerPluggedDialog" "$newPowerSettings" | awk '{print $NF}' | sed 's/\"//g' ) 138 | 139 | echo "$lidOpenedSetting" 140 | echo "$powerPluggedSetting" 141 | 142 | 143 | if [ "$lidOpenedSetting" = "false" ] && [ "$powerPluggedSetting" = "false" ]; then 144 | nvram BootPreference=%00 145 | elif [ "$lidOpenedSetting" = "false" ] && [ "$powerPluggedSetting" = "true" ]; then 146 | nvram BootPreference=%01 147 | elif [ "$lidOpenedSetting" = "true" ] && [ "$powerPluggedSetting" = "false" ]; then 148 | nvram BootPreference=%02 149 | elif [ "$lidOpenedSetting" = "true" ] && [ "$powerPluggedSetting" = "true" ]; then 150 | nvram -d BootPreference 151 | fi 152 | 153 | dialog -m "$successMessage" --bannertitle "$titleDialog" --icon "SF=power.circle.fill,colour=green,animation=pulse" --style centered -s --bannerimage colour=green --bannerheight 50 --button1text "OK" 154 | 155 | ;; 156 | 2) 157 | echo "Pressed Cancel Button (button 2)" 158 | ;; 159 | esac 160 | 161 | # Cleanup 162 | rm -f "$tmpJson" "$newPowerSettings" 163 | 164 | exit 0 165 | -------------------------------------------------------------------------------- /macbookpro_startup_icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/guillaumegete/macos_lid_and_plug_powersettings/bcf0f15ff907786d216881485d659702a37a2615/macbookpro_startup_icon.png --------------------------------------------------------------------------------