Last active
June 8, 2023 04:49
-
-
Save vmassuchetto/53d5d787b2601cd8670a772d0de8ae41 to your computer and use it in GitHub Desktop.
Shell script to open files in a VirtualBox Windows guest from the Linux host
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Based on http://tinyurl.com/jmze5lw with some additions | |
# Dependencies: detox wmctrl | |
# In your VM, share the root host location "/" in $DRIVE | |
SCRIPTPATH="$(basename "$0")" | |
VMNAME="WindowsXP" | |
DRIVE="E:" | |
# Start vm if not running already | |
if [ $(VBoxManage list runningvms | wc -l) = 0 ]; then | |
VBoxManage startvm $VMNAME | |
sleep 5s | |
fi | |
# Wait until graphics are available | |
until VBoxManage showvminfo $VMNAME | grep '"Graphics Mode": active/running' > /dev/null | |
do | |
sleep 0.5s | |
done | |
for FILE in "$@" | |
do | |
# Set a converted file path | |
if echo $FILE | grep '^/' > /dev/null; then | |
TARGETPATH=$FILE | |
else | |
TARGETPATH=$PWD'/'$FILE | |
fi | |
CLEANPATH=$(detox -vs utf_8 "$TARGETPATH" | tail -1 | awk '{print $NF}') | |
WINPATH=$(echo $DRIVE$CLEANPATH | sed 's/\//\\/g') | |
# Start application in VirtualBox | |
VBoxManage guestcontrol "$VMNAME" run --exe "cmd.exe" --username "Vinicius Massuchetto" -- "cmd" "/c" $WINPATH & | |
# Change window manager focus to VM | |
wmctrl -a "$VMNAME" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This older blog post gives a similar script and discusses how to integrate it into the XDG Desktop Linux environment