How can I include an editable config file with a sketch exported for OSX?

My sketch has a configuration file in the "data" folder. The user should be able to edit settings used by the sketch.

When exported for Windows this data folder is plainly visible and the config file is there for editing.

However, when exporting on OSX there is no visible data folder. Seems everything gets bundled into a jar.

What's the best way to set up a sketch such that is uses an editable config file, and that config file is exposed for editing when the sketch is exported on OSX? (I assume the same approach would work on Windows since Processing is not jarring all the files as it does on OSX.)

Thanks!

Tagged:

Answers

  • So far, playing around, I find this is usable:

     `String config_path = sketchPath + "/config.jsi";`
    

    and pass that to the code that needs to load the config file.

    After exporting the sketch on OSX I can then copy "config.jsi" into the same folder that has the .app folder and it seems to work OK. __ Downside is that the config file has to be copied by hand, so the next step would be a command-line script that does the export and the copying.

  • _vk_vk
    edited June 2015

    in osx the files are bundled in a package. if you right click in it there is "show package contents" that will lead to your config file, i think...

  • forgot the picture... Screen Shot 2015-06-25 at 12.07.44 AM

  • Very weird. I had been looking in the app folder and never finding the data folder or the config file, but now when I try it out I find them in application.macosx\.app\Contents\Java

    So it's available.

    OTOH I'm happy I poked around because getting to that file is a bit awkward because of how OSX uses "magic folders" as application packaging.

    So I think I will use files in the program root for easier access (while I look into making config management fit each platforms conventions).

    Thanks.

  • _vk_vk
    edited June 2015

    while I look into making config management fit each platforms conventions

    I think, in a mac that would be to store your config file in some place like ~/Library/Application Support or ~/Library/Preferences. But this is not much better than the package is it?

    Perhaps you can provide a UI to set those configs inside the program itself...? Then saving in a hided place would be no problem...

  • I'm thinking that, if I were to put any effort into this, I should have the app handle the loading and editing of the config. It's a fairly simple text file, so a dumb text "editor" shouldn't be hard to arrange, and then it can read and write from the default "data" folder. The user never needs to know the location.

    Otherwise the sketch would need to know the OS, and do something different.

    I like the idea of config files being in standard locations and users able to easily use whatever text editor they prefer, but the code overhead isn't worth it.

    I wonder if I could instead launch a native "File|open" dialog. Then get users can use whatever text editor they like.

    https://processing.org/reference/open_.html

    I'll have t try this out.

  • Otherwise the sketch would need to know the OS, and do something different.

    That's easy :)

    void setup() { 
      size(255, 255);  
      prt("file.separator"); 
      prt("java.class.path");
      prt("java.home"); 
      prt("java.vendor"); 
      prt("java.vendor.url"); 
      prt("java.version"); 
      prt("line.separator"); 
      prt("os.arch"); 
      prt("os.name"); 
      prt("os.version"); 
      prt("path.separator"); 
      prt("user.dir"); 
      prt("user.home"); 
      prt("user.name");
    }
    void prt(String infoToGet) {  
      println(infoToGet+ " > "+System.getProperty(infoToGet));
    }
    
  • _vk_vk
    edited June 2015

    Even more properties...

    void setup(){
     String[] properties = loadStrings("propertiesNames.txt");
    
      for(String p:properties){
        println(p + " --> " + System.getProperty(trim(p)));
      }
    
    }
    

    And this is the "propertiesNames.txt" :

    java.runtime.name
    sun.boot.library.path
    java.vm.version
    user.country.format
    gopherProxySet
    java.vm.vendor
    java.vendor.url
    path.separator
    java.vm.name
    file.encoding.pkg
    user.country
    sun.java.launcher
    sun.os.patch.level
    java.vm.specification.name
    user.dir
    java.runtime.version
    java.awt.graphicsenv
    java.endorsed.dirs
    os.arch
    java.io.tmpdir
    line.separator
    java.vm.specification.vendor
    os.name
    sun.jnu.encoding
    java.library.path
    sun.awt.enableExtraMouseButtons
    java.specification.name
    java.class.version
    sun.management.compiler
    os.version
    http.nonProxyHosts
    user.home
    user.timezone
    java.awt.printerjob
    java.specification.version
    file.encoding
    user.name
    java.class.path
    apple.awt.graphics.UseQuartz
    java.vm.specification.version
    sun.arch.data.model
    java.home
    sun.java.command
    java.specification.vendor
    user.language
    awt.toolkit
    java.vm.info
    java.version
    java.ext.dirs
    sun.boot.class.path
    java.vendor
    file.separator
    java.vendor.url.bug
    sun.cpu.endian
    sun.io.unicode.encoding
    sun.font.fontmanager
    socksNonProxyHosts
    sun.awt.noerasebackground
    ftp.nonProxyHosts
    sun.cpu.isalist
    
Sign In or Register to comment.