Open file using custom command: how to specify the file in cmd line?

5,430

Solution 1

Found blog entries about the same problem for Foxit reader and for PDF-XChange Viewer. None of them worked for me. So I edited them and got one tailored for my case:

#!/bin/bash  
Filename="z:${1//\//\\}"
wine "C:\Program Files\Tracker Software\PDF Viewer\PDFXCview.exe" $Filename

Save this bash script and open pdf using this script. Now double click pdf files will open them using PDF-XChange Viewer.

Solution 2

If the script works then you should accept that answer even though it was your own.

What has worked here for other apps as far as a custom command was close to what you were trying, some small differences.

wine "C:\Program Files\Tracker Software\PDF Viewer\PDFXCview.exe" Z:%f

Referenced here for photoshop with add. info on altering the display name if desired for right click use - http://ubuntuforums.org/showpost.php?p=9193687&postcount=9

Solution 3

This is based on @Flint's excellent script.

At first I tried "Z:"%U variable at the end of desktop file Exec= field for Wine programs. It worked fine until I opened a program without a file specified. Wine programs complained about missing file because the Exec= line pointed to the drive Z: which clearly is not a file but absolute file path instead. File not found: Z: or similar messages popped up in a Wine program. Bit annoying.

Problem with "Z:"%U is that it's not a conditional variable if Z: is used there. However, Wine absolutely requires Z: because it can't find correct file paths otherwise.

Your script makes the whole "Z:"%U thing a conditional clause. The script does the job exactly as I've wished for.

However, the script should consider all exe files written in uppercase, too. By now, it can't point any MS Office files (docx, pptx...) to MS Office 2010 because all program executables are written like WINWORD.EXE or POWERPNT.EXE. Of course executables could be renamed in lower case but I prefer more universal solution rather than renaming single exe's for every program.

Dirty and universal solution is to modify the script code like:

#!/bin/bash

allargs=("$@")

fixpath=0
for idx in "${!allargs[@]}"; do
    arg="${allargs[$idx]}"

    if [[ $fixpath -eq 0 ]]; then
        # fix file paths only after the first executable is found in arg
        if [[ "$arg" == *.exe ]]; then
            fixpath=1
        fi
        if [[ "$arg" == *.EXE ]]; then
            fixpath=1
        fi
        continue
    elif [[ $fixpath -eq 1 ]]; then
        # if arg starts with '/' and it's a path that exists on host
        # precede the path with drive 'Z:'
        if [[ "${arg:0:1}" == '/' && -e "$arg" ]]; then
            allargs[$idx]="z:${arg//\//\\}"
        fi
    fi
done

exec env "${allargs[@]}"

The or operator did not work for some reason. I'm sure there is a more elegant way to achieve same result, anyway.

Share:
5,430

Related videos on Youtube

Hosam.Yousof
Author by

Hosam.Yousof

your about me is currently blank

Updated on September 18, 2022

Comments

  • Hosam.Yousof
    Hosam.Yousof over 1 year

    I want to open PDF using PDF-XChange Viewer through WINE. How should I specify the pdf file name in the "custom command" line so that I can open a PDF file using PDF-XChange Viewer by double clicking it? I tried to use the \"z:%f\" following the suggestion here for using Foxit reader. But my PDF-XChange Viewer only starts with an empty window.

    wine "c:/Program Files/Tracker Software/PDF Viewer/PDFXCview.exe" \"z:%f\"
    

    I use Ubuntu 10.04 and WINE 1.2.2. PDF-XChange Viewer version 2.5.

    • RobotHumans
      RobotHumans about 12 years
      I suspect you need "c:/Program\ Files/Tracker\ Software/PDF\ Viewer/PDFXCview.exe"
    • Bruno Pereira
      Bruno Pereira about 12 years
      No, he does not, the "" are used for that...
    • Hosam.Yousof
      Hosam.Yousof about 12 years
      Bruno Pereira is right, I could actually start PDF-XChange Viewer if I double click on a PDF file. But the file is not opened, only the program is executed. Obviously the file name is not passed successively to the PDF viewer.
    • lukasz
      lukasz about 12 years
      Thiy this: wine `"C:\Program Files\Tracker Software\PDF Viewer\PDFXCview.exe" z:"%f"`
    • Hosam.Yousof
      Hosam.Yousof about 12 years
      @lukasz: the backticks cause the PDF viewer fail to even start.
  • Hosam.Yousof
    Hosam.Yousof about 12 years
    No, I did not have problem starting the pdf viewer. I guess I did not state the question clearly (I have revised the question now). I want to know how to specify input files in "custom command" s.t. when I double click a file it will be opened by pdfxcview.