# How can i add a "Open with" function?

**URL:** <https://discourse.processing.org/t/how-can-i-add-a-open-with-function/41062>\
**Category:** Processing\
**Created:** [February 25, 2023, 5:16pm UTC](https://discourse.processing.org/t/how-can-i-add-a-open-with-function/41062 "2023-02-25T17:16:27Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![mnse](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/mnse/32/16520_2.png) [@mnse](https://discourse.processing.org/u/mnse)\
**Post date:** [February 26, 2023, 9:05am UTC](https://discourse.processing.org/t/how-can-i-add-a-open-with-function/41062/2 "2023-02-26T09:05:15Z")

</div>

Hi @Aryszin,

you mean by install that want to make an executable from your sketch ie. MySketch.exe on a specific location on disk ?

If so you can do for example the following to get the command line parameter on calling the sketch executable.

```auto
PImage myImage;
String myDefaultImageName = "noimage.jpg"; // should be a valid and existing image in data folder
String myImageName;

void settings() {
  if (args == null) {
    myImageName = myDefaultImageName;
  } else {
    myImageName = args[0];
  }
  myImage=loadImage(myImageName);
  if (myImage == null) {
    myImageName = myDefaultImageName;
    myImage=loadImage(myImageName);    
  }
  size(myImage.width, myImage.height);
}

void setup() {
  surface.setTitle(myImageName);
}

void draw() {
  image(myImage, 0, 0);
}

```

Assuming you already have build the executable from your sketch and it processes the command line argument similar as shown above, you can start your sketch executable by  
`...\MySketch.exe <full_path_to_image>`.

_Please note that you need to set the working directory to your MySketch.exe path otherwise it wouldn’t start the MySketch.exe properly. For that it could be necessary to wrap everything in a batch file to make a cd before calling the executable_

ie run.bat content:

```auto
cd /D <path_to_MySketch.exe>
MySketch.exe %1

```

Hope that helps …

Cheers  
— mnse

Examples  
`run.bat`  
 ![example1](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/3X/8/0/8088e28eb78ac0662fb2a467c7eb2893b72641bf.png)

`run.bat <path_to_processing_logo>`

 ![example2](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/3X/e/6/e621a63e031b8771bcf4adc12199416a3e98f133.png)

PS: Error handling could be refined to your needs (ie. exit if not a valid image instead of showing noimage)

PPS: if you don’t want to create an executable but want to call the sketch by processing-java.exe, you can call the above example by …

```auto
<path_to_processing>\processing-java.exe --sketch="<path_to_your_sketch_folder>" --run "<path_to_the_image_file>"

```

---

_[View the full topic](https://discourse.processing.org/t/how-can-i-add-a-open-with-function/41062)._
