Created
May 20, 2021 08:59
-
-
Save OwenMelbz/1fc695bd931a8a7d27d792fcc4ffa869 to your computer and use it in GitHub Desktop.
Node CLI tool to disable darkmode on specific apps
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env node | |
const path = require('path') | |
const { execSync } = require('child_process') | |
/* | |
* You can symlink this to a bin dir e.g. "ln -s /Users/owen/lightmode.js /usr/local/bin/lightmode" | |
* To enable lightmode for an app, simply pass the full path to the application to lightmode e.g. | |
* | |
* lightmode /Application/Google\ Chrome.app | |
* | |
* You can even drag the app icon straight into your terminal to get the full path. | |
*/ | |
const appPath = process.argv.pop() | |
const appName = path.basename(appPath, '.app') | |
// Open the app so it's accessible by osascript. | |
execSync(`open "${appPath}"`) | |
// Extract the application ID. | |
const appId = execSync(`osascript -e 'id of app "${appName}"'`, { | |
encoding: 'utf8', | |
}).toString().trim() | |
// Tell the OS to disable darkmode. | |
execSync(`defaults write ${appId} NSRequiresAquaSystemAppearance -bool Yes`) | |
// Now we restart the application. | |
execSync(`pkill "${appName}"`) | |
execSync(`open "${appPath}"`) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment