Ubuntu Forums ubuntu.com - launchpad.net - ubuntu help  

Go Back   Ubuntu Forums > The Ubuntu Forum Community > Other Community Discussions > Tutorials & Tips
Register Reset Password Forum Help Forum Council Search Today's Posts Mark Forums Read

Tutorials & Tips
The place to find Ubuntu related Tips & Tricks.

 
Thread Tools Display Modes
Old October 2nd, 2007   #1
weblordpepe
Extra Foam Sugar Free Ubuntu
 
weblordpepe's Avatar
 
Join Date: Apr 2007
Location: New Zealand
Beans: 849
Ubuntu 7.10 Gutsy Gibbon
Send a message via MSN to weblordpepe
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.
__________________
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!!

Last edited by weblordpepe; October 6th, 2007 at 06:28 AM..
weblordpepe is offline   Reply With Quote
Old November 3rd, 2007   #2
stinger30au
Chocolate Ubuntu Mocha Blend
 
Join Date: May 2007
Location: Townsville, Australia
Beans: 1,764
Ubuntu 9.10 Karmic Koala
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
stinger30au is offline   Reply With Quote
Old November 3rd, 2007   #3
weblordpepe
Extra Foam Sugar Free Ubuntu
 
weblordpepe's Avatar
 
Join Date: Apr 2007
Location: New Zealand
Beans: 849
Ubuntu 7.10 Gutsy Gibbon
Send a message via MSN to weblordpepe
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!!
weblordpepe is offline   Reply With Quote
Old November 5th, 2007   #4
TeaSwigger
Dipped in Ubuntu
 
TeaSwigger's Avatar
 
Join Date: Jul 2007
Location: SLO Town, CA
Beans: 532
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.
TeaSwigger is offline   Reply With Quote
Old November 5th, 2007   #5
weblordpepe
Extra Foam Sugar Free Ubuntu
 
weblordpepe's Avatar
 
Join Date: Apr 2007
Location: New Zealand
Beans: 849
Ubuntu 7.10 Gutsy Gibbon
Send a message via MSN to weblordpepe
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!!
weblordpepe is offline   Reply With Quote
Old June 4th, 2009   #6
parmenpj
First Cup of Ubuntu
 
Join Date: Jun 2009
Beans: 2
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!
parmenpj is offline   Reply With Quote
Old June 4th, 2009   #7
parmenpj
First Cup of Ubuntu
 
Join Date: Jun 2009
Beans: 2
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 03:18 PM..
parmenpj is offline   Reply With Quote
Old November 25th, 2009   #8
kimharding
5 Cups of Ubuntu
 
Join Date: Apr 2009
Beans: 17
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.
kimharding is offline   Reply With Quote

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 12:28 AM.


vBulletin ©2000 - 2010, Jelsoft Enterprises Ltd. Ubuntu Logo, Ubuntu and Canonical © Canonical Ltd. Tango Icons © Tango Desktop Project. bilberry