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));