Thank you for getting back! Here you go: #target photoshop // Got this from: https://forums.adobe.com/thread/771241 // define the path of the intended txt-file; var thePref = "~/Desktop/pref.txt"; // check for existence of file: if (File (thePref).exists == true) { var theText = readPref (thePref); alert (theText); } else { // dialog; var dlg = new Window("dialog", "please enter a number", [500,300,750,380]); // filter for checking if entry is numeric, thanks to xbytor; numberKeystrokeFilter = function() { this.text = this.text.replace(",", ""); this.text = this.text.replace(".", ""); this.text = this.text.replace("-", ""); if (this.text.match(/[^\-\.\d]/)) { this.text = this.text.replace(/[^\-\.\d]/g, "gg") // Set new line here "\n" alert("Found NewLine"); }; if (this.text == 0) {this.text = 1} }; // field for entry; dlg.someText = dlg.add("edittext", [15,15,110,35], "3", {multiline:false}); dlg.someText.active = true; dlg.someText.onChange = numberKeystrokeFilter; // ok- and cancel-button; dlg.buildBtn = dlg.add("button", [13,45,118,68], "OK", {name:"ok"}); dlg.cancelBtn = dlg.add("button", [128,45,240,68], "Cancel", {name:"cancel"}); dlg.center(); // show dialog; var myReturn = dlg.show (); alert (myReturn); if (myReturn == 1) { var theText = dlg.someText.text; // write pref; alert(theText); writePref (theText, thePref); alert ("done") } }; ////// read prefs file ////// function readPref (thePath) { if (File(thePath).exists == true) { var file = File(thePath); file.open("r"); file.encoding= 'BINARY'; var theText = new String; for (var m = 0; m < file.length; m ++) { theText = theText.concat(file.readch()); }; file.close(); return String(theText) } }; ////// function to write a preference-file storing a text ////// function writePref (theText, thePath) { try { var thePrefFile = new File(thePath); thePrefFile.open("w"); for (var m = 0; m < theText.length; m ++) { alert("m= : " +theText ); thePrefFile.write(theText ) }; thePrefFile.close() } catch (e) {}; };
... View more