PDA

View Full Version : HOWTO: Associate filetypes with Windows(wine) applications


weblordpepe
October 2nd, 2007, 12:37 PM
What is needed:
Hello guys. I found it nessecary to have an icon on my desktop for Irfanview, which I could drag pictures onto and have them load. Or simply double-click on a picture, and have it load in IrfanView.
This is a problem with any Windows app, but today Matthew we will be using IrfanView.

Why it cant normally be done
The problem is that Irfanview is a Windows program, and you can't pass linux filepaths to Windows programs unless you convert them with winepath.

The end result
The end result after this HOWTO, is a icon on the desktop which launches Irfanview(in wine) when clicked, and I can also drag files onto it. Also, I have .gif files associated with Irfanview.

How to do it
This is done by having a quick script which accepts normal linux filepath arguments, and creates a SH script on the fly to convert it to a Windows-friendly path and launch IrfanView With it.

You then simply put a launcher to it on your desktop. And you can even register filetypes to open with the script.

So here is the script. Save it where ever. In this example it is ~/irfanview.sh:
#!/bin/sh
# This is a script to allow a launcher to open Irfanview with a file dragged onto it.
# It uses winepath -w to convert the file's path to the Windows version, and then
# creates a simple sh script to launch wine/irfanview/document with the correct syntax.

# Note: Yes I know the constructed shell script doesnt have #!/bin/sh at the beginning.
# Im not that good, and hey it works. So shoosh
#
#
# By Weblordpepe. Oct 3, 2007. 5:10am.
# (Finished: Oct 6, 2007. 11:25pm)


# Report to console the file wanted, clear temporary files.
rm -f ~/.wine/iprog3 ~/.wine/iprog2 ~/.wine/iprog


# Display to user whats going on
echo ---
echo Loading $1- into Irfanview.
echo Make Pepe a SANDWICH!
echo ---

# Begin command line making:
# Output (to text file) the command to launch Irfanview under Wine.
echo -n wine /usr/local/IrfanView/i_view32.exe\ >> ~/.wine/iprog

# Output Windows version of the file path to the same text file.
echo -n "\\042" >> ~/.wine/iprog # First doublequotes
winepath -w "$1" |tr 'h:' 'H:' | tr 'z:' 'Z:' >> ~/.wine/iprog # Replace lowercase driveletter to uppercase and output to file.
echo -n "\\042" >> ~/.wine/iprog # Second doublequotes

# Create new textfile but delete all 'new lines's so its all on one line.
less ~/.wine/iprog | tr -d '\n' >> ~/.wine/iprog2

# End of command file making


# Run the file text file which includes instruction to run Irfanview under wine with
# the Windows filepath on the end.
sh ~/.wine/iprog2

# clean up
rm -f ~/.wine/iprog3 ~/.wine/iprog2 ~/.wine/iprog

Now what you want to do is create a launcher on the desktop. I've only done this with Gnome. So KDE guys try it out & lemme know.

Create a launcher (type: application) on the desktop, and call it anything you like. The command should be gksu -u dork /home/dork/irfanview.sh where dork is your username. I think there's also a variable you can use.

There you have it. An icon you can drop files onto and have them loaded with Irfanview, or another Windows app.

To associate files, just right click any file, go to Properties, then 'Open With' and create a new entry. Select 'custom command' and put in sh /home/dork/irfanview.sh or wherever you've put the file.


And thats it. Filetypes opening with a windows application. No doubt there's a much easier way that I'm not aware of. But eh, it works so I'm happy. :guitar:

stinger30au
November 3rd, 2007, 07:20 PM
awesome!!!

i have been wondering if it could be done!!

thanks so much

weblordpepe
November 3rd, 2007, 11:28 PM
:guitar: \m/

TeaSwigger
November 5th, 2007, 01:57 AM
Hello weblordpepe, I'm posting to thank you for the script and to tell you that I've adapted it to open KeyNote (the note manager) documents and it's working perfectly well in Kubuntu. :)

weblordpepe
November 5th, 2007, 08:21 AM
Awesome! Thats what I like to hear! This script could easily be modified to launch any program. Just by parsing another argument on the command line.

eg:

runprogram.sh /usr/local/irfanview/i_view32.exe /home/dork/picture.jpg

What do you think?

parmenpj
June 4th, 2009, 02:17 AM
This line (note that I changed drive letter "H" to "C" to match my system):
winepath -w "$1" | tr 'c:' 'C:' | tr 'z:' 'Z:' >> ~/.wine/iprog # Replace lowercase driveletter to uppercase and output to file.

Should be:
winepath -w "$1" | sed s/c:/C:/g | sed s/z:/Z:/g >> ~/.wine/iprog # Replace lowercase driveletter to uppercase and output to file

This is because sed is successful in replacing the phrase "c:" with "C:", but tr instead replaces all instances of "c" with "C", "z" with "Z", etc., and does not recognize the phrase "c:", "z:", etc.

This is not causing problems most of the time, because Wine/Windows pathnames are case-insensitive - but you never know when a problem may arise.

Another thing I found:
On my Kubuntu system, Wine is in a different location so this line:
echo -n wine /usr/local/IrfanView/i_view32.exe\ >> ~/.wine/iprog

Becomes:
echo -n wine "/home/parmenpj/.wine/drive_c/Program\ Files/IrfanView/i_view32.exe"\ >> ~/.wine/iprog

Note here that "\" is needed to precede the space in "Program Files", and because there is a space the entire pathname must also be in quotes.

Hope this helps more people use this GREAT IDEA! Thank you!

parmenpj
June 4th, 2009, 03:12 PM
Your efforts ROCK. Thanks again. FYI - I found a very small script on https://help.ubuntu.com/community/Wine. Way cool and fast:#!/bin/sh

QUICKPARLOCATION="c:\\Program Files\\IrfanView\\i_view32.exe"
PARAM=`winepath -w "$*"`
wine "$QUICKPARLOCATION" "$PARAM"
exit 0

kimharding
November 25th, 2009, 07:30 AM
Have anyone got this working with Karmic? I had it working beautifully under Jaunty but since I upgraded to Karmic it hasn't been working. :-(

skidmarks
February 2nd, 2010, 03:02 AM
@parmenpj - Great find!

That little script is just what I was looking for. I thought there'd be a nice simple way to do this.

@kimharding - works fine for me under karmic.

avada
May 11th, 2010, 08:15 AM
This simple script worked for me:

#!/bin/bash

torrent_path=`winepath -w $1`

wine "/media/***Path to utorrent***/utorrent.exe" $torrent_path

What I don't know how to do is to get the icon of utorrent.exe for the quick launch icon...
Kind of annoying to have a bunch of blank icons for the windows programs.

MestreLion
August 7th, 2011, 11:45 PM
This simple script worked for me:

#!/bin/bash

torrent_path=`winepath -w $1`

wine "/media/***Path to utorrent***/utorrent.exe" $torrent_pathWhat I don't know how to do is to get the icon of utorrent.exe for the quick launch icon...
Kind of annoying to have a bunch of blank icons for the windows programs.

When you install an app via wine it automatically extracts icons from the .EXE, converts them to .PNG, and places them in ~/.local/share/icons/hicolor/SIZE/apps (where SIZE=16x16, 32x32, etc)

If youre running uTorrent without installing, you can extract the icon yourself using gExtractWinIcons (its a nice app avaliable in repositores)