<table class="d-block"> <tbody class="d-block"> <tr class="d-block"> <td class="d-block comment-body markdown-body js-comment-body">git
<p>macOS Mojave 中引入了系統層面的黑色模式,Chrome 73 在應用中支行了這一模式,即系統設置爲黑色模式時,Chrome 會自動適應切換到 Dark Mode。</p> <p><a target="_blank" rel="noopener noreferrer" href="https://user-images.githubusercontent.com/3783096/55413010-114c0f80-559b-11e9-9ec1-7080e80ad92a.png"><img src="https://user-images.githubusercontent.com/3783096/55413010-114c0f80-559b-11e9-9ec1-7080e80ad92a.png" alt="Chrome 跟隨系統設置的黑色模式" style="max-width:100%;"></a><br> <em>Chrome 跟隨系統設置的黑色模式</em></p> <p>很酷對不?</p> <p>但其實黑色模式下標題與頂部系統菜單融爲一體,且黑色模式下 Chrome 標籤上內容辨識度也不高了,看起來仍是有點彆扭。更重要的是,這個模式讓人很難區分隱身模式。</p> <p><a target="_blank" rel="noopener noreferrer" href="https://user-images.githubusercontent.com/3783096/55413062-2d4fb100-559b-11e9-88f2-3bfe5c5a5b97.png"><img src="https://user-images.githubusercontent.com/3783096/55413062-2d4fb100-559b-11e9-88f2-3bfe5c5a5b97.png" alt="Chrome 黑色模式下與隱身模式的對比" style="max-width:100%;"></a><br> <em>Chrome 黑色模式下與隱身模式的對比</em></p> <p>因此決定系統使用 Dark Mode 的狀況下將 Chrome 的黑色禁用。</p> <p>經過命令行中設置 <code>defaults</code> 值可達到目的。</p> <div class="highlight highlight-source-shell"><pre>$ defaults write com.google.Chrome NSRequiresAquaSystemAppearance -bool Yes</pre></div> <p>若是想恢復默認,只須要將剛纔設置的值刪掉或者將 <code>Yes</code> 設置成 <code>No</code>。</p> <div class="highlight highlight-source-shell"><pre>$ defaults delete com.google.Chrome NSRequiresAquaSystemAppearance</pre></div> <h2>禁用任意 App 的 Dark Mode</h2> <p>推而廣之,不只可禁止 Chrome 進入 Dark Mode,還可以讓其餘任意 App 不進入 Dark Mode,若是該應用支持過 Dark Mode 的話。只須要找出該應用的打包發佈的 bundle id 便可。這個 id 可經過下面的命令來獲得。好比查看 Canary 版本的 Chrome:</p> <div class="highlight highlight-source-shell"><pre>$ osascript -e <span class="pl-s"><span class="pl-pds">'</span>id of app "Google Chrome Canary"<span class="pl-pds">'</span></span> com.google.Chrome.canary</pre></div> <p>其中 <code>Google Chrome Canary</code> (不區分大小寫)是你在程序文件夾下看到的 <code>.app</code> 後綴的那個文件的文件名,好比這裏 <code>Google Chrome Canary.app</code>。獲得的 id 爲 <code>com.google.Chrome.canary</code> 再代入最上面的命令中便可。</p> <h3>程序 bundle id 的查找</h3> <p>更爲準備的方式,查找 id,是經過右鍵 <code>.app</code> 文件選擇 <code>Show Package Contents</code>,而後找到 <code>Contents>info.plist</code> 文件,搜索 <code>CFBundleIdentifier</code> 便可看到該程序的 bundle id。</p> <div class="highlight highlight-source-shell"><pre>$ defaults write com.google.Chrome.canary NSRequiresAquaSystemAppearance -bool Yes</pre></div> <p>這裏 id 是區分大小寫的,寫錯不生效。</p> <p>要恢復默認時同理。</p> <h3>一些經常使用軟件</h3> <ul> <li>網易雲音樂</li> </ul> <p>同理,設置網易雲音樂關閉其黑色模式,經過 <code>plist</code> 文件發現其 bundle id 爲 <code>com.netease.163music</code>,</p> <div class="highlight highlight-source-shell"><pre>... <span class="pl-k"><</span>key<span class="pl-k">></span>CFBundleIdentifier<span class="pl-k"><</span>/key<span class="pl-k">></span> <span class="pl-k"><</span>string<span class="pl-k">></span>com.netease.163music<span class="pl-k"><</span>/string<span class="pl-k">></span> ...</pre></div> <p>設置:</p> <div class="highlight highlight-source-shell"><pre>defaults write com.netease.163music NSRequiresAquaSystemAppearance -bool Yes</pre></div> <ul> <li>iBooks:</li> </ul> <div class="highlight highlight-source-shell"><pre>defaults write com.apple.iBooksX NSRequiresAquaSystemAppearance -bool Yes</pre></div> <ul> <li>Xcode:</li> </ul> <div class="highlight highlight-source-shell"><pre>defaults write com.apple.dt.Xcode NSRequiresAquaSystemAppearance -bool YES</pre></div> <h3>其餘默認值</h3> <p>經過 <code>defaults read</code> 可查看到全部應用已經存在的的 defaults 值。</p> <div class="highlight highlight-source-shell"><pre>$ defaults <span class="pl-c1">read</span> <span class="pl-k">>></span> defaults.txt</pre></div> <p>打開 <code>defaults.txt</code> 後搜索相應 app 的 id 可看到其全部可用值的列表。好比搜索 <code>com.google.chrome</code></p> <pre><code>{ "com.google.Chrome" = { KeychainReauthorizeInAppSpring2017 = 2; KeychainReauthorizeInAppSpring2017Success = 1; LastRunAppBundlePath = "/Applications/Google Chrome.app"; ... }; "com.google.Chrome.canary" = { KeychainReauthorizeInAppSpring2017 = 1; KeychainReauthorizeInAppSpring2017Success = 1; LastRunAppBundlePath = "/Applications/Google Chrome Canary.app"; ... }; } </code></pre> <h3>相關資源</h3> <ul> <li><a href="https://superuser.com/questions/1417973/how-to-disable-google-chrome-dark-mode" rel="nofollow">How to disable Google Chrome Dark Mode?</a></li> <li><a href="https://apple.stackexchange.com/questions/195244/concise-compact-list-of-all-defaults-currently-configured-and-their-values" rel="nofollow">Concise, compact list of all 'defaults' currently configured and their values?</a></li> </ul> </td> </tr> </tbody> </table>github