Code follows: (previous post was too large for Launchpad) #!/bin/bash CREATED=2010-09-30 MODIFIED=2010-10-01 VERSION=01.001.000 LICENSE="Public Domain" ########################################## ## Use this code at your own risk! ## ## I am not responspible for any ## ## results that come from your using ## ## it! ## ########################################## # You should definitely make a backup of ~/.config/terminator/config # This program will erase that file. # Ignore this terminator PID when killing later. If you want/need this functionality, # you will have to get the appropriate pid and put it here: IGNOREPID= # Set this to "true" if you want to run terminator with -d DEBUG=false # This may need to be a higher integer delay for the sleep command, for older machines DELAY=1 ME="$0" emptyconfig() { echo "" > ~/.config/terminator/config return 0 } pretest() { local what="$1" echo "test=$what" case "$what" in vanilla) # Setup config # We have Titlebars. emptyconfig PARAM= ;; notitlebars) # Setup config # We disable Titlebars. emptyconfig echo "[profiles]" > ~/.config/terminator/config echo "[[default]]" >> ~/.config/terminator/config echo "show_titlebar = False" >> ~/.config/terminator/config PARAM= ;; dirs[123]|freeze[123]) # Setup config emptyconfig PARAM=--geometry=800x600 ;; maze1) # Setup config emptyconfig PARAM=--geometry=800x600 ;; *) ERR="ERR:pretest: Invalid TEST: $what" return 1 ;; esac return 0 } xdodo() { # do a sequence of xdotool key injections, then sleep for $DELAY seconds # currently recognize: # [ e o w ] as ctrl+shift+ combos # [ u d l r ] as alt+ combos local k="$1" # TODO Implement window safety here, using xdotool to detect correct window # Probably prefer: xdodo [type "TEXT"]... | KEY... # TODO Change interface to accept unlimited parameters for sequences case "$k" in [EeOoWw]) xdotool key ctrl+shift+$k ;; U|u) xdotool key alt+Up ;; D|d) xdotool key alt+Down ;; L|l) xdotool key alt+Left ;; R|r) xdotool key alt+Right ;; *) ERR="ERR:xdodo: Invalid key command: $k" return 1 ;; esac sleep $(( DELAY * 1 )) return 0 } xdotest() { local what="$1" local count=$2 local i local k local abc="ABCDEFGHIJKLMNOPQRSTUVWXYZ" # if loop goes higher than 26 items, need to get a different plan case "$what" in vanilla|notitlebars) # open some terminals ... i=0 xdotool type "${abc:i:1} " for i in $( seq 1 $count ); do k="o"; if ! xdodo "$k"; then return 1; fi #k="u"; if ! xdodo "$k"; then return 1; fi xdotool type "${abc:i:1} " done # ... and close them for i in $( seq 1 $count ); do k="w"; if ! xdodo "$k"; then return 1; fi done ;; dirs1) # create a layout, echoing a step number after each step ... i=0 for k in o e u e e l o; do xdotool type "${abc:i:1} " if ! xdodo "$k"; then return 1; fi ((i++)) done xdotool type "${abc:i:1} " sleep $(( DELAY * 1 )) # ... and move around between the terminals xdotool type " [ d u d l u ] " sleep $(( DELAY * 1 )) i=0 for k in d u d l u; do xdotool type "$i " if ! xdodo "$k"; then return 1; fi ((i++)) done xdotool type "$i " ;; dirs2) # demo for bizarre layout #2 # create a layout, echoing a step number after each step ... i=0 for k in o e u e l o e; do xdotool type "${abc:i:1} " if ! xdodo "$k"; then return 1; fi ((i++)) done xdotool type "${abc:i:1} " sleep $(( DELAY * 1 )) # ... and move around between the terminals xdotool type " [ d u d r u ] " sleep $(( DELAY * 1 )) i=0 for k in d u d r u; do xdotool type "$i " if ! xdodo "$k"; then return 1; fi ((i++)) done xdotool type "$i " ;; dirs3) # demo for bizarre layout #3 # create a layout, echoing a step number after each step ... i=0 for k in e o l o u o e; do xdotool type "${abc:i:1} " if ! xdodo "$k"; then return 1; fi ((i++)) done xdotool type "${abc:i:1} " sleep $(( DELAY * 1 )) # ... and move around between the terminals xdotool type " [ d u d r u ] " sleep $(( DELAY * 1 )) i=0 for k in d u d r u; do xdotool type "$i " if ! xdodo "$k"; then return 1; fi ((i++)) done xdotool type "$i " ;; freeze1) # # create a layout, echoing a step number after each step ... i=0 for k in o e u e e l o; do xdotool type "${abc:i:1} " if ! xdodo "$k"; then return 1; fi ((i++)) done xdotool type "${abc:i:1} " # sleep $(( DELAY * 2 )) xdotool type "...and now a freeze:" sleep $(( DELAY * 2 )) k="e"; if ! xdodo "$k"; then return 1; fi k="e"; if ! xdodo "$k"; then return 1; fi ;; freeze2) # # create a layout, echoing a step number after each step ... i=0 for k in o e u e l o e; do xdotool type "${abc:i:1} " if ! xdodo "$k"; then return 1; fi ((i++)) done xdotool type "${abc:i:1} " # sleep $(( DELAY * 2 )) xdotool type "...and now a freeze:" sleep $(( DELAY * 2 )) k="e"; if ! xdodo "$k"; then return 1; fi k="e"; if ! xdodo "$k"; then return 1; fi ;; freeze3) # # create a layout, echoing a step number after each step ... i=0 for k in e o l o u o e; do xdotool type "${abc:i:1} " if ! xdodo "$k"; then return 1; fi ((i++)) done xdotool type "${abc:i:1} " # sleep $(( DELAY * 2 )) xdotool type "...and now a freeze:" sleep $(( DELAY * 2 )) k="e"; if ! xdodo "$k"; then return 1; fi k="e"; if ! xdodo "$k"; then return 1; fi ;; maze1) # make a simple maze for demonstration # create a layout, echoing a step number after each step ... xdotool type '"start" ' i=0 for k in e o u o d o; do xdotool type "${abc:i:1} " if ! xdodo "$k"; then return 1; fi ((i++)) done xdotool type "${abc:i:1} " sleep $(( DELAY * 1 )) xdotool type '"finish" ' # go to start k="l"; if ! xdodo "$k"; then return 1; fi # ... and move around between the terminals xdotool type " now moving: [ r d d ] " sleep $(( DELAY * 1 )) i=0 for k in r d d; do xdotool type "$i " if ! xdodo "$k"; then return 1; fi ((i++)) done xdotool type "$i " ;; *) ERR="ERR:xdotest: Invalid TEST: $what" return 1 ;; esac xdotool type " Done!" return 0 } init() { # sorry for the butchered-looking hack, but it works fine for now :) if [[ "$1" == "" ]]; then help return 1 fi if [[ "$1" == "vanilla" ]] || [[ "$1" == "notitlebars" ]]; then # we need to have a second parameter, an integer local regex='^[0-9]$' if ! [[ "$1" =~ $regex ]]; then help return 1 else COUNT=$2 fi fi TEST="$1" # For visual cleanliness; clears and reinitializes the original terminal window. reset # Silently kill the highest-numbered pid instance of terminator, # presumed to be the most recently-executed instance. THEPID=$( ps a | grep [t]erminator | tail -n 1 | awk '{print $1}' ) if ! [[ "$IGNOREPID" == "$THEPID" ]]; then echo "Killing $THEPID ... " kill $THEPID &> /dev/null # # Did it really die? I haven't seen a problem with this, but it doesn't hurt to check. # if [[ "" == $( ps a | grep $THEPID ) ]]; then # echo "Success." # else # echo "Fail!" # ERR="ERR:init: Failed to kill pid $THEPID." # return 1 # fi else echo "Nothing to kill. This is fine." fi return 0 } help() { cat << EOT Usage: ${ME##*/} ( vanilla | titlebars ) COUNT ${ME##*/} dirs1 | dirs2 | dirs3 | freeze1 | freeze2 | freeze3 Where COUNT is the number of times we perform the 'action.' The 'action' is defined depending on which TEST is chosen. Currently, the basic action is to open new terminals by splitting horizontally COUNT times, then close them again. Be very conservative! When Terminator freezes, the xdotool has no way of knowing, and may inject keypresses where they are not wanted. (Actually, it does have a way, but I haven't implemented it here.) ########################################## ## Use this code at your own risk! ## ## I am not responspible for any ## ## results that come from your using ## ## it! ## ########################################## You should definitely make a backup of ~/.config/terminator/config This program will erase that file. EOT return 0 } main() { if ! init "$@"; then return 1; fi # Setup ~/.config/terminator/config as appropriate to the test chosen. if ! pretest "$TEST"; then return 1; fi # Run Terminator as a background process, so that everything else works. terminator $PARAM & # Wait for the new window to open. sleep $(( DELAY * 2 )) if ! xdotest "$TEST" "$COUNT"; then return 1; fi return 0 } # Program starts here if ! main "$@"; then echo "$ERR" exit fi sleep 2 exit 0