add new restore way

This commit is contained in:
xzhih 2019-01-24 02:53:19 +08:00
parent 4acbf8721a
commit d6ca677a4f
4 changed files with 421 additions and 246 deletions

View file

@ -20,24 +20,48 @@ macOS 的 DPI 机制和 Windows 下不一样,比如 1080p 的屏幕在 Windows
在终端输入以下命令回车即可 在终端输入以下命令回车即可
``` ```bash
$ sh -c "$(curl -fsSL https://raw.githubusercontent.com/xzhih/one-key-hidpi/master/hidpi-zh.sh)" sh -c "$(curl -fsSL https://raw.githubusercontent.com/xzhih/one-key-hidpi/master/hidpi-zh.sh)"
``` ```
![运行](./img/run-zh.jpg) ![运行](./img/run-zh.jpg)
## 恢复 ## 恢复
如果使用此脚本后,开机无法进入系统,请到恢复模式中或使用 clover `-x` 安全模式进入系统 ,使用终端删除 `/System/Library/Displays/Contents/Resources/Overrides` 下删除显示器 VendorID 对应的文件夹,并把 backup 文件夹中的备份复制出来。 ### 命令恢复
如果还能进系统,就再次运行命令选择选项 3 关闭 HIDPI。
### 恢复模式
如果使用此脚本后,开机无法进入系统,请到 macos 恢复模式中或使用 clover `-x` 安全模式进入系统,打开终端
这里有两种方式进行关闭,建议选第一种
1. 快捷恢复
```bash
ls /Volumes/
cd /Volumes/你的系统盘/System/Library/Displays/Contents/Resources/Overrides/HIDPI
./disable
```
2. 手动恢复
使用终端删除 `/System/Library/Displays/Contents/Resources/Overrides` 下删除显示器 VendorID 对应的文件夹,并把 `HIDPI/backup` 文件夹中的备份复制出来。
请使用单个显示器执行以下命令,笔记本关闭外接显示器的 HIDPI 时请关闭内置显示器
具体命令如下: 具体命令如下:
``` ```bash
$ cd /Volumes/你的系统盘/System/Library/Displays/Contents/Resources/Overrides ls /Volumes/
$ VendorID=$(ioreg -l | grep "DisplayVendorID" | awk '{print $8}') cd /Volumes/你的系统盘/System/Library/Displays/Contents/Resources/Overrides
$ Vid=$(echo "obase=16;$VendorID" | bc | tr 'A-Z' 'a-z') EDID=($(ioreg -lw0 | grep -i "IODisplayEDID" | sed -e "/[^<]*</s///" -e "s/\>//"))
$ rm -rf ./DisplayVendorID-$Vid Vid=($(echo $EDID | cut -c18-20))
$ cp -r ./backup/* ./ rm -rf ./DisplayVendorID-$Vid
cp -r ./HIDPI/backup/* ./
``` ```
## 从以下得到启发 ## 从以下得到启发

View file

@ -16,26 +16,50 @@ System Preferences
## Usage ## Usage
Run script in Terminal Run this script in Terminal
``` ```bash
$ sh -c "$(curl -fsSL https://raw.githubusercontent.com/xzhih/one-key-hidpi/master/hidpi.sh)" sh -c "$(curl -fsSL https://raw.githubusercontent.com/xzhih/one-key-hidpi/master/hidpi.sh)"
``` ```
![RUN](./img/run.jpg) ![RUN](./img/run.jpg)
## Recovery ## Recovery
If you cant boot into system, or get any another issues, you can use clover `-x ` reboot or into Recovery mode, remove your display's DisplayVendorID folder under `/System/Library/Displays/Contents/Resources/Overrides` , and move backup files ### Normal
Still running the script in the terminal, but choose option 3
### Recovery mode
If you cant boot into system, or get any another issues, you can boot into macOS Recovery mode, and use the Terminal.app
There are two ways to close it. It is recommended to choose the first one
1.
```bash
ls /Volumes/
cd /Volumes/"Your System Disk Part"/System/Library/Displays/Contents/Resources/Overrides/HIDPI
./disable
```
2.
Remove your display's DisplayVendorID folder under `/System/Library/Displays/Contents/Resources/Overrides` , and move backup files
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: In Terminal:
``` ```bash
$ cd /Volumes/"Your System Disk Part"/System/Library/Displays/Contents/Resources/Overrides ls /Volumes/
$ VendorID=$(ioreg -l | grep "DisplayVendorID" | awk '{print $8}') cd /Volumes/"Your System Disk Part"/System/Library/Displays/Contents/Resources/Overrides
$ Vid=$(echo "obase=16;$VendorID" | bc | tr 'A-Z' 'a-z') EDID=($(ioreg -lw0 | grep -i "IODisplayEDID" | sed -e "/[^<]*</s///" -e "s/\>//"))
$ rm -rf ./DisplayVendorID-$Vid Vid=($(echo $EDID | cut -c18-20))
$ cp -r ./backup/* ./ rm -rf ./DisplayVendorID-$Vid
cp -r ./HIDPI/backup/* ./
``` ```
## Inspired ## Inspired

View file

@ -1,19 +1,5 @@
#!/bin/sh #!/bin/sh
#
# Output styling.
#
BOLD="\033[1m"
RED="\033[1;31m"
GREEN="\033[1;32m"
BLUE="\033[1;34m"
OFF="\033[m"
STYLE_UNDERLINED="\e[4m"
#
function _toLowerCase()
{
echo "`echo $1 | tr '[:upper:]' '[:lower:]'`"
}
#
function get_edid() function get_edid()
{ {
local index=0 local index=0
@ -21,79 +7,61 @@ function get_edid()
gDisplayInf=($(ioreg -lw0 | grep -i "IODisplayEDID" | sed -e "/[^<]*</s///" -e "s/\>//")) gDisplayInf=($(ioreg -lw0 | grep -i "IODisplayEDID" | sed -e "/[^<]*</s///" -e "s/\>//"))
if [[ "${#gDisplayInf[@]}" -ge 2 ]]; if [[ "${#gDisplayInf[@]}" -ge 2 ]]; then
then
#
# Multi monitors detected. Choose target monitor. # Multi monitors detected. Choose target monitor.
# echo ''
echo ' 显示器列表 ' echo ' 显示器列表 '
echo '------------------------------------' echo '------------------------------------'
echo ' 序号 | VendorID | ProductID ' echo ' 序号 | VendorID | ProductID '
echo '------------------------------------' echo '------------------------------------'
# Show monitors.
for display in "${gDisplayInf[@]}" for display in "${gDisplayInf[@]}"
do do
let index++ let index++
# printf " %d | ${display:16:4} | ${display:20:4}\n" $index
# Show monitors.
#
printf " %d | ${display:16:4} | ${display:20:4}\n" $index
done done
#
# Close the table
#
echo '------------------------------------' echo '------------------------------------'
#
# Let user make a selection. # Let user make a selection.
#
printf '请选择需要开启HiDPI的显示器序号'
if [[ "${#gDisplayInf[@]}" == 2 ]]; then
printf "[$RED${STYLE_UNDERLINED}E${OFF}xit/1/2]"
else
printf "[$RED${STYLE_UNDERLINED}E${OFF}xit/1-${index}]"
fi
read -p ": " selection
case "$(_toLowerCase $selection)" in
e|exit ) echo "Abort."
exit -0
;;
[[:digit:]]* ) # read -p "选择显示器序号: " selection
# Lower selection (arrays start at zero). case $selection in
# [[:digit:]]* )
if ((selection < 1 || selection > index)); then # Lower selection (arrays start at zero).
echo "Enter error, bye"; if ((selection < 1 || selection > index)); then
exit 0 echo "输入错误,拜拜";
fi exit 0
let selection-=1 fi
gMonitor=${gDisplayInf[$selection]} let selection-=1
;; gMonitor=${gDisplayInf[$selection]}
;;
* ) if [[ "${#gDisplayInf[@]}" == 2 ]]; then * )
echo 'Invalid menu action, enter 1 or 2' echo "输入错误,拜拜";
else exit 0
echo "Invalid menu action, enter valid number among 1, ..., ${index}" ;;
fi
;;
esac esac
else else
gMonitor=${gDisplayInf} gMonitor=${gDisplayInf}
fi fi
#
#
if [[ ${gMonitor:16:1} == 0 ]]; then if [[ ${gMonitor:16:1} == 0 ]]; then
# get rid of the prefix 0 # get rid of the prefix 0
gDisplayVendorID_RAW=${gMonitor:17:3} gDisplayVendorID_RAW=${gMonitor:17:3}
else else
gDisplayVendorID_RAW=${gMonitor:16:4} gDisplayVendorID_RAW=${gMonitor:16:4}
fi fi
# convert from hex to dec # convert from hex to dec
gDisplayVendorID=$((0x$gDisplayVendorID_RAW)) gDisplayVendorID=$((0x$gDisplayVendorID_RAW))
gDisplayProductID_RAW=${gMonitor:20:4} gDisplayProductID_RAW=${gMonitor:20:4}
#
# Exchange two bytes # Exchange two bytes
#
# Fix an issue that will cause wrong name of DisplayProductID # Fix an issue that will cause wrong name of DisplayProductID
#
if [[ ${gDisplayProductID_RAW:2:1} == 0 ]]; then if [[ ${gDisplayProductID_RAW:2:1} == 0 ]]; then
# get rid of the prefix 0 # get rid of the prefix 0
gDisplayProduct_pr=${gDisplayProductID_RAW:3:1} gDisplayProduct_pr=${gDisplayProductID_RAW:3:1}
@ -104,22 +72,21 @@ function get_edid()
gDisplayProductID_reverse="${gDisplayProduct_pr}${gDisplayProduct_st}" gDisplayProductID_reverse="${gDisplayProduct_pr}${gDisplayProduct_st}"
gDisplayProductID=$((0x$gDisplayProduct_pr$gDisplayProduct_st)) gDisplayProductID=$((0x$gDisplayProduct_pr$gDisplayProduct_st))
EDID=$gMonitor EDID=$gMonitor
VendorID=$gDisplayVendorID VendorID=$gDisplayVendorID
ProductID=$gDisplayProductID ProductID=$gDisplayProductID
# echo $VendorID Vid=$gDisplayVendorID_RAW
# echo $ProductID Pid=$gDisplayProductID_reverse
# echo $Vid
# echo $Pid
# echo $EDID # echo $EDID
} }
#
#
# 初始化 # 初始化
function init() function init()
{ {
# #
cat << EEF cat << EEF
_ _ _____ _____ _____ _____ _ _ _____ _____ _____ _____
| | | | |_ _| | __ \ | __ \ |_ _| | | | | |_ _| | __ \ | __ \ |_ _|
| |__| | | | | | | | | |__) | | | | |__| | | | | | | | | |__) | | |
@ -128,15 +95,10 @@ cat << EEF
|_| |_| |_____| |_____/ |_| |_____| |_| |_| |_____| |_____/ |_| |_____|
============================================ ============================================
EEF EEF
# #
get_edid get_edid
Vid=$(echo "obase=16;$VendorID" | bc | tr 'A-Z' 'a-z')
Pid=$(echo "obase=16;$ProductID" | bc | tr 'A-Z' 'a-z')
edID=$(echo $EDID | sed 's/../b5/21') edID=$(echo $EDID | sed 's/../b5/21')
EDid=$(printf $edID | xxd -r -p | base64) EDid=$(printf $edID | xxd -r -p | base64)
@ -150,14 +112,111 @@ EEF
mbicon=${Overrides}"DisplayVendorID-610\/DisplayProductID-a028-9d9da0.tiff" mbicon=${Overrides}"DisplayVendorID-610\/DisplayProductID-a028-9d9da0.tiff"
lgicon=${Overrides}"DisplayVendorID-1e6d\/DisplayProductID-5b11.tiff" lgicon=${Overrides}"DisplayVendorID-1e6d\/DisplayProductID-5b11.tiff"
if [[ ! -d $thatDir/backup ]]; then if [[ ! -f $thatDir/HIDPI/disable ]]; then
echo "正在备份" echo "正在备份"
sudo mkdir -p $thatDir/backup sudo mkdir -p $thatDir/HIDPI/backup
sudo cp $thatDir/Icons.plist $thatDir/backup/ sudo cp $thatDir/Icons.plist $thatDir/HIDPI/backup/
if [[ -d $thatDir/DisplayVendorID-$Vid ]]; then if [[ -d $thatDir/DisplayVendorID-$Vid ]]; then
sudo cp -r $thatDir/DisplayVendorID-$Vid $thatDir/backup/ sudo cp -r $thatDir/DisplayVendorID-$Vid $thatDir/HIDPI/backup/
fi fi
fi fi
if [[ ! -f $thatDir/HIDPI/disable ]]; then
generate_restore_cmd
fi
}
#
function generate_restore_cmd()
{
#
rm -rf $thisDir/tmp/
mkdir -p $thisDir/tmp/
cat > "$thisDir/tmp/disable" <<-\CCC
function get_edid()
{
local index=0
local selection=0
gDisplayInf=($(ioreg -lw0 | grep -i "IODisplayEDID" | sed -e "/[^<]*</s///" -e "s/\>//"))
if [[ "${#gDisplayInf[@]}" -ge 2 ]]; then
echo ' Monitors '
echo '------------------------------------'
echo ' Index | VendorID | ProductID '
echo '------------------------------------'
for display in "${gDisplayInf[@]}"
do
let index++
printf " %d | ${display:16:4} | ${display:20:4}\n" $index
done
echo '------------------------------------'
read -p "Choose the display: " selection
case $selection in
[[:digit:]]* )
if ((selection < 1 || selection > index)); then
echo "Enter error, bye";
exit 0
fi
let selection-=1
gMonitor=${gDisplayInf[$selection]}
;;
* )
echo "Enter error, bye";
exit 0
;;
esac
else
gMonitor=${gDisplayInf}
fi
if [[ ${gMonitor:16:1} == 0 ]]; then
gDisplayVendorID_RAW=${gMonitor:17:3}
else
gDisplayVendorID_RAW=${gMonitor:16:4}
fi
gDisplayVendorID=$((0x$gDisplayVendorID_RAW))
gDisplayProductID_RAW=${gMonitor:20:4}
if [[ ${gDisplayProductID_RAW:2:1} == 0 ]]; then
gDisplayProduct_pr=${gDisplayProductID_RAW:3:1}
else
gDisplayProduct_pr=${gDisplayProductID_RAW:2:2}
fi
gDisplayProduct_st=${gDisplayProductID_RAW:0:2}
gDisplayProductID_reverse="${gDisplayProduct_pr}${gDisplayProduct_st}"
gDisplayProductID=$((0x$gDisplayProduct_pr$gDisplayProduct_st))
EDID=$gMonitor
Vid=$gDisplayVendorID_RAW
Pid=$gDisplayProductID_reverse
# echo $Vid
# echo $Pid
# echo $EDID
}
get_edid
if [[ -d ../DisplayVendorID-$Vid ]]; then
rm -rf ../DisplayVendorID-$Vid
fi
rm -rf ../Icons.plist
cp -r ./backup/* ../
rm -rf ./disable
echo "HIDPI Disabled"
CCC
sudo mv $thisDir/tmp/disable $thatDir/HIDPI/
sudo chmod +x $thatDir/HIDPI/disable
} }
# 选择ICON # 选择ICON
@ -185,25 +244,25 @@ EOF
read -p "输入你的选择[1~5]: " logo read -p "输入你的选择[1~5]: " logo
case $logo in case $logo in
1) Picon=$imacicon 1) Picon=$imacicon
RP=("33" "68" "160" "90") RP=("33" "68" "160" "90")
;; ;;
2) Picon=$mbicon 2) Picon=$mbicon
RP=("52" "66" "122" "76") RP=("52" "66" "122" "76")
;; ;;
3) Picon=$mbpicon 3) Picon=$mbpicon
RP=("40" "62" "147" "92") RP=("40" "62" "147" "92")
;; ;;
4) Picon=$lgicon 4) Picon=$lgicon
RP=("11" "47" "202" "114") RP=("11" "47" "202" "114")
DICON=${Overrides}"DisplayVendorID-1e6d\/DisplayProductID-5b11.icns" DICON=${Overrides}"DisplayVendorID-1e6d\/DisplayProductID-5b11.icns"
;; ;;
5) rm -rf $thisDir/tmp/Icons.plist 5) rm -rf $thisDir/tmp/Icons.plist
;; ;;
*) *)
echo "输入错误,拜拜"; echo "输入错误,拜拜";
exit 0 exit 0
;; ;;
esac esac
if [[ $Picon ]]; then if [[ $Picon ]]; then
@ -254,19 +313,19 @@ EOF
read -p "选择你想要的配置: " res read -p "选择你想要的配置: " res
case $res in case $res in
1 ) create_res_1 1920x1080 1680x945 1440x810 1280x720 1024x576 1 ) create_res_1 1680x944 1600x900 1440x810 1280x720 1024x576
;; ;;
2 ) create_res_1 2048x1152 1920x1080 1680x945 1440x810 1280x720 2 ) create_res_1 2048x1152 1920x1080 1680x944 1440x810 1280x720
create_res_2 1024x576 create_res_2 1024x576
create_res_3 960x540 create_res_3 960x540
create_res_4 2048x1152 create_res_4 2048x1152 1920x1080
;; ;;
3 ) custom_res;; 3 ) custom_res;;
esac esac
create_res_2 1280x720 960x540 640x360 create_res_2 1280x800 1280x720 960x600 960x540 640x360
create_res_3 840x472 720x405 640x360 576x324 512x288 420x234 400x225 320x180 create_res_3 840x472 800x450 720x405 640x360 576x324 512x288 420x234 400x225 320x180
create_res_4 1920x1080 1680x945 1440x810 1280x720 1024x576 960x540 640x360 create_res_4 1680x944 1600x900 1440x810 1280x720 1024x576 960x540 840x472 800x450 640x360
cat >> "$dpiFile" <<-\FFF cat >> "$dpiFile" <<-\FFF
</array> </array>
@ -287,7 +346,6 @@ function end()
sudo rm -rf $thisDir/tmp sudo rm -rf $thisDir/tmp
echo "开启成功,重启生效" echo "开启成功,重启生效"
echo "首次重启开机logo会变得巨大之后就不会了" echo "首次重启开机logo会变得巨大之后就不会了"
# say "妖怪,哪里跑"
} }
#自定义分辨率 #自定义分辨率
@ -387,13 +445,17 @@ function enable_hidpi_with_patch()
# 关 # 关
function disable() function disable()
{ {
sudo rm -rf $thatDir/DisplayVendorID-$Vid if [[ -d $thatDir/DisplayVendorID-$Vid ]]; then
sudo rm -rf $thatDir/DisplayVendorID-$Vid
fi
sudo rm -rf $thatDir/Icons.plist sudo rm -rf $thatDir/Icons.plist
sudo cp -r $thatDir/backup/* $thatDir/ sudo cp -r $thatDir/HIDPI/backup/* $thatDir/
sudo rm -rf $thatDir/backup sudo rm -rf $thatDir/HIDPI/disable
echo "已关闭,重启生效" echo "已关闭,重启生效"
} }
#
function start() function start()
{ {
init init
@ -409,16 +471,16 @@ EOF
read -p "输入你的选择[1~3]: " input read -p "输入你的选择[1~3]: " input
case $input in case $input in
1) enable_hidpi 1) enable_hidpi
;; ;;
2) enable_hidpi_with_patch 2) enable_hidpi_with_patch
;; ;;
3) disable 3) disable
;; ;;
*) *)
echo "输入错误,拜拜"; echo "输入错误,拜拜";
exit 0 exit 0
;; ;;
esac esac
} }

277
hidpi.sh
View file

@ -1,19 +1,5 @@
#!/bin/sh #!/bin/sh
#
# Output styling.
#
BOLD="\033[1m"
RED="\033[1;31m"
GREEN="\033[1;32m"
BLUE="\033[1;34m"
OFF="\033[m"
STYLE_UNDERLINED="\e[4m"
#
function _toLowerCase()
{
echo "`echo $1 | tr '[:upper:]' '[:lower:]'`"
}
#
function get_edid() function get_edid()
{ {
local index=0 local index=0
@ -21,79 +7,61 @@ function get_edid()
gDisplayInf=($(ioreg -lw0 | grep -i "IODisplayEDID" | sed -e "/[^<]*</s///" -e "s/\>//")) gDisplayInf=($(ioreg -lw0 | grep -i "IODisplayEDID" | sed -e "/[^<]*</s///" -e "s/\>//"))
if [[ "${#gDisplayInf[@]}" -ge 2 ]]; if [[ "${#gDisplayInf[@]}" -ge 2 ]]; then
then
#
# Multi monitors detected. Choose target monitor. # Multi monitors detected. Choose target monitor.
# echo ''
echo ' Table of monitors ' echo ' Monitors '
echo '------------------------------------' echo '------------------------------------'
echo ' Index | VendorID | ProductID ' echo ' Index | VendorID | ProductID '
echo '------------------------------------' echo '------------------------------------'
# Show monitors.
for display in "${gDisplayInf[@]}" for display in "${gDisplayInf[@]}"
do do
let index++ let index++
# printf " %d | ${display:16:4} | ${display:20:4}\n" $index
# Show monitors.
#
printf " %d | ${display:16:4} | ${display:20:4}\n" $index
done done
#
# Close the table
#
echo '------------------------------------' echo '------------------------------------'
#
# Let user make a selection. # Let user make a selection.
#
printf 'Choose the display to enable HiDPI'
if [[ "${#gDisplayInf[@]}" == 2 ]]; then
printf "[$RED${STYLE_UNDERLINED}E${OFF}xit/1/2]"
else
printf "[$RED${STYLE_UNDERLINED}E${OFF}xit/1-${index}]"
fi
read -p ": " selection
case "$(_toLowerCase $selection)" in
e|exit ) echo "Abort."
exit -0
;;
[[:digit:]]* ) # read -p "Choose the display: " selection
# Lower selection (arrays start at zero). case $selection in
# [[:digit:]]* )
if ((selection < 1 || selection > index)); then # Lower selection (arrays start at zero).
echo "Enter error, bye"; if ((selection < 1 || selection > index)); then
exit 0 echo "Enter error, bye";
fi exit 0
let selection-=1 fi
gMonitor=${gDisplayInf[$selection]} let selection-=1
;; gMonitor=${gDisplayInf[$selection]}
;;
* ) if [[ "${#gDisplayInf[@]}" == 2 ]]; then * )
echo 'Invalid menu action, enter 1 or 2' echo "Enter error, bye";
else exit 0
echo "Invalid menu action, enter valid number among 1, ..., ${index}" ;;
fi
;;
esac esac
else else
gMonitor=${gDisplayInf} gMonitor=${gDisplayInf}
fi fi
#
#
if [[ ${gMonitor:16:1} == 0 ]]; then if [[ ${gMonitor:16:1} == 0 ]]; then
# get rid of the prefix 0 # get rid of the prefix 0
gDisplayVendorID_RAW=${gMonitor:17:3} gDisplayVendorID_RAW=${gMonitor:17:3}
else else
gDisplayVendorID_RAW=${gMonitor:16:4} gDisplayVendorID_RAW=${gMonitor:16:4}
fi fi
# convert from hex to dec # convert from hex to dec
gDisplayVendorID=$((0x$gDisplayVendorID_RAW)) gDisplayVendorID=$((0x$gDisplayVendorID_RAW))
gDisplayProductID_RAW=${gMonitor:20:4} gDisplayProductID_RAW=${gMonitor:20:4}
#
# Exchange two bytes # Exchange two bytes
#
# Fix an issue that will cause wrong name of DisplayProductID # Fix an issue that will cause wrong name of DisplayProductID
#
if [[ ${gDisplayProductID_RAW:2:1} == 0 ]]; then if [[ ${gDisplayProductID_RAW:2:1} == 0 ]]; then
# get rid of the prefix 0 # get rid of the prefix 0
gDisplayProduct_pr=${gDisplayProductID_RAW:3:1} gDisplayProduct_pr=${gDisplayProductID_RAW:3:1}
@ -104,22 +72,21 @@ function get_edid()
gDisplayProductID_reverse="${gDisplayProduct_pr}${gDisplayProduct_st}" gDisplayProductID_reverse="${gDisplayProduct_pr}${gDisplayProduct_st}"
gDisplayProductID=$((0x$gDisplayProduct_pr$gDisplayProduct_st)) gDisplayProductID=$((0x$gDisplayProduct_pr$gDisplayProduct_st))
EDID=$gMonitor EDID=$gMonitor
VendorID=$gDisplayVendorID VendorID=$gDisplayVendorID
ProductID=$gDisplayProductID ProductID=$gDisplayProductID
# echo $VendorID Vid=$gDisplayVendorID_RAW
# echo $ProductID Pid=$gDisplayProductID_reverse
# echo $Vid
# echo $Pid
# echo $EDID # echo $EDID
} }
#
#
# init # init
function init() function init()
{ {
# #
cat << EEF cat << EEF
_ _ _____ _____ _____ _____ _ _ _____ _____ _____ _____
| | | | |_ _| | __ \ | __ \ |_ _| | | | | |_ _| | __ \ | __ \ |_ _|
| |__| | | | | | | | | |__) | | | | |__| | | | | | | | | |__) | | |
@ -128,15 +95,10 @@ cat << EEF
|_| |_| |_____| |_____/ |_| |_____| |_| |_| |_____| |_____/ |_| |_____|
============================================ ============================================
EEF EEF
# #
get_edid get_edid
Vid=$(echo "obase=16;$VendorID" | bc | tr 'A-Z' 'a-z')
Pid=$(echo "obase=16;$ProductID" | bc | tr 'A-Z' 'a-z')
edID=$(echo $EDID | sed 's/../b5/21') edID=$(echo $EDID | sed 's/../b5/21')
EDid=$(echo $edID | xxd -r -p | base64) EDid=$(echo $edID | xxd -r -p | base64)
@ -150,14 +112,111 @@ EEF
mbicon=${Overrides}"DisplayVendorID-610\/DisplayProductID-a028-9d9da0.tiff" mbicon=${Overrides}"DisplayVendorID-610\/DisplayProductID-a028-9d9da0.tiff"
lgicon=${Overrides}"DisplayVendorID-1e6d\/DisplayProductID-5b11.tiff" lgicon=${Overrides}"DisplayVendorID-1e6d\/DisplayProductID-5b11.tiff"
if [[ ! -d $thatDir/backup ]]; then if [[ ! -d $thatDir/HIDPI/backup ]]; then
echo "Backing up..." echo "Backing up..."
sudo mkdir -p $thatDir/backup sudo mkdir -p $thatDir/HIDPI/backup
sudo cp $thatDir/Icons.plist $thatDir/backup/ sudo cp $thatDir/Icons.plist $thatDir/HIDPI/backup/
if [[ -d $thatDir/DisplayVendorID-$Vid ]]; then if [[ -d $thatDir/DisplayVendorID-$Vid ]]; then
sudo cp -r $thatDir/DisplayVendorID-$Vid $thatDir/backup/ sudo cp -r $thatDir/DisplayVendorID-$Vid $thatDir/HIDPI/backup/
fi fi
fi fi
if [[ ! -f $thatDir/HIDPI/disable ]]; then
generate_restore_cmd
fi
}
#
function generate_restore_cmd()
{
#
rm -rf $thisDir/tmp/
mkdir -p $thisDir/tmp/
cat > "$thisDir/tmp/disable" <<-\CCC
function get_edid()
{
local index=0
local selection=0
gDisplayInf=($(ioreg -lw0 | grep -i "IODisplayEDID" | sed -e "/[^<]*</s///" -e "s/\>//"))
if [[ "${#gDisplayInf[@]}" -ge 2 ]]; then
echo ' Monitors '
echo '------------------------------------'
echo ' Index | VendorID | ProductID '
echo '------------------------------------'
for display in "${gDisplayInf[@]}"
do
let index++
printf " %d | ${display:16:4} | ${display:20:4}\n" $index
done
echo '------------------------------------'
read -p "Choose the display: " selection
case $selection in
[[:digit:]]* )
if ((selection < 1 || selection > index)); then
echo "Enter error, bye";
exit 0
fi
let selection-=1
gMonitor=${gDisplayInf[$selection]}
;;
* )
echo "Enter error, bye";
exit 0
;;
esac
else
gMonitor=${gDisplayInf}
fi
if [[ ${gMonitor:16:1} == 0 ]]; then
gDisplayVendorID_RAW=${gMonitor:17:3}
else
gDisplayVendorID_RAW=${gMonitor:16:4}
fi
gDisplayVendorID=$((0x$gDisplayVendorID_RAW))
gDisplayProductID_RAW=${gMonitor:20:4}
if [[ ${gDisplayProductID_RAW:2:1} == 0 ]]; then
gDisplayProduct_pr=${gDisplayProductID_RAW:3:1}
else
gDisplayProduct_pr=${gDisplayProductID_RAW:2:2}
fi
gDisplayProduct_st=${gDisplayProductID_RAW:0:2}
gDisplayProductID_reverse="${gDisplayProduct_pr}${gDisplayProduct_st}"
gDisplayProductID=$((0x$gDisplayProduct_pr$gDisplayProduct_st))
EDID=$gMonitor
Vid=$gDisplayVendorID_RAW
Pid=$gDisplayProductID_reverse
# echo $Vid
# echo $Pid
# echo $EDID
}
get_edid
if [[ -d ../DisplayVendorID-$Vid ]]; then
rm -rf ../DisplayVendorID-$Vid
fi
rm -rf ../Icons.plist
cp -r ./backup/* ../
rm -rf ./disable
echo "HIDPI Disabled"
CCC
sudo mv $thisDir/tmp/disable $thatDir/HIDPI/
sudo chmod +x $thatDir/HIDPI/disable
} }
# choose_icon # choose_icon
@ -185,21 +244,23 @@ EOF
read -p "Enter your choice [1~5]: " logo read -p "Enter your choice [1~5]: " logo
case $logo in case $logo in
1) Picon=$imacicon 1) Picon=$imacicon
RP=("33" "68" "160" "90") RP=("33" "68" "160" "90")
;; ;;
2) Picon=$mbicon 2) Picon=$mbicon
RP=("52" "66" "122" "76") RP=("52" "66" "122" "76")
;; ;;
3) Picon=$mbpicon 3) Picon=$mbpicon
RP=("40" "62" "147" "92") RP=("40" "62" "147" "92")
;; ;;
4) Picon=$lgicon 4) Picon=$lgicon
RP=("11" "47" "202" "114") RP=("11" "47" "202" "114")
DICON=${Overrides}"DisplayVendorID-1e6d\/DisplayProductID-5b11.icns" DICON=${Overrides}"DisplayVendorID-1e6d\/DisplayProductID-5b11.icns"
;; ;;
5) rm -rf $thisDir/tmp/Icons.plist 5) rm -rf $thisDir/tmp/Icons.plist
;; ;;
*) echo "Enter error, bye"; *)
echo "Enter error, bye";
exit 0 exit 0
;; ;;
esac esac
@ -252,19 +313,19 @@ EOF
read -p "Enter your choice: " res read -p "Enter your choice: " res
case $res in case $res in
1 ) create_res_1 1920x1080 1680x945 1440x810 1280x720 1024x576 1 ) create_res_1 1680x944 1600x900 1440x810 1280x720 1024x576
;; ;;
2 ) create_res_1 2048x1152 1920x1080 1680x945 1440x810 1280x720 2 ) create_res_1 2048x1152 1920x1080 1680x944 1440x810 1280x720
create_res_2 1024x576 create_res_2 1024x576
create_res_3 960x540 create_res_3 960x540
create_res_4 2048x1152 create_res_4 2048x1152 1920x1080
;; ;;
3 ) custom_res;; 3 ) custom_res;;
esac esac
create_res_2 1280x720 960x540 640x360 create_res_2 1280x800 1280x720 960x600 960x540 640x360
create_res_3 840x472 720x405 640x360 576x324 512x288 420x234 400x225 320x180 create_res_3 840x472 800x450 720x405 640x360 576x324 512x288 420x234 400x225 320x180
create_res_4 1920x1080 1680x945 1440x810 1280x720 1024x576 960x540 640x360 create_res_4 1680x944 1600x900 1440x810 1280x720 1024x576 960x540 840x472 800x450 640x360
cat >> "$dpiFile" <<-\FFF cat >> "$dpiFile" <<-\FFF
</array> </array>
@ -285,7 +346,6 @@ function end()
sudo rm -rf $thisDir/tmp sudo rm -rf $thisDir/tmp
echo "Enabled, please reboot." echo "Enabled, please reboot."
echo "Rebooting the logo for the first time will become huge, then it will not be." echo "Rebooting the logo for the first time will become huge, then it will not be."
say "Good"
} }
# custom resolution # custom resolution
@ -385,13 +445,17 @@ function enable_hidpi_with_patch()
# disable # disable
function disable() function disable()
{ {
sudo rm -rf $thatDir/DisplayVendorID-$Vid if [[ -d $thatDir/DisplayVendorID-$Vid ]]; then
sudo rm -rf $thatDir/DisplayVendorID-$Vid
fi
sudo rm -rf $thatDir/Icons.plist sudo rm -rf $thatDir/Icons.plist
sudo cp -r $thatDir/backup/* $thatDir/ sudo cp -r $thatDir/HIDPI/backup/* $thatDir/
sudo rm -rf $thatDir/backup sudo rm -rf $thatDir/HIDPI/disable
echo "Disabled, restart takes effect" echo "Disabled, restart takes effect"
} }
#
function start() function start()
{ {
init init
@ -413,10 +477,11 @@ case $input in
3) disable 3) disable
;; ;;
*) *)
echo "Enter error, bye"; echo "Enter error, bye";
exit 0 exit 0
;; ;;
esac esac
} }
start start