Thanks 
I realized that upon quitting Photoshop the path is lost, is there nothing I can do about that?
Change beginning of your script to:
PTH = ""; displayDialogs = DialogModes.NO
var Path = $.getenv('pth') || PTH || "d/";
// for saving files
var doc = app.activeDocument;
And in the middle where you last time insterted new part, edit that to:
dlg.show();
$.setenv('pth', Path.slice(1))
if (PTH != ge = $.getenv('pth')) {
(fle = File($.fileName)).open('r'), jsxFile = fle.read()
.replace(/"(.*)"(?=;)/, '"' + ge + '"'), fle.close()
fle.open('w'), fle.write(jsxFile), fle.close()
}
Additionally what is important change two your trim methods from doc.trim(TrimType.TRANSPARENT, true, true, true, true); to just doc.trim(). This way your images will be trimmed whether they are on transparent or one coloured or else coloured background. If you won't do this then your script will stop working (of course in specific situation).
As to beginning and middle of script now when PTH is false, and environment pth is undefined it will display 'd\', however it will happen only once, at first time of running script. During using Ps it will always refer to environmental path. Every time it is changed your .jsx script is going to update itself of new path (first line of code). If you choose few times in a row the same path, then PTH variable will keep last different path, if you change it to other in dialog and click 'Export' button it's going to be changed also in your script, but will be used only at every next Photoshop session.