Jump to content

Parameters passed to programs by file associations


Recommended Posts

Thanks for the suggestion. I just tried it, and it still tried to open the file called "%1".

 

I am suspecting that there is a special KDE protocol to get the file name to the app, and the Windows app does not understand it. The entry for the GIMP has no arguments on the command line at all, and yet it somehow figures out the name of the file to open.

 

Banjo

(_)=='=~

Link to comment
Share on other sites

  • 1 month later...

I too am a big fan of IrfanView and have struggled with this problem. I'm not a bash or KDE person, but here's a solution that works on my SuSE 10 machine and should work in bash on other distros I think.

 

The problem is the conversion of / to \. I set up the command in KDE specifying a file - say, wine "p:\somepath\Irfanview.exe" z:\home\rdh\mypick.jpg - and it displayed the file just fine.

 

I tried a bunch of different ways of passing the file name argument to Irfanview via KDE's File Associations (which is what Konqueror uses) - %U, %1, %f, etc. I tried adding comand line pipes and stuff (| tr / \), but none of them worked.

 

[bTW, here's how to get a list of the various % variables. Start File Associations in KDE (KDE Control Panel, KDE Components, File Associations). Then selectg the type you want (jpeg, say). Then select the appliction you want in the list on the left (in Application Preference Order) (or Add it to the list). Click Edit. Click on the Application tab. Click on the ? in title bar up on the right - the cursor changes to a pointer plus question mark. Point at the Command area - the pop-up box will tell you what % combos are.]

 

So I went back to the suggestion made earlier - do it through a script. Now, forgive me if I over-explain the script - I got the impression that some here aren't that familiar with them (not that I am).

 

First, I created the script - it's just a short text file - six lines including comments:

 

#!/bin/sh

# Purpose: To convert Unix filename to DOS style to pass as an argument

# to wine when starting IrfanView from KDE.

#

FileName="z:"${1//\//\\}

wine "C:\Program Files\Irfanview\i_view32.exe" $FileName

 

 

I saved the file as /home/[my home directory]/launchIrfanView.sh.

 

Here's what the script does. The first uncommented line (no #) creates the script variable FileName. My wine install includes a mapping for z: to my root directory - in my case, "z:" equals / I will tell KDE (below) to pass the absolute path and file name (i.e. starting at /), so that's the same as "z:" to wine.

 

The ${1//\//\\} bit is a string substitution command to bash - it says "take the first command line argument and replace the next character, the /, with two characters, //" The extra /\ is in there (for those who may be following) is to escape the \. The result is assigned to FileName. The \ character is duplicated because it would get stripped out otherwise.

 

The next line calls wine and IrfanView, and passes what's in FileName to it. (When you create the shell variable FileName, you don't use the $ in front - when you refer to it later, you do.)

 

To use the script, I took out the reference to "wine IrfanView" in the Applicaton Preference Order in KDE File Associations. I clicked Add, and browsed to the script file: /home/[my home directory]/launchIrfanView.sh, so it became the Command.

 

Finally, I added %f after /home/[my home directory]/launchIrfanView.sh in the Command, to pass the file's absolute path and file name to the script.

 

I found the launch feedback annoying, so I turned it off, by clicking the Advanced Options button, and then clearing the check box next to Enable launch feedback in the Startup section.

 

Click Okay to change the system configuration, then Apply to change the File Associations, and all should be well.

 

I'm sure some clever shell programmer can make this better, but I hope it's a start . . .

 

daveh

 

 

Thanks for the suggestion. I just tried it, and it still tried to open the file called "%1".

 

I am suspecting that there is a special KDE protocol to get the file name to the app, and the Windows app does not understand it. The entry for the GIMP has no arguments on the command line at all, and yet it somehow figures out the name of the file to open.

 

Banjo

(_)=='=~

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...