Vbox chooser

I use Virtualbox frequently and usually have several systems available. To quickly launch a system without the overhead of the full Virtualbox application I wrote this little script which somebody might find useful.

#!/bin/bash - 
set -o nounset                              

VBOXES=""	# available machines
ACTIVE=""	# running machines
COUNT=0		# total available machines

VBOXES=`vboxmanage list vms | sed 's/"//g' | sed 's/ //g'| cut -d"{" -f 1 |  sort`
ACTIVE=`vboxmanage list runningvms | sed 's/"//g' | sed 's/ //g'| cut -d"{" -f 1 `
for i in $VBOXES
do 
  (( COUNT++ ))
done

HEIGHT=$(( $COUNT*30+130 ))
VM=$(zenity --list --title="$COUNT Virtual Machines" --column="Operating System" --width=350 --height=$HEIGHT $VBOXES)
if [ -z $VM ] ; then
  exit 0
fi
for v in $ACTIVE
do 
  if [ $VM == $v ] ; then
    zenity --info --text="That machine is already running"
    exit 1
  fi
done
$(vboxmanage startvm $VM) 
exit 0

vmstarter

I wrote it in 2013 so most of the bugs have been squashed.

5 Likes