Skip to content

Instantly share code, notes, and snippets.

@scmx
Created April 9, 2021 18:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save scmx/f38ce3fdc625dc11e75ed2c6290fbb87 to your computer and use it in GitHub Desktop.
Save scmx/f38ce3fdc625dc11e75ed2c6290fbb87 to your computer and use it in GitHub Desktop.
How to switch between dark mode and light mode in iTerm using dynamic profiles #iterm #dark-mode #light-mode #node

https://iterm2.com/documentation-dynamic-profiles.html

#!/usr/bin/env node

const fs = require('fs');
const path = require('path');

// Example usage
// 1. Create two nice profiles in iTerm
// 2. Export them to one JSON file each
// 3. Run iterm-switch-dynamic-profile ~/path/to/profile.json
// 4. Run iterm-switch-dynamic-profile ~/path/to/other.json
// 5. Automate this when OS switches dark mode

// Read new profile JSON
const newProfile = require(path.resolve(
  process.cwd(),
  process.argv[2]
));

// Maintain same Guid for the Dynamic Profile.
// Needs to be different from other profiles
newProfile.Guid = 'A98F9A85-8AF3-455D-8C46-0BD3A71EB756'

// This file will be updated
const dynamicProfilePath = path.resolve(path.join(
  process.env.HOME,
  'Library/Application Support/iTerm2/DynamicProfiles',
  'Auto.json'
));

// Write JSON with Profiles array according to docs
// https://iterm2.com/documentation-dynamic-profiles.html
fs.writeFileSync(dynamicProfilePath, JSON.stringify({
  Profiles: [newProfile]
}, null, 2));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment