Glen Mazza's Weblog

« TightBlog 2.0 update... | Main | Creating a WSDL-firs... » Saturday February 18, 2017

Using AppleScript to quickly configure your work environment

At work, I use Mac OS' Script Editor to create and compile AppleScript scripts to quickly configure my desktop depending on the programming task at hand. Each compiled script, or application, I place in the desktop folder so it appears on my desktop and can be activated with a simple double-click.

Three tasks I commonly have that I include and adjust as needed depending on the task:

  • Activating a terminal window with tabs pre-opened to various directories and running various commands. A script that opens up three terminal windows in the specified directories, and optionally runs any commands in those directories, would look as follows (see here for more info):
    tell application "Terminal"
    	do script
    	do script "cd /Users/gmazza/mydir1" in tab 1 of front window
    	my makeTab()
    	do script "cd /Users/gmazza/mydir2" in tab 2 of front window
    	my makeTab()
    	do script "cd /Users/gmazza/mydir3" in tab 3 of front window
    end tell
    on makeTab()
    	tell application "System Events" to keystroke "t" using {command down}
    	delay 0.2
    end makeTab
  • Running IntelliJ IDEA. Simple:
    activate application "IntelliJ IDEA"
  • Opening Chrome with a desired number of tabs to certain webpages:
    tell application "Google Chrome"
    	open location ""
    	open location ""
    	open location ""
    end tell

Script editor has a "run" button allowing me to test the scripts as I develop them. Once done, I save the script both standalone (so I can edit it later if desired), but also export it as an application. Exporting it allows for a simple double-click to directly run the task, rather than bringing up the Script Editor and requiring the script to be run via the "run" button.


mac os is fork of BSD(as far as I know), but I am using ubuntu as my desktop and loving it, very easy to customize,total control, drivers(for printer/scanner) installation /anti virus(like window) not needed. Thanks for sharing about apple script. Anant

Posted by Anant Jaynarayan on February 26, 2017 at 05:19 AM EST #

Yup, I've been using Ubuntu at home for over a decade now. Mac OS is my work laptop.

Posted by Glen on March 12, 2017 at 12:36 PM EDT #

Post a Comment:
  • HTML Syntax: NOT allowed

Valid HTML! Valid CSS!

This is a personal weblog, I do not speak for my employer.