3

I want files ending in .fw.png to open in Adobe Fireworks but I want regular .png files to open in my standard image viewer program.

Is this possible?

2
  • 1
    To all voting to close: Initially I thought this question was an exact duplicate, but upon further review, the question being asked does differ significantly enough to warrant a new question. Dec 13, 2011 at 12:56
  • Not a dupe. Suggested question is for files with exactly the same extension; this is different.
    – Hello71
    Dec 17, 2011 at 23:40

1 Answer 1

7

Using an AutoIt script, the following should perform what you want:

$FIREWORKS = "C:/Program Files/Fireworks.exe"
$NORMALVWR = "C:/WindowsPictureViewer.exe"

If $CmdLine[0] > 0 Then
    $toRun = ""
    $fExt = StringRight($CmdLine[1], 7)

    ; First, we set $toRun as the proper target program to run.
    If StringLen($CmdLine[1]) >= 7                  And _
       StringRight($fExt, 4) = ".png"               And _
       StringLeft(StringRight($fExt, 7), 3) = ".fw" Then
        $toRun = $FIREWORKS
    Else
        $toRun = $NORMALVWR 
    EndIf

    ; Next, we append all command line arguments (with a space before each one).
    For $i = 1 To $CmdLine[0]
        $toRun &= ' "' & $CmdLine[$i] & '"'   ; We surround each with quotation marks.
    Next

    ; Finally, run the command in the current working directory.
    Run($toRun, @WorkingDir)
    ; Since the Run() function is asynchronous, this program should close right after.
EndIf

To make this work for your case, you'll need to change those constants up at the top to the proper executables you want to launch. Then, install AutoIt, and compile the script to a .EXE file. Place it in a convent location, and set Windows to open .PNG files with this executable.

I haven't tested this code yet, but it looks like it should work fine. Just for your reference, the compiled program will do the following:

  1. Check if the first argument (if it exists) ends in .fw.png (it is assumed you only run the executable with a .PNG to begin with). If so, the Fireworks executable is launched, otherwise, the normal viewer is launched.

  2. All of the command line arguments are then added again as arguments to the respective application.

  3. The application is called via the AutoIt Run() function, in the current working directory.


If enough people are interested, I can create a full program to do this for any arbitrary set of (nested) file extensions.

2
  • You have a syntax error on line 9, there's a stray close paren after "StringLen($CmdLine[1]) >= 7". Other than that it compiles and works like a charm, thanks.
    – Rob
    Jul 25, 2015 at 10:25
  • @Rob good catch, thank you - I've updated the answer accordingly. Jul 27, 2015 at 1:45

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .