Modify the recovery method and optimize the code structure

This commit is contained in:
xzhih 2020-11-16 08:50:08 +08:00
parent 84e35ead60
commit fa0e36f68a
3 changed files with 248 additions and 228 deletions

View file

@ -38,34 +38,42 @@ bash -c "$(curl -fsSL https://raw.githubusercontent.com/xzhih/one-key-hidpi/dev/
### 恢复模式 ### 恢复模式
如果使用此脚本后,开机无法进入系统,请到 macos 恢复模式中或使用 clover `-x` 安全模式进入系统,打开终端 如果使用此脚本后,开机无法进入系统,请到 macos 恢复模式,打开终端
这里有两种方式进行关闭,建议选第一种 这里有两种方式进行关闭,建议选第一种
1. 快捷恢复 1. 快捷恢复
```bash ```bash
ls /Volumes/ ls /Volumes/
cd /Volumes/你的系统盘/System/Library/Displays/Contents/Resources/Overrides/HIDPI ```
./disable 你会看到你的系统盘
```bash
cd /Volumes/你的系统盘/Users/
ls
```
你可以看到所有用户的家目录
```bash
cd 你的用户名
./.hidpi-disable
``` ```
2. 手动恢复 2. 手动恢复
使用终端删除 `/System/Library/Displays/Contents/Resources/Overrides` 下删除显示器 VendorID 对应的文件夹,并把 `HIDPI/backup` 文件夹中的备份复制出来。 使用终端删除 `Library/Displays/Contents/Resources/Overrides` 下删除所有通过外部注入的显示器配置文件夹
请使用单个显示器执行以下命令,笔记本关闭外接显示器的 HIDPI 时请关闭内置显示器
具体命令如下: 具体命令如下:
```bash ```bash
ls /Volumes/ ls /Volumes/
cd /Volumes/你的系统盘/System/Library/Displays/Contents/Resources/Overrides rm -rf /Volumes/你的系统盘/Library/Displays/Contents/Resources/Overrides
EDID=($(ioreg -lw0 | grep -i "IODisplayEDID" | sed -e "/[^<]*</s///" -e "s/\>//"))
Vid=($(echo $EDID | cut -c18-20))
rm -rf ./DisplayVendorID-$Vid
cp -r ./HIDPI/backup/* ./
``` ```
## 从以下得到启发 ## 从以下得到启发

View file

@ -44,26 +44,31 @@ There are two ways to close it. It is recommended to choose the first one
```bash ```bash
ls /Volumes/ ls /Volumes/
cd /Volumes/"Your System Disk Part"/System/Library/Displays/Contents/Resources/Overrides/HIDPI ```
./disable you can see all Disk.
```bash
cd /Volumes/"Your System Disk Part"/Users/
ls
```
you can see user home directory.
```bash
cd "user name"
./.hidpi-disable
``` ```
2. 2.
Remove your display's DisplayVendorID folder under `/System/Library/Displays/Contents/Resources/Overrides` , and move backup files Remove all injected display's DisplayVendorID folder under `Library/Displays/Contents/Resources/Overrides`
Please use the single display to execute the following commands. If it is a laptop, turn off the internal monitor when turning off the HIDPI of the external monitor.
In Terminal:
```bash ```bash
ls /Volumes/ ls /Volumes/
cd /Volumes/"Your System Disk Part"/System/Library/Displays/Contents/Resources/Overrides rm -rf /Volumes/"Your System Disk Part"/Library/Displays/Contents/Resources/Overrides
EDID=($(ioreg -lw0 | grep -i "IODisplayEDID" | sed -e "/[^<]*</s///" -e "s/\>//"))
Vid=($(echo $EDID | cut -c18-20))
rm -rf ./DisplayVendorID-$Vid
cp -r ./HIDPI/backup/* ./
``` ```
## Inspired ## Inspired

407
hidpi.sh
View file

@ -1,6 +1,6 @@
#!/bin/bash #!/bin/bash
cat << EEF cat <<EEF
_ _ _____ _____ _____ _____ _ _ _____ _____ _____ _____
| | | | |_ _| | __ \ | __ \ |_ _| | | | | |_ _| | __ \ | __ \ |_ _|
| |__| | | | | | | | | |__) | | | | |__| | | | | | | | | |__) | | |
@ -11,6 +11,7 @@ cat << EEF
============================================ ============================================
EEF EEF
currentDir="$(cd $(dirname -- $0) && pwd)"
systemLanguage=($(locale | grep LANG | sed s/'LANG='// | tr -d '"' | cut -d "." -f 1)) systemLanguage=($(locale | grep LANG | sed s/'LANG='// | tr -d '"' | cut -d "." -f 1))
langDisplay="Display" langDisplay="Display"
@ -81,8 +82,7 @@ if [[ "${systemLanguage}" == "zh_CN" ]]; then
langChooseResOpCustom="(6) 手动输入分辨率" langChooseResOpCustom="(6) 手动输入分辨率"
fi fi
function get_edid() function get_edid() {
{
local index=0 local index=0
local selection=0 local selection=0
@ -98,8 +98,7 @@ function get_edid()
echo "--------------------------------------------------------" echo "--------------------------------------------------------"
# Show monitors. # Show monitors.
for display in "${gDisplayInf[@]}" for display in "${gDisplayInf[@]}"; do
do
let index++ let index++
MonitorName=("$(echo ${display:190:24} | xxd -p -r)") MonitorName=("$(echo ${display:190:24} | xxd -p -r)")
VendorID=${display:16:4} VendorID=${display:16:4}
@ -122,20 +121,20 @@ function get_edid()
read -p "${langChooseDis}: " selection read -p "${langChooseDis}: " selection
case $selection in case $selection in
[[:digit:]]* ) [[:digit:]]*)
# 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 1
fi
let selection-=1
gMonitor=${gDisplayInf[$selection]}
;;
* )
echo "${langEnterError}";
exit 1 exit 1
;; fi
let selection-=1
gMonitor=${gDisplayInf[$selection]}
;;
*)
echo "${langEnterError}"
exit 1
;;
esac esac
else else
gMonitor=${gDisplayInf} gMonitor=${gDisplayInf}
@ -152,47 +151,42 @@ function get_edid()
} }
# init # init
function init() function init() {
{ rm -rf ${currentDir}/tmp/
get_edid mkdir -p ${currentDir}/tmp/
currentDir="$(cd `dirname -- $0` && pwd)" libDisplaysDir="/Library/Displays"
libDisplaysDir="/Library/Displays" targetDir="${libDisplaysDir}/Contents/Resources/Overrides"
targetDir="${libDisplaysDir}/Contents/Resources/Overrides" sysDisplayDir="/System${targetDir}"
sysDisplayDir="/System${targetDir}" Overrides="\/Library\/Displays\/Contents\/Resources\/Overrides"
Overrides="\/Library\/Displays\/Contents\/Resources\/Overrides" sysOverrides="\/System${Overrides}"
sysOverrides="\/System${Overrides}"
DICON="com\.apple\.cinema-display" if [[ ! -d "${targetDir}" ]]; then
imacicon=${sysOverrides}"\/DisplayVendorID\-610\/DisplayProductID\-a032\.tiff" sudo mkdir -p "${targetDir}"
mbpicon=${sysOverrides}"\/DisplayVendorID\-610\/DisplayProductID\-a030\-e1e1df\.tiff" fi
mbicon=${sysOverrides}"\/DisplayVendorID\-610\/DisplayProductID\-a028\-9d9da0\.tiff"
lgicon=${sysOverrides}"\/DisplayVendorID\-1e6d\/DisplayProductID\-5b11\.tiff"
proxdricon=${Overrides}"\/DisplayVendorID\-610\/DisplayProductID\-ae2f\_Landscape\.tiff"
if [[ ! -d ${targetDir}/HIDPI ]]; then
sudo mkdir -p ${targetDir}/HIDPI
fi
downloadHost="https://raw.githubusercontent.com/xzhih/one-key-hidpi/master" downloadHost="https://raw.githubusercontent.com/xzhih/one-key-hidpi/master"
if [ -d "${currentDir}/displayIcons" ];then if [ -d "${currentDir}/displayIcons" ]; then
downloadHost="file://${currentDir}" downloadHost="file://${currentDir}"
fi fi
generate_restore_cmd DICON="com\.apple\.cinema-display"
imacicon=${sysOverrides}"\/DisplayVendorID\-610\/DisplayProductID\-a032\.tiff"
mbpicon=${sysOverrides}"\/DisplayVendorID\-610\/DisplayProductID\-a030\-e1e1df\.tiff"
mbicon=${sysOverrides}"\/DisplayVendorID\-610\/DisplayProductID\-a028\-9d9da0\.tiff"
lgicon=${sysOverrides}"\/DisplayVendorID\-1e6d\/DisplayProductID\-5b11\.tiff"
proxdricon=${Overrides}"\/DisplayVendorID\-610\/DisplayProductID\-ae2f\_Landscape\.tiff"
get_edid
generate_restore_cmd
} }
# #
function generate_restore_cmd() function generate_restore_cmd() {
{
#
rm -rf ${currentDir}/tmp/
mkdir -p ${currentDir}/tmp/
cat > "${currentDir}/tmp/disable" <<-\CCC
#!/bin/sh
function get_edid() cat >"$(cd && pwd)/.hidpi-disable" <<-\CCC
{ #!/bin/sh
function get_edid() {
local index=0 local index=0
local selection=0 local selection=0
gDisplayInf=($(ioreg -lw0 | grep -i "IODisplayEDID" | sed -e "/[^<]*</s///" -e "s/\>//")) gDisplayInf=($(ioreg -lw0 | grep -i "IODisplayEDID" | sed -e "/[^<]*</s///" -e "s/\>//"))
@ -201,26 +195,25 @@ function get_edid()
echo '------------------------------------' echo '------------------------------------'
echo ' Index | VendorID | ProductID ' echo ' Index | VendorID | ProductID '
echo '------------------------------------' echo '------------------------------------'
for display in "${gDisplayInf[@]}" for display in "${gDisplayInf[@]}"; do
do
let index++ let index++
printf " %d | ${display:16:4} | ${gMonitor:22:2}${gMonitor:20:2}\n" $index printf " %d | ${display:16:4} | ${gMonitor:22:2}${gMonitor:20:2}\n" $index
done done
echo '------------------------------------' echo '------------------------------------'
read -p "Choose the display: " selection read -p "Choose the display: " selection
case $selection in case $selection in
[[:digit:]]* ) [[:digit:]]*)
if ((selection < 1 || selection > index)); then if ((selection < 1 || selection > index)); then
echo "Enter error, bye"; echo "Enter error, bye"
exit 1
fi
let selection-=1
gMonitor=${gDisplayInf[$selection]}
;;
* )
echo "Enter error, bye";
exit 1 exit 1
;; fi
let selection-=1
gMonitor=${gDisplayInf[$selection]}
;;
*)
echo "Enter error, bye"
exit 1
;;
esac esac
else else
gMonitor=${gDisplayInf} gMonitor=${gDisplayInf}
@ -235,7 +228,8 @@ function get_edid()
get_edid get_edid
rootPath="../../../../../.." rootPath="../.."
restorePath="${rootPath}/Library/Displays/Contents/Resources/Overrides"
echo "" echo ""
echo "(1) Disable HIDPI on this monitor" echo "(1) Disable HIDPI on this monitor"
@ -244,13 +238,20 @@ echo ""
read -p "Enter your choice [1~2]: " input read -p "Enter your choice [1~2]: " input
case ${input} in case ${input} in
1) ${rootPath}/usr/libexec/plistbuddy -c "Delete :vendors:${Vid}:products:${Pid}" ../Icons.plist 1)
if [[ -f "${restorePath}/Icons.plist" ]]; then
${rootPath}/usr/libexec/plistbuddy -c "Delete :vendors:${Vid}:products:${Pid}" "${restorePath}/Icons.plist"
fi
if [[ -d "${restorePath}/DisplayVendorID-${Vid}" ]]; then
rm -rf "${restorePath}/DisplayVendorID-${Vid}"
fi
;; ;;
2) rm -rf ${rootPath}/Library/Displays 2)
rm -rf "${restorePath}"
;; ;;
*) *)
echo "Enter error, bye"; echo "Enter error, bye"
exit 1 exit 1
;; ;;
esac esac
@ -258,15 +259,13 @@ esac
echo "HIDPI Disabled" echo "HIDPI Disabled"
CCC CCC
sudo mv ${currentDir}/tmp/disable ${targetDir}/HIDPI/ chmod +x "$(cd && pwd)/.hidpi-disable"
sudo chmod +x ${targetDir}/HIDPI/disable
} }
# choose_icon # choose_icon
function choose_icon() function choose_icon() {
{
#
rm -rf ${currentDir}/tmp/ rm -rf ${currentDir}/tmp/
mkdir -p ${currentDir}/tmp/ mkdir -p ${currentDir}/tmp/
mkdir -p ${currentDir}/tmp/DisplayVendorID-${Vid} mkdir -p ${currentDir}/tmp/DisplayVendorID-${Vid}
@ -284,26 +283,31 @@ function choose_icon()
echo "(5) Pro Display XDR" echo "(5) Pro Display XDR"
echo "(6) ${langNotChange}" echo "(6) ${langNotChange}"
echo "" echo ""
#
read -p "${langInputChoice} [1~6]: " logo read -p "${langInputChoice} [1~6]: " logo
case ${logo} in case ${logo} in
1) Picon=${imacicon} 1)
Picon=${imacicon}
RP=("33" "68" "160" "90") RP=("33" "68" "160" "90")
curl -fsSL "${downloadHost}/displayIcons/iMac.icns" -o ${currentDir}/tmp/DisplayVendorID-${Vid}/DisplayProductID-${Pid}.icns curl -fsSL "${downloadHost}/displayIcons/iMac.icns" -o ${currentDir}/tmp/DisplayVendorID-${Vid}/DisplayProductID-${Pid}.icns
;; ;;
2) Picon=${mbicon} 2)
Picon=${mbicon}
RP=("52" "66" "122" "76") RP=("52" "66" "122" "76")
curl -fsSL "${downloadHost}/displayIcons/MacBook.icns" -o ${currentDir}/tmp/DisplayVendorID-${Vid}/DisplayProductID-${Pid}.icns curl -fsSL "${downloadHost}/displayIcons/MacBook.icns" -o ${currentDir}/tmp/DisplayVendorID-${Vid}/DisplayProductID-${Pid}.icns
;; ;;
3) Picon=${mbpicon} 3)
Picon=${mbpicon}
RP=("40" "62" "147" "92") RP=("40" "62" "147" "92")
curl -fsSL "${downloadHost}/displayIcons/MacBookPro.icns" -o ${currentDir}/tmp/DisplayVendorID-${Vid}/DisplayProductID-${Pid}.icns curl -fsSL "${downloadHost}/displayIcons/MacBookPro.icns" -o ${currentDir}/tmp/DisplayVendorID-${Vid}/DisplayProductID-${Pid}.icns
;; ;;
4) Picon=${lgicon} 4)
Picon=${lgicon}
RP=("11" "47" "202" "114") RP=("11" "47" "202" "114")
cp ${sysDisplayDir}/DisplayVendorID-1e6d/DisplayProductID-5b11.icns ${currentDir}/tmp/DisplayVendorID-${Vid}/DisplayProductID-${Pid}.icns cp ${sysDisplayDir}/DisplayVendorID-1e6d/DisplayProductID-5b11.icns ${currentDir}/tmp/DisplayVendorID-${Vid}/DisplayProductID-${Pid}.icns
;; ;;
5) Picon=${proxdricon} 5)
Picon=${proxdricon}
RP=("5" "45" "216" "121") RP=("5" "45" "216" "121")
curl -fsSL "${downloadHost}/displayIcons/ProDisplayXDR.icns" -o ${currentDir}/tmp/DisplayVendorID-${Vid}/DisplayProductID-${Pid}.icns curl -fsSL "${downloadHost}/displayIcons/ProDisplayXDR.icns" -o ${currentDir}/tmp/DisplayVendorID-${Vid}/DisplayProductID-${Pid}.icns
if [[ ! -f ${targetDir}/DisplayVendorID-610/DisplayProductID-ae2f_Landscape.tiff ]]; then if [[ ! -f ${targetDir}/DisplayVendorID-610/DisplayProductID-ae2f_Landscape.tiff ]]; then
@ -311,38 +315,37 @@ case ${logo} in
Picon=${Overrides}"\/DisplayVendorID\-${Vid}\/DisplayProductID\-${Pid}\.tiff" Picon=${Overrides}"\/DisplayVendorID\-${Vid}\/DisplayProductID\-${Pid}\.tiff"
fi fi
;; ;;
6) rm -rf ${currentDir}/tmp/Icons.plist 6)
rm -rf ${currentDir}/tmp/Icons.plist
;; ;;
*) *)
echo "${langEnterError}"; echo "${langEnterError}"
exit 1 exit 1
;; ;;
esac esac
if [[ ${Picon} ]]; then if [[ ${Picon} ]]; then
DICON=${Overrides}"\/DisplayVendorID\-${Vid}\/DisplayProductID\-${Pid}\.icns" DICON=${Overrides}"\/DisplayVendorID\-${Vid}\/DisplayProductID\-${Pid}\.icns"
/usr/bin/sed -i "" "s/VID/${Vid}/g" ${currentDir}/tmp/Icons.plist /usr/bin/sed -i "" "s/VID/${Vid}/g" ${currentDir}/tmp/Icons.plist
/usr/bin/sed -i "" "s/PID/${Pid}/g" ${currentDir}/tmp/Icons.plist /usr/bin/sed -i "" "s/PID/${Pid}/g" ${currentDir}/tmp/Icons.plist
/usr/bin/sed -i "" "s/RPX/${RP[0]}/g" ${currentDir}/tmp/Icons.plist /usr/bin/sed -i "" "s/RPX/${RP[0]}/g" ${currentDir}/tmp/Icons.plist
/usr/bin/sed -i "" "s/RPY/${RP[1]}/g" ${currentDir}/tmp/Icons.plist /usr/bin/sed -i "" "s/RPY/${RP[1]}/g" ${currentDir}/tmp/Icons.plist
/usr/bin/sed -i "" "s/RPW/${RP[2]}/g" ${currentDir}/tmp/Icons.plist /usr/bin/sed -i "" "s/RPW/${RP[2]}/g" ${currentDir}/tmp/Icons.plist
/usr/bin/sed -i "" "s/RPH/${RP[3]}/g" ${currentDir}/tmp/Icons.plist /usr/bin/sed -i "" "s/RPH/${RP[3]}/g" ${currentDir}/tmp/Icons.plist
/usr/bin/sed -i "" "s/PICON/${Picon}/g" ${currentDir}/tmp/Icons.plist /usr/bin/sed -i "" "s/PICON/${Picon}/g" ${currentDir}/tmp/Icons.plist
/usr/bin/sed -i "" "s/DICON/${DICON}/g" ${currentDir}/tmp/Icons.plist /usr/bin/sed -i "" "s/DICON/${DICON}/g" ${currentDir}/tmp/Icons.plist
fi fi
} }
# main # main
function main() function main() {
{
sudo mkdir -p ${currentDir}/tmp/DisplayVendorID-${Vid} sudo mkdir -p ${currentDir}/tmp/DisplayVendorID-${Vid}
dpiFile=${currentDir}/tmp/DisplayVendorID-${Vid}/DisplayProductID-${Pid} dpiFile=${currentDir}/tmp/DisplayVendorID-${Vid}/DisplayProductID-${Pid}
sudo chmod -R 777 ${currentDir}/tmp/ sudo chmod -R 777 ${currentDir}/tmp/
# cat >"${dpiFile}" <<-\CCC
cat > "${dpiFile}" <<-\CCC
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0"> <plist version="1.0">
@ -357,58 +360,63 @@ cat > "${dpiFile}" <<-\CCC
<array> <array>
CCC CCC
echo "" echo ""
echo "------------------------------------------" echo "------------------------------------------"
echo "|********** "${langChooseRes}" ***********|" echo "|********** "${langChooseRes}" ***********|"
echo "------------------------------------------" echo "------------------------------------------"
echo ${langChooseResOp1} echo ${langChooseResOp1}
echo ${langChooseResOp2} echo ${langChooseResOp2}
echo ${langChooseResOp3} echo ${langChooseResOp3}
echo ${langChooseResOp4} echo ${langChooseResOp4}
echo ${langChooseResOp5} echo ${langChooseResOp5}
echo ${langChooseResOpCustom} echo ${langChooseResOpCustom}
echo "" echo ""
# read -p "${langInputChoice}: " res
read -p "${langInputChoice}: " res case ${res} in
case ${res} in 1)
1 ) create_res_1 1680x945 1440x810 1280x720 1024x576 create_res_1 1680x945 1440x810 1280x720 1024x576
create_res_2 1280x800 1280x720 960x600 960x540 640x360 create_res_2 1280x800 1280x720 960x600 960x540 640x360
create_res_3 840x472 800x450 720x405 640x360 576x324 512x288 420x234 400x225 320x180 create_res_3 840x472 800x450 720x405 640x360 576x324 512x288 420x234 400x225 320x180
create_res_4 1680x945 1440x810 1280x720 1024x576 960x540 840x472 800x450 640x360 create_res_4 1680x945 1440x810 1280x720 1024x576 960x540 840x472 800x450 640x360
;; ;;
2 ) create_res_1 1680x945 1424x802 1280x720 1024x576 2)
create_res_1 1680x945 1424x802 1280x720 1024x576
create_res_2 1280x800 1280x720 960x600 960x540 640x360 create_res_2 1280x800 1280x720 960x600 960x540 640x360
create_res_3 840x472 800x450 720x405 640x360 576x324 512x288 420x234 400x225 320x180 create_res_3 840x472 800x450 720x405 640x360 576x324 512x288 420x234 400x225 320x180
create_res_4 1680x945 1440x810 1280x720 1024x576 960x540 840x472 800x450 640x360 create_res_4 1680x945 1440x810 1280x720 1024x576 960x540 840x472 800x450 640x360
;; ;;
3 ) create_res_1 1680x1050 1440x900 1280x800 1024x640 3)
create_res_1 1680x1050 1440x900 1280x800 1024x640
create_res_2 1280x800 1280x720 960x600 960x540 640x360 create_res_2 1280x800 1280x720 960x600 960x540 640x360
create_res_3 840x472 800x450 720x405 640x360 576x324 512x288 420x234 400x225 320x180 create_res_3 840x472 800x450 720x405 640x360 576x324 512x288 420x234 400x225 320x180
create_res_4 1680x1050 1440x900 1280x800 1024x640 960x540 840x472 800x450 640x360 create_res_4 1680x1050 1440x900 1280x800 1024x640 960x540 840x472 800x450 640x360
;; ;;
4 ) create_res_1 2560x1440 2048x1152 1920x1080 1760x990 1680x945 1440x810 1360x765 1280x720 4)
create_res_1 2560x1440 2048x1152 1920x1080 1760x990 1680x945 1440x810 1360x765 1280x720
create_res_2 1360x765 1280x800 1280x720 1024x576 960x600 960x540 640x360 create_res_2 1360x765 1280x800 1280x720 1024x576 960x600 960x540 640x360
create_res_3 960x540 840x472 800x450 720x405 640x360 576x324 512x288 420x234 400x225 320x180 create_res_3 960x540 840x472 800x450 720x405 640x360 576x324 512x288 420x234 400x225 320x180
create_res_4 2048x1152 1920x1080 1680x945 1440x810 1280x720 1024x576 960x540 840x472 800x450 640x360 create_res_4 2048x1152 1920x1080 1680x945 1440x810 1280x720 1024x576 960x540 840x472 800x450 640x360
;; ;;
5 ) create_res_1 3000x2000 2880x1920 2250x1500 1920x1280 1680x1050 1440x900 1280x800 1024x640 5)
create_res_1 3000x2000 2880x1920 2250x1500 1920x1280 1680x1050 1440x900 1280x800 1024x640
create_res_2 1280x800 1280x720 960x600 960x540 640x360 create_res_2 1280x800 1280x720 960x600 960x540 640x360
create_res_3 840x472 800x450 720x405 640x360 576x324 512x288 420x234 400x225 320x180 create_res_3 840x472 800x450 720x405 640x360 576x324 512x288 420x234 400x225 320x180
create_res_4 1920x1280 1680x1050 1440x900 1280x800 1024x640 960x540 840x472 800x450 640x360 create_res_4 1920x1280 1680x1050 1440x900 1280x800 1024x640 960x540 840x472 800x450 640x360
;; ;;
6 ) custom_res 6)
custom_res
create_res_2 1360x765 1280x800 1280x720 960x600 960x540 640x360 create_res_2 1360x765 1280x800 1280x720 960x600 960x540 640x360
create_res_3 840x472 800x450 720x405 640x360 576x324 512x288 420x234 400x225 320x180 create_res_3 840x472 800x450 720x405 640x360 576x324 512x288 420x234 400x225 320x180
create_res_4 1680x945 1440x810 1280x720 1024x576 960x540 840x472 800x450 640x360 create_res_4 1680x945 1440x810 1280x720 1024x576 960x540 840x472 800x450 640x360
;; ;;
*) *)
echo "${langEnterError}"; echo "${langEnterError}"
exit 1 exit 1
;; ;;
esac esac
cat >> "${dpiFile}" <<-\FFF cat >>"${dpiFile}" <<-\FFF
</array> </array>
<key>target-default-ppmm</key> <key>target-default-ppmm</key>
<real>10.0699301</real> <real>10.0699301</real>
@ -421,8 +429,7 @@ FFF
} }
# end # end
function end() function end() {
{
sudo chown -R root:wheel ${currentDir}/tmp/ sudo chown -R root:wheel ${currentDir}/tmp/
sudo chmod -R 0755 ${currentDir}/tmp/ sudo chmod -R 0755 ${currentDir}/tmp/
sudo chmod 0644 ${currentDir}/tmp/DisplayVendorID-${Vid}/* sudo chmod 0644 ${currentDir}/tmp/DisplayVendorID-${Vid}/*
@ -434,83 +441,76 @@ function end()
} }
# custom resolution # custom resolution
function custom_res() function custom_res() {
{
echo "${langCustomRes}" echo "${langCustomRes}"
read -p ":" res read -p ":" res
create_res ${res} create_res ${res}
} }
# create resolution # create resolution
function create_res() function create_res() {
{
for res in $@; do for res in $@; do
width=$(echo ${res} | cut -d x -f 1) width=$(echo ${res} | cut -d x -f 1)
height=$(echo ${res} | cut -d x -f 2) height=$(echo ${res} | cut -d x -f 2)
hidpi=$(printf '%08x %08x' $((${width}*2)) $((${height}*2)) | xxd -r -p | base64) hidpi=$(printf '%08x %08x' $((${width} * 2)) $((${height} * 2)) | xxd -r -p | base64)
# #
cat << OOO >> ${dpiFile} cat <<OOO >>${dpiFile}
<data>${hidpi:0:11}AAAAB</data> <data>${hidpi:0:11}AAAAB</data>
<data>${hidpi:0:11}AAAABACAAAA==</data> <data>${hidpi:0:11}AAAABACAAAA==</data>
OOO OOO
done done
} }
function create_res_1() function create_res_1() {
{
for res in $@; do for res in $@; do
width=$(echo ${res} | cut -d x -f 1) width=$(echo ${res} | cut -d x -f 1)
height=$(echo ${res} | cut -d x -f 2) height=$(echo ${res} | cut -d x -f 2)
hidpi=$(printf '%08x %08x' $((${width}*2)) $((${height}*2)) | xxd -r -p | base64) hidpi=$(printf '%08x %08x' $((${width} * 2)) $((${height} * 2)) | xxd -r -p | base64)
# #
cat << OOO >> ${dpiFile} cat <<OOO >>${dpiFile}
<data>${hidpi:0:11}A</data> <data>${hidpi:0:11}A</data>
OOO OOO
done done
} }
function create_res_2() function create_res_2() {
{
for res in $@; do for res in $@; do
width=$(echo ${res} | cut -d x -f 1) width=$(echo ${res} | cut -d x -f 1)
height=$(echo ${res} | cut -d x -f 2) height=$(echo ${res} | cut -d x -f 2)
hidpi=$(printf '%08x %08x' $((${width}*2)) $((${height}*2)) | xxd -r -p | base64) hidpi=$(printf '%08x %08x' $((${width} * 2)) $((${height} * 2)) | xxd -r -p | base64)
# #
cat << OOO >> ${dpiFile} cat <<OOO >>${dpiFile}
<data>${hidpi:0:11}AAAABACAAAA==</data> <data>${hidpi:0:11}AAAABACAAAA==</data>
OOO OOO
done done
} }
function create_res_3() function create_res_3() {
{
for res in $@; do for res in $@; do
width=$(echo ${res} | cut -d x -f 1) width=$(echo ${res} | cut -d x -f 1)
height=$(echo ${res} | cut -d x -f 2) height=$(echo ${res} | cut -d x -f 2)
hidpi=$(printf '%08x %08x' $((${width}*2)) $((${height}*2)) | xxd -r -p | base64) hidpi=$(printf '%08x %08x' $((${width} * 2)) $((${height} * 2)) | xxd -r -p | base64)
# #
cat << OOO >> ${dpiFile} cat <<OOO >>${dpiFile}
<data>${hidpi:0:11}AAAAB</data> <data>${hidpi:0:11}AAAAB</data>
OOO OOO
done done
} }
function create_res_4() function create_res_4() {
{
for res in $@; do for res in $@; do
width=$(echo ${res} | cut -d x -f 1) width=$(echo ${res} | cut -d x -f 1)
height=$(echo ${res} | cut -d x -f 2) height=$(echo ${res} | cut -d x -f 2)
hidpi=$(printf '%08x %08x' $((${width}*2)) $((${height}*2)) | xxd -r -p | base64) hidpi=$(printf '%08x %08x' $((${width} * 2)) $((${height} * 2)) | xxd -r -p | base64)
# #
cat << OOO >> ${dpiFile} cat <<OOO >>${dpiFile}
<data>${hidpi:0:11}AAAAJAKAAAA==</data> <data>${hidpi:0:11}AAAAJAKAAAA==</data>
OOO OOO
done done
} }
# enable # enable
function enable_hidpi() function enable_hidpi() {
{
choose_icon choose_icon
main main
sed -i "" "/.*IODisplayEDID/d" ${dpiFile} sed -i "" "/.*IODisplayEDID/d" ${dpiFile}
@ -519,15 +519,14 @@ function enable_hidpi()
} }
# patch # patch
function enable_hidpi_with_patch() function enable_hidpi_with_patch() {
{
choose_icon choose_icon
main main
version=${EDID:38:2} version=${EDID:38:2}
basicparams=${EDID:40:2} basicparams=${EDID:40:2}
checksum=${EDID:254:2} checksum=${EDID:254:2}
newchecksum=$(printf '%x' $((0x${checksum} + 0x${version} +0x${basicparams} - 0x04 - 0x90)) | tail -c 2) newchecksum=$(printf '%x' $((0x${checksum} + 0x${version} + 0x${basicparams} - 0x04 - 0x90)) | tail -c 2)
newedid=${EDID:0:38}0490${EDID:42:6}e6${EDID:50:204}${newchecksum} newedid=${EDID:0:38}0490${EDID:42:6}e6${EDID:50:204}${newchecksum}
EDid=$(printf ${newedid} | xxd -r -p | base64) EDid=$(printf ${newedid} | xxd -r -p | base64)
@ -536,8 +535,7 @@ function enable_hidpi_with_patch()
} }
# disable # disable
function disable() function disable() {
{
echo "" echo ""
echo "${langDisableOpt1}" echo "${langDisableOpt1}"
echo "${langDisableOpt2}" echo "${langDisableOpt2}"
@ -545,13 +543,20 @@ function disable()
read -p "${langInputChoice} [1~2]: " input read -p "${langInputChoice} [1~2]: " input
case ${input} in case ${input} in
1) sudo /usr/libexec/plistbuddy -c "Delete :vendors:${Vid}:products:${Pid}" ${targetDir}/Icons.plist 1)
if [[ -f "${targetDir}/Icons.plist" ]]; then
sudo /usr/libexec/plistbuddy -c "Delete :vendors:${Vid}:products:${Pid}" "${targetDir}/Icons.plist"
fi
if [[ -d "${targetDir}/DisplayVendorID-${Vid}" ]]; then
sudo rm -rf "${targetDir}/DisplayVendorID-${Vid}"
fi
;; ;;
2) sudo rm -rf ${libDisplaysDir} 2)
sudo rm -rf "${targetDir}"
;; ;;
*) *)
echo "${langEnterError}"; echo "${langEnterError}"
exit 1 exit 1
;; ;;
esac esac
@ -560,8 +565,7 @@ function disable()
} }
# #
function start() function start() {
{
init init
echo "" echo ""
echo ${langEnableOp1} echo ${langEnableOp1}
@ -569,21 +573,24 @@ function start()
echo ${langEnableOp3} echo ${langEnableOp3}
echo "" echo ""
# #
read -p "${langInputChoice} [1~3]: " input read -p "${langInputChoice} [1~3]: " input
case ${input} in case ${input} in
1) enable_hidpi 1)
;; enable_hidpi
2) enable_hidpi_with_patch ;;
;; 2)
3) disable enable_hidpi_with_patch
;; ;;
3)
disable
;;
*) *)
echo "${langEnterError}"; echo "${langEnterError}"
exit 1 exit 1
;; ;;
esac esac
} }
start start