using Applescript to switch working environments

Nikolaus Gradwohl2007-09-16T17:40:00+00:00

Halve of my time i'm working at a costomers office, everyone has a different network environment, some usuale proxies some don't. in some environments i can use my mailclient, in some i have to use my webmail account.

so i usualy spent the first 5 to 10 minutes of my workday switching network profiles, configuring proxies, changing my subversion configurations, stopping and starting various propgramms, etc

doing repetitive stupid work is something i dont like. im a computer programmer and these are exactly the ones that sould be automated in my oppinion.

so i startet to create a little applescipt for every environment im in. it switches to the correct network profile stops my mailclient where nessesery and changes my current subversion profile, if a proxy is required.

changing the subversion config was the easiest part. i just fired up iterm and changed the config by setting a symlink using a shellscript so i have two copies of my .subversion/servers file one for using the proxy and one for direct connections, and the 'servers' file is a symlink to one of those

well at least i thought it woult be easy ...

the tricky part starts when iTerm is running but has no open windows. then i have to start a Termintal before i can call the shellscript so this is what the shellscript-starting part looks like

tell application "iTerm"
    activate
    delay 1
    if (count of windows) is 1 then
        set myterm to (current terminal)
    else
        set myterm to (make terminal)
    end if
    tell myterm
        set mysession to (launch session "Default Session")
        tell the last session
            write text "/Users/nikki/tools/switchsvn2 default"
        end tell
    end tell
end tell

and the corresponding shell script is

#!/bin/bash
cd ~/.subversion
rm servers
ln -s servers.$1 servers

to switch the current network profile applescript UI events need to be activated. Then applescript can be told to click on various menu items like this

tell application "Finder"
    activate
end tell

tell application "System Events"
    click menu item "networkprofilename" of menu "Location" 
                  of menu item "Location" of menu "Apple" of menu bar 1 of process "Finder"
end tell    

to start the applescript files i use quicksilver. So all i have to do now when starting my working day in a different environment is fire up quicksilver using - and entering the name of the environment

thats how i like it :-)

Tweet This! submit to reddit Digg! Tags: | 1 comments | no trackbacks

See also:

sispmctl on macos (aka tale of a ikea lamp)

Trackbacks

Comments

Leave a response

  1. swelidelbert 2011-12-11T08:29:23+00:00

    must check for more detail to your friends

Leave a comment