A workaround for "per-sketch-settings" (and libraries)

There are already multiple topics on this issue like:

"Board Settings in *.ino file" and "Make board/CPU type stick per project."

And since the arduino IDE supports more and more different boards and platforms (great!) it's no wonder that more and more people are asking for a way to include the board settings "in the sketch".
Me myself had the same problem, and not only for the board settings but also for the libraries and tools which often are uniquely for a specific platform (like ATtiny and esp8266) or you need to set different settings IN the library files (Realy developers, Solve this problem! No settings should ever need a change in the library source files !).

But I found a way to solve all these problems by using the attached batchfile to open .ino files (cannot attach a .cmd file, so you need to rename it from .txt to .cmd !).
It will create and use a preferences.txt per sketch folder. In this preferences.txt the sketchbook.path will be set to the root of the sketchfolder so you can use the following folder layout:

/Arduino
  /libraries
     /lib1
     /lib2
  /sketch1
      sketch1.ino
  /sketch2
      sketch2.ino
/esp8266
  /libraries
     /lib2
     /esp8266lib1
     /esp8266lib2
  /tools
     /ESP8266FS
     /EspExceptionDecoder
  /sketch1
      sketch1.ino
  /sketch2
      sketch2.ino
/ATtiny
  /libraries
    /lib1
    /attinylib1
    /attinylib2
  /sketch1
      sketch1.ino
  /sketch2
      sketch2.ino
/specialproject
  /device1
    /libraries
      /lib1v1
      /lib2
      /lib3
    /sketch
        sketch.ino
  /device2
    /libraries
      /lib1v2
      /lib2
      /lib3
    /sketch
        sketch.ino

Once you have set this batch file as the default program to open .ino files,
you can just doubleclick a .ino file to open the IDE with the settings loaded from the sketch folder.

Note that when you doubleclick a .ino for first time the command window will show, and the preferences file will be copied to the sketch folder and the ide will be started just to set the sketchbook path in the new preferences.txt. Once the IDE closes again you can close the cammand window and click the .ino again, wich will now open 'normally', set your board settings for the sketch which now will be stored in the sketch folder, so the next time you doubleclick the .ino these settings will be loaded again.

ALSO NOTE that this will only work if you open a sketch by doubleclicking the .ino from windows explorer, NOT when you open a .ino from the arduino IDE. To switch project close the IDE and doubleclick the other .ino in explorer.

I hope this helps you too.
Any questions or remarks ? Post them in this topic (no PM please)

arduino.txt (3.04 KB)