Development

Applescript to Interact with iTerm2

iTerm2 has decent support for Applescript. You can work with sessions, profiles, tabs, and more through Applescript. I only have one example, but it’s something I use in the real-world, so maybe it’ll help someone else.

The following script will open a new tab for every server in the list, and execute a command on that server. Let’s say a new version of Drush is available. I’d use this script to log into every server (we have no less than 15 servers) and check which version of Drush the server is running. I could then quickly update if needed, and I’m already logged in to do so.

The “servers” are defined in my ~/.ssh/config  and use key-based authentication.

This a pretty simple example. To take it one step further it’d be cool to cd into the drush directory, wherever that is on each server, before checking the drush version. Here’s something I’ve been getting help with (thanks to #bash on freenode; sorry if I’ve butchered this, which is why I’m not giving the nick of the person who helped me). Don’t forget to deal with single vs double quotes.

 

Leave a Reply

Your email address will not be published.