Using args[] for opening files

I guess you are saying yes to both of my questions.

Some references, related but likely unhelpful:

Cannot set Processing sketch as default program for opening .test files - Processing 2.x and 3.x Forum
I can't set a program as the default to open a filetype with in Windows 7 - Super User
My exported application won't run! - Processing 2.x and 3.x Forum

Assume you have your own defined file extension. I did my test using .axx and it is executed with an executable generated by Processing via export. The executable is called openWithDEMO.exe. This is what I did:

  1. Open cmd as administrator. One way is to click start/windows logo, type cmd and then press ctrl+shift+ENTER
  2. Then type assoc .axx=axxFiles
  3. Then type ftype axxFiles=C:\Users\kfrajer\Documents\Processing\CMsketches\untested\openWithDEMO\application.windows64\openWithDEMO.exe %1 %*

Now if I dbl click any .axx app, it opens the axx file with my executable app generated by Processing via export. This was tested in Windows 10. Two more things for you to consider:

  1. In the command prompt, type ftype /? to read some of the documentation related to this process.
  2. If you want your Processing exported application to open a file that is known by the current OS (Windows in this case), you will need to read more about it. For instance check this [post]{Pass command line arguments to Windows "Open With" - Super User} from another forum.

By the way, this is my testing code:


final String FILENAME = "c:\\mySandBox\\output.txt";

void setup() {
  size(400, 600);

  fill(255);
  strokeWeight(2);

  surface.setTitle(args==null?"No args":(args.length==0?"args.len=0":args[0]));
  openTab(args);
}

//===========================================================================
// OTHER FUNCTIONS:

void openTab(String[] path) {


  String[] lines = {"FAIL"};  //In case no argument is provided

  if (path!=null && path.length>0) {
    lines = path;
  }

  saveStrings(FILENAME, lines);
}

Kf

3 Likes