Created
January 14, 2022 10:37
-
-
Save Josasp/d1c39d2f562c1f2ccefdcf81e038f411 to your computer and use it in GitHub Desktop.
Run with "sudo bash edit_display.sh" from Terminal. Requires VS Code installed.
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 | |
cd /Library/Preferences | |
BACKUP_NAME=com.apple.windowserver.displays_$(date +%F-%H_%M).plist | |
echo "Backing up plist to $BACKUP_NAME" | |
cp com.apple.windowserver.displays.plist $BACKUP_NAME | |
open_xml () { | |
echo "Converting plist to XML..." | |
plutil -convert xml1 com.apple.windowserver.displays.plist | |
echo "Opening in VS Code..." | |
sudo code com.apple.windowserver.displays.plist | |
} | |
open_xml | |
VALID=1 | |
while [ $VALID -eq 1 ] | |
do | |
echo "Edit the file in VS Code, save and hit enter here when done [Enter]:" | |
read dummy | |
echo "Converting the file back to binary..." | |
plutil -convert binary1 com.apple.windowserver.displays.plist | |
echo "Validating file..." | |
plutil -lint /Library/Preferences/com.apple.windowserver.displays.plist | |
VALID=$? | |
if [ $VALID -eq 1 ] | |
then | |
echo "Validation FAIL, try editing again" | |
open_xml | |
else | |
echo "Validation OK" | |
fi | |
done | |
echo "Removing the ByHost-file..." | |
rm ~/Library/Preferences/ByHost/com.apple.windowserver*.plist | |
while true; do | |
read -p "Reboot? [Y/n]: " yn | |
case $yn in | |
[Yy]* ) sudo reboot; break;; | |
[Nn]* ) echo "Exiting"; exit;; | |
* ) echo "Please answer yes or no.";; | |
esac | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment