Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: HOWTO: Associate filetypes with Windows(wine) applications

  1. #1
    Join Date
    Apr 2007
    Location
    New Zealand
    Beans
    894
    Distro
    Ubuntu 9.10 Karmic Koala

    HOWTO: Associate filetypes with Windows(wine) applications

    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:
    Code:
    #!/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.
    Last edited by weblordpepe; October 6th, 2007 at 11:28 AM.
    Brown doesn't suck. And neither does wood. Download Woody. A Metacity theme.
    Note: the rm command deletes stuff! Don't be tricked into running malicious scripts. If in doubt, ask!!

  2. #2
    Join Date
    May 2007
    Location
    Townsville, Australia
    Beans
    1,820
    Distro
    Lubuntu 14.04 Trusty Tahr

    Re: HOWTO: Associate filetypes with Windows(wine) applications

    awesome!!!

    i have been wondering if it could be done!!

    thanks so much
    Ubuntu user # 16304 www.nocleanfeed.com
    If someone asks you to sudo rm -rf anything, don't do it, and don't run any command with rm in it unless you know exactly what you're doing.things i have learnt changing from Xp pro to Ubuntu

  3. #3
    Join Date
    Apr 2007
    Location
    New Zealand
    Beans
    894
    Distro
    Ubuntu 9.10 Karmic Koala

    Re: HOWTO: Associate filetypes with Windows(wine) applications

    \m/
    Brown doesn't suck. And neither does wood. Download Woody. A Metacity theme.
    Note: the rm command deletes stuff! Don't be tricked into running malicious scripts. If in doubt, ask!!

  4. #4
    Join Date
    Jul 2007
    Location
    SLO Town, CA
    Beans
    532
    Distro
    Kubuntu 9.10 Karmic Koala

    Re: HOWTO: Associate filetypes with Windows(wine) applications

    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.

  5. #5
    Join Date
    Apr 2007
    Location
    New Zealand
    Beans
    894
    Distro
    Ubuntu 9.10 Karmic Koala

    Re: HOWTO: Associate filetypes with Windows(wine) applications

    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?
    Brown doesn't suck. And neither does wood. Download Woody. A Metacity theme.
    Note: the rm command deletes stuff! Don't be tricked into running malicious scripts. If in doubt, ask!!

  6. #6
    Join Date
    Jun 2009
    Beans
    3

    Re: HOWTO: Associate filetypes with Windows(wine) applications

    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!

  7. #7
    Join Date
    Jun 2009
    Beans
    3

    Re: HOWTO: Associate filetypes with Windows(wine) applications

    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
    Last edited by parmenpj; June 4th, 2009 at 08:18 PM.

  8. #8
    Join Date
    Apr 2009
    Beans
    19
    Distro
    Ubuntu 9.10 Karmic Koala

    Re: HOWTO: Associate filetypes with Windows(wine) applications

    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.

  9. #9
    Join Date
    Oct 2008
    Beans
    3

    Re: HOWTO: Associate filetypes with Windows(wine) applications

    @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.

  10. #10
    Join Date
    Nov 2007
    Beans
    51

    Re: HOWTO: Associate filetypes with Windows(wine) applications

    This simple script worked for me:

    Code:
    #!/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.

Page 1 of 2 12 LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •