Last active
April 23, 2018 19:55
-
-
Save jansabbe/ec033959c8907df712bc3816328b3296 to your computer and use it in GitHub Desktop.
JXA script for changing the current profile of the current tab in Terminal.app
This file contains 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 osascript -l JavaScript | |
ObjC.import('stdlib') | |
function run(argv) { | |
const [newSettingSetName, ...commandArray] = argv; | |
const app = Application("Terminal"); | |
const oldSettingsName = app.windows[0].selectedTab.currentSettings.name(); | |
setSettingSet(app, newSettingSetName); | |
if (commandArray.length) { | |
const status = $.system(commandArray.join(" ")); | |
setSettingSet(app, oldSettingsName); | |
$.exit(status) | |
} | |
} | |
function setSettingSet(app, name) { | |
let sets = app.settingsSets.whose({name: name}); | |
assertSingleSettingSet(sets, "Didn't find unique profile with name '" + name + "'"); | |
app.windows[0].selectedTab.currentSettings = sets.first(); | |
} | |
function assertSingleSettingSet(settingSets, errorMessage) { | |
if (settingSets.length !== 1) { | |
console.log(errorMessage) | |
$.exit(-1); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
withprofile
An JXA script that temporarily allows you to change the current profile in your osx terminal. Usefull if you want to change the background to red while sshing to a remote server.
Example usage:
withprofile "silver aerogel" vim
When
vim
ends, you go back to your original profile. In OSX Terminal Preferences, change New tabs open with to Default Profile to avoid unexpected behavior when opening new tabs.Tip: Adding
alias ssh='withprofile "Red Sands" caffeinate /usr/bin/ssh'
to your~/.bashrc
or~/.zshrc
will avoid putting your mac to sleep while connecting to a remote server. The red background will remind you of your connection to a remote server.You can also leave off the command. When you run
withprofile "red sands"
, it will change the profile for the current tab.