1

I want to be able to open files in Linux host (with double click) in an application installed in Windows guest in Oracle VirtualBox.

Details: I have myfile.docx in ~/Documents folder in Linux host and MS Word application installed a Windows guest OS. The directory ~/Documents is also mounted in Windows guest under Y:\ path with full read-write access. I have also setup the Windows guest to work in seamless mode with Linux host (which is so much attractive part of VBox).

Now once I start the Windows guest, I don't want to bother about it anymore. I just want to double click on myfile.docx in Linux host so that it opens in MS Word, that's all! (Let's not bother where this MS Word comes from).

In fact, as a first step, I got a partial success in opening myfile.docx with the following command in Linux host terminal:

VBoxManage guestcontrol "Win07" run --exe "C:\\Program Files (x86)\\Microsoft Office\root\\Office16\\WINWORD.EXE" --username sbnwl --password myPassword -- WINWORD/arg0 "Y:\myfile.docx"

The file instantly opens in MS Word. Perfect! Note that the argument at the end of the above command ("Y:\myfile.docx") requires Windows style absolute path.

Now I am trying to make a desktop configuration file in the path ~/.local/shrare/applications with the following content:

[Desktop Entry]
Version=1.0
Encoding=UTF-8
Type=Application
Name=word
NoDsiplay=true
Exec=VBoxManage guestcontrol "Win07" run --exe "C:\\Program Files (x86)\\Microsoft Office\root\\Office16\\WINWORD.EXE" --username sbnwl --password myPassword -- WINWORD/arg0 HOW-TO-SUPPLY-WINDOWS-STYLE-PATH-TO-THE-FILE-BEING-DOUBLE-CLICKED? 
Name[en]=Word
Icon=/usr/share/icons/word.png

Does somebody know how to accomplish this argument at the end of line staring with Exec= ??

  • Which is the argument to be transformed? – ctrl-alt-delor Feb 14 at 22:50
0

It looks like you have done the main bit. Now you need to transform the name. I would recommend writing a script. Have your desktop entry start the script, with the Unix file-name, then have the script transform the name, and call VBoxManager (as you did in your example).

sed is your friend in the transform.

0

Thanks to everybody who looked into here and commented...

Managed to click-open host files with guest application. It's a fantastic experience now onward on Linux host using virtualbox.

Here is the complete Solution !!!

The steps are summarized as follows:

STEP1--> ENSURE THE FOLLOWING REQUIREMENTS ARE MET:

  1. THE FILES to be opened ARE ON THE HOST LINUX FILESYSTEM (SUB-DIRECTORIES also supported)
  2. THE host's Documents DIRECTORY IS MOUNTED AS Y:\ IN THE WINDOWS GUEST (preferably with write permissions)
  3. THE host's Downloads DIRECTORY IS MOUNTED AS Z:\ IN THE WINDOWS GUEST (preferably with write permissions)
  4. THE host's $HOME directory IS MOUNTED AS X:\ IN THE WINDOWS GUEST (prefer with read-only permissions)

STEP2--> YOU NEED TO CREATE A DESKTOP ENTRY FILE named 'Word.desktop' (without quotes), WITH FOLLOWING CONTENTS, IN THE $HOME/.local/share/applications PATH:

[Desktop Entry]
Version=1.0
Encoding=UTF-8
Type=Application
Name=Word 365
NoDsiplay=true
Exec=$HOME/.local/share/applications/muScripts/runWord %u
Name[en]=Word 365 ProPlus
Icon=/usr/share/icons/MSWord.png

In the above substitute $HOME with the userpath, for example /home/user

STEP3--> MAKE AN EXECUTABLE FILE NAMED 'runWord' (without quotes), WITH THE FOLLOWING CONTENTS AND PLACE IT IN THE DIRECTORY $HOME/.local/share/applications/muScripts/

#!/bin/bash

# THIS PROGRAM (runWord) OPENS *.docx FILES ON LINUX HOST, WITH MS Word APPLICATION
# INSTALLED ON A WINDOWS GUEST (IN VirtualBox).

## STEP1--> CHECK FOLLOWING REQUIREMENTS ARE MET:
# 1. THE FILES ARE EITHER IN Documents OR Downloads OR any other DIRECTORY/SUB-DIRECTORY 
#    OF THE HOST FILESYSTEM (SUB-DIRECTORIES also supported)
# 2. THE host's Documents DIRECTORY IS MOUNTED AS Y:\ IN THE WINDOWS GUEST (preferably with write permissions)
# 3. THE host's Downloads DIRECTORY IS MOUNTED AS Z:\ IN THE WINDOWS GUEST (preferably with write permissions)
# 4. THE host's     $HOME directory IS MOUNTED AS X:\ IN THE WINDOWS GUEST (prefer with read-only permissions)

## STEP2--> YOU NEED TO CREATE A DESKTOP ENTRY FILE WITH FOLLOWING CONTENTS, IN THE
# $HOME/.local/share/applications PATH:
#
#[Desktop Entry]
#Version=1.0
#Encoding=UTF-8
#Type=Application
#Name=Word 365
#NoDsiplay=true
#Exec=/home/hostuser/.local/share/applications/muScripts/runWord %u
#Name[en]=Word 365 ProPlus
#Icon=/usr/share/icons/MSWord.png
#

## STEP3--> PLACE THIS FILE IN THE DIRECTORY $HOME/.local/share/applications/muScripts/

#
##--CODE DEVELOPERS/CONTRIBUTORS -- andpy73, sbnwl
##-- andpy73 https://forums.virtualbox.org/memberlist.php?mode=viewprofile&u=50134
##-- sbnwl https://forums.virtualbox.org/memberlist.php?mode=viewprofile&u=116543
##-- Original post at https://forums.virtualbox.org/viewtopic.php?f=7&t=91799
#

clear

#
# Check that we have got the correct number of parameters.
#
if [ "$#" -ne 1 ]; then
   echo "Warning: Remote script requires one parameter to be passed!"
#   exit
fi

#
# Check if the file exists in the host file system incase we are
# called from a terminal.
#
if [ ! -f "$1" ]; then
   echo "Warning: File not found in the host file system!"
   echo '         Make sure the file' $1 'exists!'
#   exit
fi

#
# Get the filename part from the full path given.
#
FILE=$(basename "$1")
nixPATH=$(dirname "$1")
echo 'Full UNIX path is:' $nixPATH

echo 'Opening' $FILE ' ...'
echo 'Full UNIX path of the file is:' $1

#
# Make a new executable file having WINDOWS_PATH as argument at the end of 
# VBoxManage command and write the command sting in it.
#
mkdir ~/.tmp
cd ~/.tmp
rm tmpfile
touch tmpfile
chmod +x tmpfile
printf 'VBoxManage guestcontrol "Win10" run --exe "C:\\Program Files (x86)\\Microsoft Office\\root\\Office16\\WINWORD.EXE" --username myWindowsUsername --password myWindowsPassword -- WINWORD/arg0 ' >> tmpfile

if [[ $1 == "$HOME/Documents/"* ]]; then
   echo "The file is in Documents folder, i.e., in Y:\ of Windows host!"
   prefix="$HOME/Documents"
   partPATH=${nixPATH#"$prefix"}
   echo 'Partial UNIX path is:' $partPATH
   winPATH=${partPATH//\//\\}
   echo 'Partial WINDOWS path is:' $winPATH
   echo 'Full WINDOWS path is:' '"'Y:\\$partPATH\\$FILE'"'
   echo '"'Y:\\$partPATH\\$FILE'"' >> tmpfile

elif [[ $1 == "$HOME/Downloads/"* ]]; then
   echo "The file is in Downloads folder, i.e., in Z:\ of Windows host!"
   prefix="$HOME/Downloads"
   partPATH=${nixPATH#"$prefix"}
   echo 'Partial UNIX path is:' $partPATH
   winPATH=${partPATH//\//\\}
   echo 'Partial WINDOWS path is:' $winPATH
   echo 'Full WINDOWS path is:' '"'Z:\\$partPATH\\$FILE'"'
   echo '"'Z:\\$partPATH\\$FILE'"' >> tmpfile

else
   echo "The file is elsewhere, i.e., in X:\ of Windows host! (If $HOME is mounted as X:\)"
   prefix="$HOME"
   partPATH=${nixPATH#"$prefix"}
   echo 'Partial UNIX path is:' $partPATH
   winPATH=${partPATH//\//\\}
   echo 'Partial WINDOWS path is:' $winPATH
   echo 'Full WINDOWS path is:' '"'X:\\$partPATH\\$FILE'"'
   echo '"'X:\\$partPATH\\$FILE'"' >> tmpfile
fi

#
# Show the contents of tmpfile (for only debugging purpose)
#
echo '-------------------------------------------------------------------------'
echo 'This is the content of tmpfile for debugging purpose:'
echo ' '
cat tmpfile
echo ' '
echo '-------------------------------------------------------------------------'

#
# Run the commands in tmpfile for opening the double-clicked file!
#
./tmpfile &
rm tmpfile

Please make sure you make the following changes in the above script file in one particular line starting with printf 'VBoxManage guestcontrol

  1. Replace the string Win10 with the name of your Windows Guest virtual-machine having MS Office installation.
  2. Replace myWindowsUsername with your login username on Windows Guest OS
  3. Replace myWindowsPassword with your login password on Windows Guest OS

STEP4--> ASSOCIATE THE *.docx AND .doc FILES IN HOST FILESYSTEM WITH THE PROGRAM 'Word'. HERE IS HOW TO DO SO: 1. Go to any file MS Word file (.docx) in the Linux host file manager (such as nautilus, nemo, dolphin etc.) 2. Right click on *.docx file and click on 'properties' in the contextual menu. A window will pop up. 3. Click on 'Open With' tab and scroll through a list of available applications. Select 'Word 365 ProPlus' and click 'Set as default' in the bottom right corner of the window.

That's all!

The next time just start the Windows machine in the virtualbox in seamless mode (Press CTRL+L after login) and forget about it.

All you need to do is to directly double-click your *.docx files in the Linux file manager.

And Voila, they will immediately open in the MS Word application.

  • OK, you're happy; we get it.   Please don't SHOUT. – G-Man Apr 2 at 3:26
  • Thanks man.. No shouting.. – user399146 Apr 2 at 3:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.