Fix disable function for macOS Big Sur

This commit is contained in:
Bat.bat 2020-07-06 16:56:41 +08:00
parent 9f01ee0d73
commit 80f139936f

115
hidpi.sh
View file

@ -29,6 +29,9 @@ langEnableOp1="(1) Enable HIDPI"
langEnableOp2="(2) Enable HIDPI (with EDID)" langEnableOp2="(2) Enable HIDPI (with EDID)"
langEnableOp3="(3) Disable HIDPI" langEnableOp3="(3) Disable HIDPI"
langDisableOpt1="(1) Disable HIDPI on this monitor"
langDisableOpt2="(2) Reset all settings to macOS default"
langChooseRes="resolution config" langChooseRes="resolution config"
langChooseResOp1="(1) 1920x1080 Display" langChooseResOp1="(1) 1920x1080 Display"
langChooseResOp2="(2) 1920x1080 Display (use 1424x802, fix underscaled after sleep)" langChooseResOp2="(2) 1920x1080 Display (use 1424x802, fix underscaled after sleep)"
@ -63,6 +66,9 @@ if [[ "${systemLanguage}" == "zh_CN" ]]; then
langEnableOp2="(2) 开启HIDPI(同时注入EDID)" langEnableOp2="(2) 开启HIDPI(同时注入EDID)"
langEnableOp3="(3) 关闭HIDPI" langEnableOp3="(3) 关闭HIDPI"
langDisableOpt1="(1) 在此显示器上禁用 HIDPI"
langDisableOpt2="(2) 还原所有设置至 macOS 默认"
langChooseRes="选择分辨率配置" langChooseRes="选择分辨率配置"
langChooseResOp1="(1) 1920x1080 显示屏" langChooseResOp1="(1) 1920x1080 显示屏"
langChooseResOp2="(2) 1920x1080 显示屏 (使用 1424x802 分辨率,修复睡眠唤醒后的屏幕缩小问题)" langChooseResOp2="(2) 1920x1080 显示屏 (使用 1424x802 分辨率,修复睡眠唤醒后的屏幕缩小问题)"
@ -89,7 +95,7 @@ if [[ "${sipInfo}" == *"Filesystem Protections: disabled"* ]] || [[ "$(awk '{pri
: :
else else
echo "${disableSIP}"; echo "${disableSIP}";
exit 0 exit 1
fi fi
# Starting from macOS Big Sur (16), this method no longer works # Starting from macOS Big Sur (16), this method no longer works
@ -142,7 +148,7 @@ function get_edid()
# Lower selection (arrays start at zero). # Lower selection (arrays start at zero).
if ((selection < 1 || selection > index)); then if ((selection < 1 || selection > index)); then
echo "${langEnterError}"; echo "${langEnterError}";
exit 0 exit 1
fi fi
let selection-=1 let selection-=1
gMonitor=${gDisplayInf[$selection]} gMonitor=${gDisplayInf[$selection]}
@ -150,7 +156,7 @@ function get_edid()
* ) * )
echo "${langEnterError}"; echo "${langEnterError}";
exit 0 exit 1
;; ;;
esac esac
else else
@ -207,19 +213,18 @@ EEF
fi fi
# In Big Sur+ files are created in a seperate dir, not necessary to backup # In Big Sur+ files are created in a seperate dir, not necessary to backup
if [[ "${systemVersion}" -le "15" ]]; then sudo mkdir -p ${thatDir}/HIDPI
if [[ ! -d ${thatDir}/HIDPI/backup ]]; then if [[ ! -d ${thatDir}/HIDPI/backup && "${systemVersion}" -le "15" ]]; then
echo "${langBackingUp}" echo "${langBackingUp}"
sudo mkdir -p ${thatDir}/HIDPI/backup sudo mkdir -p ${thatDir}/HIDPI/backup
sudo cp ${thatSysDir}/Icons.plist ${thatDir}/HIDPI/backup/ sudo cp ${thatSysDir}/Icons.plist ${thatDir}/HIDPI/backup/
if [[ -d ${thatSysDir}/DisplayVendorID-${Vid} ]]; then if [[ -d ${thatSysDir}/DisplayVendorID-${Vid} ]]; then
sudo cp -r ${thatSysDir}/DisplayVendorID-${Vid} ${thatDir}/HIDPI/backup/ sudo cp -r ${thatSysDir}/DisplayVendorID-${Vid} ${thatDir}/HIDPI/backup/
fi
fi fi
generate_restore_cmd
fi fi
generate_restore_cmd
} }
# #
@ -231,6 +236,8 @@ mkdir -p ${thisDir}/tmp/
cat > "${thisDir}/tmp/disable" <<-\CCC cat > "${thisDir}/tmp/disable" <<-\CCC
#!/bin/sh #!/bin/sh
systemVersion=($(sw_vers -productVersion | cut -d "." -f 2))
function get_edid() function get_edid()
{ {
local index=0 local index=0
@ -252,14 +259,14 @@ function get_edid()
[[:digit:]]* ) [[:digit:]]* )
if ((selection < 1 || selection > index)); then if ((selection < 1 || selection > index)); then
echo "Enter error, bye"; echo "Enter error, bye";
exit 0 exit 1
fi fi
let selection-=1 let selection-=1
gMonitor=${gDisplayInf[$selection]} gMonitor=${gDisplayInf[$selection]}
;; ;;
* ) * )
echo "Enter error, bye"; echo "Enter error, bye";
exit 0 exit 1
;; ;;
esac esac
else else
@ -275,13 +282,39 @@ function get_edid()
get_edid get_edid
if [[ -d ../DisplayVendorID-${Vid} ]]; then rootPath="../../../../../../.."
rm -rf ../DisplayVendorID-${Vid} if [[ "${systemVersion}" -ge "16" ]];
rootPath="../../../../../.."
fi fi
rm -rf ../Icons.plist echo ""
cp -r ./backup/* ../ echo "${langDisableOpt1}"
rm -rf ./disable echo "${langDisableOpt2}"
echo ""
read -p "${langInputChoice} [1~2]: " input
case ${input} in
1) ${rootPath}/usr/libexec/plistbuddy -c "Delete :vendors:${Vid}:products:${Pid}" ../Icons.plist
;;
2) if [[ "${systemVersion}" -ge "16" ]]; then
rm -rf ${rootPath}/Library/Displays
else
if [[ -d ../DisplayVendorID-${Vid} ]]; then
rm -rf ../DisplayVendorID-${Vid}
fi
rm -rf ../Icons.plist
cp -r ./backup/* ../
rm -rf ../HIDPI
fi
;;
*)
echo "Enter error, bye";
exit 1
;;
esac
echo "HIDPI Disabled" echo "HIDPI Disabled"
CCC CCC
@ -343,7 +376,7 @@ case ${logo} in
*) *)
echo "${langEnterError}"; echo "${langEnterError}";
exit 0 exit 1
;; ;;
esac esac
@ -431,7 +464,7 @@ case ${res} in
;; ;;
*) *)
echo "${langEnterError}"; echo "${langEnterError}";
exit 0 exit 1
;; ;;
esac esac
@ -565,17 +598,33 @@ function enable_hidpi_with_patch()
# disable # disable
function disable() function disable()
{ {
if [[ -d ${thatDir} && "${systemVersion}" -ge "16" ]]; then echo ""
sudo rm -rf ${libDisplaysDir} echo "${langDisableOpt1}"
else echo "${langDisableOpt2}"
if [[ -d ${thatDir}/DisplayVendorID-${Vid} ]]; then echo ""
sudo rm -rf ${thatDir}/DisplayVendorID-${Vid}
fi
sudo rm -rf ${thatDir}/Icons.plist read -p "${langInputChoice} [1~2]: " input
sudo cp -r ${thatDir}/HIDPI/backup/* ${thatDir}/ case ${input} in
sudo rm -rf ${thatDir}/HIDPI/disable 1) sudo /usr/libexec/plistbuddy -c "Delete :vendors:${Vid}:products:${Pid}" ${thatDir}/Icons.plist
fi ;;
2) if [[ "${systemVersion}" -ge "16" ]]; then
sudo rm -rf ${libDisplaysDir}
else
if [[ -d ${thatDir}/DisplayVendorID-${Vid} ]]; then
sudo rm -rf ${thatDir}/DisplayVendorID-${Vid}
fi
sudo rm -rf ${thatDir}/Icons.plist
sudo cp -r ${thatDir}/HIDPI/backup/* ${thatDir}/
sudo rm -rf ${thatDir}/HIDPI
fi
;;
*)
echo "${langEnterError}";
exit 1
;;
esac
echo "${langDisabled}" echo "${langDisabled}"
} }
@ -602,7 +651,7 @@ case ${input} in
*) *)
echo "${langEnterError}"; echo "${langEnterError}";
exit 0 exit 1
;; ;;
esac esac
} }