Some variable name changes and code structure changes
This commit is contained in:
parent
1ee7bccafd
commit
84e35ead60
1 changed files with 67 additions and 91 deletions
154
hidpi.sh
154
hidpi.sh
|
@ -1,12 +1,18 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
sipInfo=("$(csrutil status)")
|
cat << EEF
|
||||||
systemVersion=($(sw_vers -productVersion | cut -d "." -f 2))
|
_ _ _____ _____ _____ _____
|
||||||
|
| | | | |_ _| | __ \ | __ \ |_ _|
|
||||||
|
| |__| | | | | | | | | |__) | | |
|
||||||
|
| __ | | | | | | | | ___/ | |
|
||||||
|
| | | | _| |_ | |__| | | | _| |_
|
||||||
|
|_| |_| |_____| |_____/ |_| |_____|
|
||||||
|
|
||||||
|
============================================
|
||||||
|
EEF
|
||||||
|
|
||||||
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))
|
||||||
|
|
||||||
disableSIP="Need to disable SIP"
|
|
||||||
langRemoteMode="Remote Mode"
|
|
||||||
langLocalMode="Local Mode"
|
|
||||||
langDisplay="Display"
|
langDisplay="Display"
|
||||||
langMonitors="Monitors"
|
langMonitors="Monitors"
|
||||||
langIndex="Index"
|
langIndex="Index"
|
||||||
|
@ -41,9 +47,6 @@ langChooseResOp5="(5) 3000x2000 Display"
|
||||||
langChooseResOpCustom="(6) Manual input resolution"
|
langChooseResOpCustom="(6) Manual input resolution"
|
||||||
|
|
||||||
if [[ "${systemLanguage}" == "zh_CN" ]]; then
|
if [[ "${systemLanguage}" == "zh_CN" ]]; then
|
||||||
disableSIP="需要关闭 SIP"
|
|
||||||
langRemoteMode="远程模式"
|
|
||||||
langLocalMode="本地模式"
|
|
||||||
langDisplay="显示器"
|
langDisplay="显示器"
|
||||||
langMonitors="显示器"
|
langMonitors="显示器"
|
||||||
langIndex="序号"
|
langIndex="序号"
|
||||||
|
@ -78,26 +81,6 @@ if [[ "${systemLanguage}" == "zh_CN" ]]; then
|
||||||
langChooseResOpCustom="(6) 手动输入分辨率"
|
langChooseResOpCustom="(6) 手动输入分辨率"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
downloadHost="https://raw.githubusercontent.com/xzhih/one-key-hidpi/master"
|
|
||||||
# downloadHost="https://raw.githubusercontent.com/xzhih/one-key-hidpi/dev"
|
|
||||||
# downloadHost="http://127.0.0.1:8080"
|
|
||||||
|
|
||||||
shellDir="$(cd `dirname -- $0` && pwd)"
|
|
||||||
|
|
||||||
if [ -d "${shellDir}/displayIcons" ];then
|
|
||||||
echo $langLocalMode
|
|
||||||
downloadHost="file://${shellDir}"
|
|
||||||
else
|
|
||||||
echo $langRemoteMode
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ "${sipInfo}" == *"Filesystem Protections: disabled"* ]] || [[ "$(awk '{print $5}' <<< "${sipInfo}")" == "disabled." ]] || [[ "$(awk '{print $5}' <<< "${sipInfo}")" == "disabled" ]]; then
|
|
||||||
:
|
|
||||||
else
|
|
||||||
echo "${disableSIP}";
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
function get_edid()
|
function get_edid()
|
||||||
{
|
{
|
||||||
local index=0
|
local index=0
|
||||||
|
@ -171,48 +154,41 @@ function get_edid()
|
||||||
# init
|
# init
|
||||||
function init()
|
function init()
|
||||||
{
|
{
|
||||||
#
|
get_edid
|
||||||
cat << EEF
|
|
||||||
_ _ _____ _____ _____ _____
|
|
||||||
| | | | |_ _| | __ \ | __ \ |_ _|
|
|
||||||
| |__| | | | | | | | | |__) | | |
|
|
||||||
| __ | | | | | | | | ___/ | |
|
|
||||||
| | | | _| |_ | |__| | | | _| |_
|
|
||||||
|_| |_| |_____| |_____/ |_| |_____|
|
|
||||||
|
|
||||||
============================================
|
currentDir="$(cd `dirname -- $0` && pwd)"
|
||||||
EEF
|
libDisplaysDir="/Library/Displays"
|
||||||
#
|
targetDir="${libDisplaysDir}/Contents/Resources/Overrides"
|
||||||
get_edid
|
sysDisplayDir="/System${targetDir}"
|
||||||
|
Overrides="\/Library\/Displays\/Contents\/Resources\/Overrides"
|
||||||
|
sysOverrides="\/System${Overrides}"
|
||||||
|
|
||||||
thisDir=$(cd `dirname -- $0` && pwd)
|
DICON="com\.apple\.cinema-display"
|
||||||
libDisplaysDir="/Library/Displays"
|
imacicon=${sysOverrides}"\/DisplayVendorID\-610\/DisplayProductID\-a032\.tiff"
|
||||||
thatDir="${libDisplaysDir}/Contents/Resources/Overrides"
|
mbpicon=${sysOverrides}"\/DisplayVendorID\-610\/DisplayProductID\-a030\-e1e1df\.tiff"
|
||||||
thatSysDir="/System${thatDir}"
|
mbicon=${sysOverrides}"\/DisplayVendorID\-610\/DisplayProductID\-a028\-9d9da0\.tiff"
|
||||||
Overrides="\/Library\/Displays\/Contents\/Resources\/Overrides"
|
lgicon=${sysOverrides}"\/DisplayVendorID\-1e6d\/DisplayProductID\-5b11\.tiff"
|
||||||
sysOverrides="\/System${Overrides}"
|
proxdricon=${Overrides}"\/DisplayVendorID\-610\/DisplayProductID\-ae2f\_Landscape\.tiff"
|
||||||
|
|
||||||
DICON="com\.apple\.cinema-display"
|
if [[ ! -d ${targetDir}/HIDPI ]]; then
|
||||||
imacicon=${sysOverrides}"\/DisplayVendorID\-610\/DisplayProductID\-a032\.tiff"
|
sudo mkdir -p ${targetDir}/HIDPI
|
||||||
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 ${thatDir}/HIDPI ]]; then
|
downloadHost="https://raw.githubusercontent.com/xzhih/one-key-hidpi/master"
|
||||||
sudo mkdir -p ${thatDir}/HIDPI
|
if [ -d "${currentDir}/displayIcons" ];then
|
||||||
|
downloadHost="file://${currentDir}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
generate_restore_cmd
|
generate_restore_cmd
|
||||||
}
|
}
|
||||||
|
|
||||||
#
|
#
|
||||||
function generate_restore_cmd()
|
function generate_restore_cmd()
|
||||||
{
|
{
|
||||||
#
|
#
|
||||||
rm -rf ${thisDir}/tmp/
|
rm -rf ${currentDir}/tmp/
|
||||||
mkdir -p ${thisDir}/tmp/
|
mkdir -p ${currentDir}/tmp/
|
||||||
cat > "${thisDir}/tmp/disable" <<-\CCC
|
cat > "${currentDir}/tmp/disable" <<-\CCC
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
function get_edid()
|
function get_edid()
|
||||||
|
@ -282,8 +258,8 @@ esac
|
||||||
echo "HIDPI Disabled"
|
echo "HIDPI Disabled"
|
||||||
CCC
|
CCC
|
||||||
|
|
||||||
sudo mv ${thisDir}/tmp/disable ${thatDir}/HIDPI/
|
sudo mv ${currentDir}/tmp/disable ${targetDir}/HIDPI/
|
||||||
sudo chmod +x ${thatDir}/HIDPI/disable
|
sudo chmod +x ${targetDir}/HIDPI/disable
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -291,10 +267,10 @@ sudo chmod +x ${thatDir}/HIDPI/disable
|
||||||
function choose_icon()
|
function choose_icon()
|
||||||
{
|
{
|
||||||
#
|
#
|
||||||
rm -rf ${thisDir}/tmp/
|
rm -rf ${currentDir}/tmp/
|
||||||
mkdir -p ${thisDir}/tmp/
|
mkdir -p ${currentDir}/tmp/
|
||||||
mkdir -p ${thisDir}/tmp/DisplayVendorID-${Vid}
|
mkdir -p ${currentDir}/tmp/DisplayVendorID-${Vid}
|
||||||
curl -fsSL "${downloadHost}/Icons.plist" -o ${thisDir}/tmp/Icons.plist
|
curl -fsSL "${downloadHost}/Icons.plist" -o ${currentDir}/tmp/Icons.plist
|
||||||
|
|
||||||
echo ""
|
echo ""
|
||||||
echo "-------------------------------------"
|
echo "-------------------------------------"
|
||||||
|
@ -313,29 +289,29 @@ 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 ${thisDir}/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 ${thisDir}/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 ${thisDir}/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 ${thatSysDir}/DisplayVendorID-1e6d/DisplayProductID-5b11.icns ${thisDir}/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 ${thisDir}/tmp/DisplayVendorID-${Vid}/DisplayProductID-${Pid}.icns
|
curl -fsSL "${downloadHost}/displayIcons/ProDisplayXDR.icns" -o ${currentDir}/tmp/DisplayVendorID-${Vid}/DisplayProductID-${Pid}.icns
|
||||||
if [[ ! -f ${thatDir}/DisplayVendorID-610/DisplayProductID-ae2f_Landscape.tiff ]]; then
|
if [[ ! -f ${targetDir}/DisplayVendorID-610/DisplayProductID-ae2f_Landscape.tiff ]]; then
|
||||||
curl -fsSL "${downloadHost}/displayIcons/ProDisplayXDR.tiff" -o ${thisDir}/tmp/DisplayVendorID-${Vid}/DisplayProductID-${Pid}.tiff
|
curl -fsSL "${downloadHost}/displayIcons/ProDisplayXDR.tiff" -o ${currentDir}/tmp/DisplayVendorID-${Vid}/DisplayProductID-${Pid}.tiff
|
||||||
Picon=${Overrides}"\/DisplayVendorID\-${Vid}\/DisplayProductID\-${Pid}\.tiff"
|
Picon=${Overrides}"\/DisplayVendorID\-${Vid}\/DisplayProductID\-${Pid}\.tiff"
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
6) rm -rf ${thisDir}/tmp/Icons.plist
|
6) rm -rf ${currentDir}/tmp/Icons.plist
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
|
|
||||||
|
@ -346,14 +322,14 @@ 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" ${thisDir}/tmp/Icons.plist
|
/usr/bin/sed -i "" "s/VID/${Vid}/g" ${currentDir}/tmp/Icons.plist
|
||||||
/usr/bin/sed -i "" "s/PID/${Pid}/g" ${thisDir}/tmp/Icons.plist
|
/usr/bin/sed -i "" "s/PID/${Pid}/g" ${currentDir}/tmp/Icons.plist
|
||||||
/usr/bin/sed -i "" "s/RPX/${RP[0]}/g" ${thisDir}/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" ${thisDir}/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" ${thisDir}/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" ${thisDir}/tmp/Icons.plist
|
/usr/bin/sed -i "" "s/RPH/${RP[3]}/g" ${currentDir}/tmp/Icons.plist
|
||||||
/usr/bin/sed -i "" "s/PICON/${Picon}/g" ${thisDir}/tmp/Icons.plist
|
/usr/bin/sed -i "" "s/PICON/${Picon}/g" ${currentDir}/tmp/Icons.plist
|
||||||
/usr/bin/sed -i "" "s/DICON/${DICON}/g" ${thisDir}/tmp/Icons.plist
|
/usr/bin/sed -i "" "s/DICON/${DICON}/g" ${currentDir}/tmp/Icons.plist
|
||||||
fi
|
fi
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -361,9 +337,9 @@ fi
|
||||||
# main
|
# main
|
||||||
function main()
|
function main()
|
||||||
{
|
{
|
||||||
sudo mkdir -p ${thisDir}/tmp/DisplayVendorID-${Vid}
|
sudo mkdir -p ${currentDir}/tmp/DisplayVendorID-${Vid}
|
||||||
dpiFile=${thisDir}/tmp/DisplayVendorID-${Vid}/DisplayProductID-${Pid}
|
dpiFile=${currentDir}/tmp/DisplayVendorID-${Vid}/DisplayProductID-${Pid}
|
||||||
sudo chmod -R 777 ${thisDir}/tmp/
|
sudo chmod -R 777 ${currentDir}/tmp/
|
||||||
|
|
||||||
#
|
#
|
||||||
cat > "${dpiFile}" <<-\CCC
|
cat > "${dpiFile}" <<-\CCC
|
||||||
|
@ -447,11 +423,11 @@ FFF
|
||||||
# end
|
# end
|
||||||
function end()
|
function end()
|
||||||
{
|
{
|
||||||
sudo chown -R root:wheel ${thisDir}/tmp/
|
sudo chown -R root:wheel ${currentDir}/tmp/
|
||||||
sudo chmod -R 0755 ${thisDir}/tmp/
|
sudo chmod -R 0755 ${currentDir}/tmp/
|
||||||
sudo chmod 0644 ${thisDir}/tmp/DisplayVendorID-${Vid}/*
|
sudo chmod 0644 ${currentDir}/tmp/DisplayVendorID-${Vid}/*
|
||||||
sudo cp -r ${thisDir}/tmp/* ${thatDir}/
|
sudo cp -r ${currentDir}/tmp/* ${targetDir}/
|
||||||
sudo rm -rf ${thisDir}/tmp
|
sudo rm -rf ${currentDir}/tmp
|
||||||
sudo defaults write /Library/Preferences/com.apple.windowserver DisplayResolutionEnabled -bool YES
|
sudo defaults write /Library/Preferences/com.apple.windowserver DisplayResolutionEnabled -bool YES
|
||||||
echo "${langEnabled}"
|
echo "${langEnabled}"
|
||||||
echo "${langEnabledLog}"
|
echo "${langEnabledLog}"
|
||||||
|
@ -569,7 +545,7 @@ 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}" ${thatDir}/Icons.plist
|
1) sudo /usr/libexec/plistbuddy -c "Delete :vendors:${Vid}:products:${Pid}" ${targetDir}/Icons.plist
|
||||||
;;
|
;;
|
||||||
2) sudo rm -rf ${libDisplaysDir}
|
2) sudo rm -rf ${libDisplaysDir}
|
||||||
;;
|
;;
|
||||||
|
|
Loading…
Reference in a new issue