Home » English » Working in multiple locations

Working in multiple locations

I guess it becomes more and more usual to work not only in one place but have your office wherever you are. Since years I find it extremely practical to have all my data on one mobile computer (a MacBook Pro, currently) and work with this laptop in various locations. But different locations require different computer settings: The network setup may change, the printer system as well, the filesystem you’re connected to can be different as well as many other things. Since I found it annoying to always have to change all these things by hand, I put in place a set of scripts with which all setttings can be changed from one location to another with one simple shell command. When I get to my institute, I call a script called switchmpia.sh which looks like this:

#!/bin/bash
rm ~/.bash_profile
ln -s ~/.bash_profile_mpia ~/.bash_profile
sudo mv /etc/cups/client.conf.off /etc/cups/client.conf
#
switch_network_mpia.osascript
echo “**************     Network environment set to home ******************”
#
echo “**************         Environment set to MPIA        ***************”
echo “Printer settings only become effective after restart of applications.”

#!/bin/bash

rm ~/.bash_profile

ln -s ~/.bash_profile_mpia ~/.bash_profile

sudo mv /etc/cups/client.conf.off /etc/cups/client.conf

switch_network_mpia.osascript

It changes the default .bash_profile to one that has some institute-specific settings (see below), changes the CUPS settings (so that I can use my USB printer at home and the CUPS network printers in my institute) and calls an Apple Script that changes my Mac’s network settings (see below).
My .bash_profile_mpia looks like this:
export MIDIDATA=/Volumes/astrodata/MIDIDATA
# …
echo “Environment: MPIA”
source ~/.bash_profile_generic
It sets a number of environment variables that I use in my scripts to values appropriate for the disks that I have available in my office, then it calls my generic .bash_profile.
The above mentioned Apple Script switch_network_mpia.osascript looks like this:
#!/usr/bin/osascript
tell application “System Events” to tell (process 1 whose frontmost is true) to click menu item “MPIA” of menu 1 of menu item “Umgebung” of menu 1 of menu bar item 1 of menu bar 1
It changes my Mac’s network location (which uses a German localization) to the settings for my institute (setting mainly the correct proxy servers). A good website to learn how Apple Script can help you with scripting system preferences was macosxautomation.com. The Apple Script was the most tricky bit for me and I was happy to receive very helpful comments from Pierre L. in Apple’s discussion forum for this (see the link for more information about this). Thanks again, Pierre L.!

2 Comments

Leave a comment

My Tweets