--- arb_macsetup.original	2011-02-28 14:05:31.000000000 -0500
+++ arb_macsetup	2011-02-28 15:22:02.000000000 -0500
@@ -29,11 +29,11 @@
 #
 
 # This is the arb_macsetup script
-# Use it to set the ARBHOME and PATH variables after installing ARB using MacPorts.
+# Use it to set the ARBHOME and PATH variables and to install a .xmodmap file after installing ARB using MacPorts.
 
 # Derived from the MacPorts postflight script
 # Provided by: Matthew Cottrell
-# October 1, 2009
+# January 31, 2011
 
 # Abstraction variables:
 PREFIX=@@PREFIX@@
@@ -42,6 +42,7 @@
 MANPAGES=${PREFIX}/share/man
 TIMESTAMP=$(date +"%Y-%m-%d_at_%H:%M:%S")
 BACKUP_SUFFIX=macports-saved_${TIMESTAMP}
+XMODMAP_FILE=xmodmap
 OUR_STRING="ARB Installer addition on ${TIMESTAMP}"
 
 # Determine the user's shell, in order to choose an appropriate configuration file we'll be tweaking.
@@ -104,6 +105,21 @@
     echo "An appropriate ${1} variable has been added to your shell environment by the ${3} installer."
 }
 
+function write_xmodmap_setting () {
+    if [ -f ${HOME}/.${XMODMAP_FILE} ] && ! grep "${OUR_STRING}" ${HOME}/.${XMODMAP_FILE} > /dev/null; then
+        echo "Backing up your ${HOME}/.${XMODMAP_FILE} keyboard confguration file as ${HOME}/.${XMODMAP_FILE}.${BACKUP_SUFFIX} before adapting it for ARB."
+        /bin/cp -fp ${HOME}/.${XMODMAP_FILE} "${HOME}/.${XMODMAP_FILE}.${BACKUP_SUFFIX}" || {
+            echo "An attempt to backup your original configuration file failed! Please set your ARB compatible environment manually."
+            
+            exit 1
+        }
+        echo -e "\n##\n# Your previous ${HOME}/.${XMODMAP_FILE} file was backed up as ${HOME}/.${XMODMAP_FILE}.${BACKUP_SUFFIX}\n##" >> ${HOME}/.${XMODMAP_FILE}
+    fi
+    echo -e "${1}\n${2}\n${3}\n${4}\n${5}\n${6}\n${7}\n" > ${HOME}/.${XMODMAP_FILE}
+    chown ${USER} ${HOME}/.${XMODMAP_FILE} || echo "Warning: unable to adapt permissions on your ${HOME}/.${XMODMAP_FILE} shell configuration file!"
+    echo "An appropriate xmodmap file has been added to your home folder by the ${8} installer."
+}
+
 # Confirm that MacPorts has been configured for this user:
 if ${SHELL} ${LOGIN_FLAG} -c "/usr/bin/printenv PATH" | grep ${PREFIX} > /dev/null; then
     echo "Your shell already has the right PATH environment variable for use with MacPorts!"
@@ -148,16 +164,19 @@
 	write_setting ARBHOME "${PREFIX}/share/arb" ARB
 fi
 
+#write the .xmodmap file for easy keyboard shortcutsin the ARB sequence editor
+write_xmodmap_setting "clear Mod1" "clear Mod2" "keycode 63 = Mode_switch" "keycode 66 = Meta_L" "keycode 69 = Meta_R" "add Mod1 = Meta_L Meta_R" "add Mod2 = Mode_switch" ARB
+
 # arb_setenv script is done with its job - exit gracefully!
 echo ""
 echo "You have succesfully installed ARB"
 echo ""
 echo  "Open a new terminal window and type arb to launch ARB"
 echo ""
-echo "A demo data base is located at ${prefix}/share/arb.demo.arb"
+echo "A demo data base is located at ${PREFIX}/share/arb.demo.arb"
 echo ""
 echo "************************************************************************************************"
-echo "Note: To set up ARB for another user log into their account and type ${prefix}/bin/arb_macsetup"
+echo "Note: To set up ARB for another user log into their account and type ${PREFIX}/bin/arb_macsetup"
 echo "************************************************************************************************"
 echo ""
 echo "Please cite: Wolfgang Ludwig, et al. (2004) ARB: a software environment for sequence data. Nucleic Acids Research. 32:1363-1371"
