Open in Linux from Win guest

Discuss and share scripts and script files...
Post Reply
p85
Posts: 17
Joined: 29 Aug 2014 11:07

Open in Linux from Win guest

Post by p85 »

Hi,

I've switched to Linux with Windows XP in Virtualbox and Xyplorer doesn't work well for me under Wine. So I created this workaround to open files with their right applications.

Note: I'm a newbie in Linux and these programming languages, so please be gentle with me. I know the writing's awful and there should be neater ways to do this, but I’m just happy it’s working, FINALLY. :). Corrections and suggestions are always appreciated, of course.

Requirements:
- Auto capture keyboard in Virtualbox must be disabled.
- Download nircmd or implement some other sendkey windows applications
- Shared folders must be set up such that the drive letter in Windows can be translated to folder in Linux (here: F:\ corresponds to /mnt/F/)
- Obviously change paths, username, preferences, etc. according to your system.

1) Create this script in Linux:

Code: Select all

#create empty helper file
>"/mnt/F/My Files/Various/LinuxTempFiles/DONE.txt";
#simulate keyboard shortcut in Windows
vboxmanage guestcontrol "XP" run --exe "C:\RunOpenWithLinuxFromLinux.bat" --username XXX –password XXX --wait-stdout;
#wait max. 60 seconds for the script to finish 
for i in {1..60}
do
	if [ -s "/mnt/F/My Files/Various/LinuxTempFiles/DONE.txt" ]
	then
		break
	else
		sleep 1
	fi
done
#if playlist isn't empty open it with VLC
if [ -s "/mnt/F/My Files/Various/LinuxTempFiles/VLCPlaylist.m3u" ]
then
	vlc '/mnt/F/My Files/Various/LinuxTempFiles/VLCPlaylist.m3u' &
fi
#open the other files
python3 '/mnt/F/My Files/Various/LinuxTempFiles/LinuxOperations.py'
(Note: writing a playlist of some 4700 files took about 30 seconds for me, but vlc wasn’t too thrilled)

2) Assign a system-wide shortcut to this script.

3) Create C:\Programme\XYplorer\Data\Scripts\OpenInLinux.xys

Code: Select all

$currentlyselecteditems = <get selecteditemspathnames>;
 End $currentlyselecteditems == '';

//Change to your preferred location
 $pathofplaylist = "F:\My Files\Various\LinuxTempFiles\VLCPlaylist.m3u";
 $pathofpyfile = "F:\My Files\Various\LinuxTempFiles\LinuxOperations.py";
 $pathDONE = "F:\My Files\Various\LinuxTempFiles\DONE.txt";

//Reset playlist and py file
 writefile($pathofplaylist,"", o, t);
 writefile($pathofpyfile, "", o, t);
 $pathsforplaylist= "";
 $pathsfordefaultapplications= "";

//Loop through selected files:
 foreach($item, $currentlyselecteditems , <crlf>, , "") {
    $standardprogram = get("regcmd", getpathcomponent($item, "ext"));		//get standard application in Windows
    $path= "/mnt/" . substr($item,0,1) . "/" . replace(substr($item,3),"\","/") ;	//convert Windows path to Linux path
    if $standardprogram Like "*PotPlayer*" {
	//audio/video file → add to playlist
       $pathsforplaylist = $pathsforplaylist. $path . <crlf> ;
    }
    elseif $standardprogram Like "*EXCEL*" {
	//open Excel files in Windows
       open $item;
    } 
    else {
	//open anything else in Linux standard application
       $pathsfordefaultapplications = $pathsfordefaultapplications . "os.system('xdg-open " . """" . $path . """" . "')" . <crlf> ;
    }    
    } 

//Write files
 writefile($pathofplaylist, utf8encode($pathsforplaylist), o, t) ;
 if $pathsforplaylist <> "" {
    writefile($pathofpyfile, utf8encode("import os" . <crlf> . $pathsfordefaultapplications), o, t);
 } 

//indicate that script is finished
 writefile($pathDONE,"DONE", o, t);
4) Assign a shortcut to C:\Programme\XYplorer\Data\Scripts\OpenInLinux.xys in Xyplorer (here z)

5 Create C:\RunOpenWithLinuxFromLinux.bat with

Code: Select all

"C:\Programme\XYplorer\Data\Scripts\nircmd.exe" sendkey z press
(replace z with your Xyplorer shortcut)


Now, select files in Xyplorer, run the 2) shortcut and the files should be opened in the right programs (I hope I didn’t forget anything, there was a lot of trial and error :oops: ). Unfortunately, changing between Xyplorer and host seems to trigger a right click which is a bit of an annoyance.

Let me know what you think.

Post Reply