Skip to content

Instantly share code, notes, and snippets.

@cesarandreu
Last active June 4, 2018 19:31
Show Gist options
  • Save cesarandreu/035b31f7edf4e1c242f6f33770b95bd3 to your computer and use it in GitHub Desktop.
Save cesarandreu/035b31f7edf4e1c242f6f33770b95bd3 to your computer and use it in GitHub Desktop.
Resize the active Terminal.app window from the CLI

resize.js

This script lets you resize the active Terminal.app window from the CLI. If no values are specified it'll use the current profile's default size.

Usage

Set width and height:

$ resize 120 24

Reset to the current profile's default size:

$ resize

Installation

  1. Add ~/.local/bin/ to your PATH.
  2. Save resize.js to ~/.local/bin/.
  3. Make it executable: chmod +x resize.js.
  4. Create a symlink so you don't have to type .js: ls -s resize.js resize
#!/usr/bin/env osascript -l JavaScript
/**
* Author: Cesar Andreu ([email protected])
* License: MIT
* Resize the active Terminal.app window from the CLI
*/
function run (args) {
const Terminal = Application('Terminal')
const tab = Terminal.windows[0].selectedTab
const settings = tab.currentSettings
// Use the current profile's values as the default size
let width = settings.numberOfColumns
let height = settings.numberOfRows
// resize 120 24
if (args.length === 2) {
width = Number.parseInt(args[0], 10)
height = Number.parseInt(args[1], 10)
}
tab.numberOfColumns = width
tab.numberOfRows = height
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment