Skip to content

Instantly share code, notes, and snippets.

@jubianchi
Last active December 15, 2015 12:59
Show Gist options
  • Save jubianchi/5264237 to your computer and use it in GitHub Desktop.
Save jubianchi/5264237 to your computer and use it in GitHub Desktop.
# Start your VM either manually or using vboxmanage
#
# /!\ The VM has to be started in non-headless mode for this script to work
# When you want to make it headless (dettached window) use
$ vboxsw "VM Name" d
# When you want to get the window back use
$ vboxsw "VM Name" a
# Here is an example using the IE9 VM from xdissent/ievms :
$ vboxmanage startvm 'IE9'
# Do some work inside the VM...
$ vboxsw "IE9 (clean)" d # Detach the VM's window
# Do whatever you want on your host machine or on the VM via SSH or something else
$ vboxsw "IE9 (clean)" a # Re-attach the VM's window
# Do whatever you want inside the VM using its GUI
$ vboxmanage controlvm 'IE9' poweroff
# /!\ Something important to notice :
# As you can see in the previous example, vboxmanage works with the VM real name whereas
# vboxsw works with window name.
# It's partially hard coded in the script but you'll still have to give the
# VM Name + Current snapshot name to the vboxsw script
#!/bin/bash
NAME=$1
ID=$(xwininfo -name "$NAME [Running] - Oracle VM VirtualBox" -int \
| grep -e "Window id: [0-9]*" \
| grep -oe " [0-9]* " \
| sed 's/ //g')
if [ $2 = "d" ]
then
[ ! -z $ID ] && xdotool windowunmap $ID
fi
if [ $2 = "a" ]
then
[ ! -z $ID ] && xdotool windowmap $ID
fi
@jubianchi
Copy link
Author

Had an issue or want to make feedback ?

use this: https://github.com/jubianchi/gist
ping me on twitter: @jubianchi

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment