How can I associate file types in desktop Linux with Windows 7 applications running through VirtualBox so they work seamlessly, starting VirtualBox if required?
I'm using KDE.
Current method
(example for Excel files):
Add a new entry in the start menu called "Excel"
- Command: /home/USER/bin/excelstarter.sh %f
- See below
- Launch feedback does not work well so it's disabled
Associate .xlsx files with "Excel" by right clicking and choosing run as...
- Remember application associations for all files of type ...
Mount relevant folders in VirtualBox
VirtualBox main window > Settings for machine > Shared folders:
- Add:
- Folder path: /data
- Auto mount
- Make permanent
- Add:
- Folder path: /home/USER
- Auto mount
- Make permanent
- Add:
Disable group policy restriction on empty passwords
Without this change VirtualBox will not run commands if no password has been set.
- Run gpedit.msc
Navigate to
Computer Configuration\Windows Settings\Security Settings\Local Policies\Security Options
Change
Limit local account use of blank passwords to console logon only to Disabled.
excelstarter.sh
The idea here is that this file takes care of starting VirtualBox if it is not already running, waiting for it to start up and then starts Excel with a filepath that has been translated to the corresponding mounts set up in VirtualBox.
# Start VM (if it is already started this does nothing)
VBoxManage startvm "win7_hilti"
# Replace folders with windows-local versions (mounts need to be setup)
# /data/ is mounted as F:
original=$1
findWhat=\/data/
replaceWith="F:\\"
fixedFilePath="${original/$findWhat/$replaceWith}"
# /home/USER/ is mounted as G:
original=$fixedFilePath
findWhat=\/home\/USER/
replaceWith="G:\\"
fixedFilePath="${original/$findWhat/$replaceWith}"
# Used for debugging the file paths
#notify-send $fixedFilePath
# Start Excel
# Try to run it until it the machine has started
until VBoxManage guestcontrol "VM-NAME" start --exe "C:\\Program Files\\Microsoft Office\\Office14\\EXCEL.EXE" --username WINDOWSUSER "excel" -- "$fixedFilePath"
do
# Sleep 1 gave the problem that the mounts were not yet ready, sleep 2 seems to work fine
sleep 2
done
Problems
- VirtualBox does not get focus if it was already running in the background.
- Ugly sleep in the loop while waiting for VirtualBox to start. Sleep 1 gave problems where the mounts were not yet set up. On a slower machine this value might need to be increased.
- Sometimes it does not start Excel after VirtualBox has started.