-
Notifications
You must be signed in to change notification settings - Fork 1
/
virtualbox.sh
executable file
·50 lines (47 loc) · 1.79 KB
/
virtualbox.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/usr/bin/env bash
lf='
'
IFS="$lf"
VMS=($(vboxmanage list vms))
unset IFS
echo "VBox | iconName=virtualbox"
echo "---"
for vml in "${VMS[@]}"; do
vmname="${vml% *}"
vmname="${vmname%\"}"
vmname="${vmname#\"}"
vmid="${vml##* }"
status="$(vboxmanage showvminfo "$vmid" | sed -n '/^State:/{s/State:\s*//;s/ (.*//;p;q}')"
#echo "$status"
actions=''
case "$status" in
'powered off')
status='⏹'
actions="--⏵ Start | bash='vboxmanage' param1='startvm' param2='$vmid' terminal=false refresh=true"
;;
'running')
status="⏵"
if which xwininfo >/dev/null 2>&1 && which xdotool >/dev/null 2>&1 ; then
wid="$(xwininfo -root -children | grep "$vmname \[.*\] - Oracle VM VirtualBox\"" | sed 's/ ".*//')"
actions+="--🗔 Display | bash='xdotool windowactivate $wid' terminal=false refresh=true $lf"
fi
actions+="--⏸ Pause | bash='vboxmanage' param1='controlvm' param2='$vmid' param3='pause' terminal=false refresh=true $lf"
actions+="--⏹ ACPI Shutdown | bash='vboxmanage' param1='controlvm' param2='$vmid' param3='acpipowerbutton' terminal=false refresh=true $lf"
actions+="--😴 ACPI Suspend | bash='vboxmanage' param1='controlvm' param2='$vmid' param3='acpisleepbutton' terminal=false refresh=true"
;;
'paused')
status='⏸'
if which xwininfo >/dev/null 2>&1 && which xdotool >/dev/null 2>&1 ; then
wid="$(xwininfo -root -children | grep "$vmname \[.*\] - Oracle VM VirtualBox\"" | sed 's/ ".*//')"
actions+="--🗔 Display | bash='xdotool windowactivate $wid' terminal=false refresh=true $lf"
fi
actions+="--⏵ Resume | bash='vboxmanage' param1='controlvm' param2='$vmid' param3='resume' terminal=false refresh=true"
;;
*)
status='?';;
esac
echo "$status $vmname | ansi=true refresh=true"
echo "$actions"
done
echo "---"
echo "Refresh | refresh=true"