I'm working on a WorkSpace saver, there is nothing more frustrating then having a bunch of documents open and Ps crashes or stops working. When all the while I could have had a saved workspace. My scripting knowledge is weak at best, the following is what has been thrown together. There are two problems with this script, one problem is the untitled scripts are not automatically saving along with the save documents. The untitled documents would be "untitled1, "untitled2" etc then whatever saved documents I have. The second problem is that instead of listing the actual names of the documents that were open in another session, it only lists the file path, as the script is currently the file path is only for the saved documents.
Code: Select all
// 2012; use it at your own risk;
#target photoshop
// get list if txt-file exists;
var thePath = "~/Desktop/openfiles.txt";
if (File(thePath).exists == true) {
var theText = readPref (thePath);
var theFiles = theText.split("\:");
var theFiles = selectFromArray(theFiles);
var theFails = new Array;
// open files;
for (var m = 0; m < theFiles.length; m++) {
try {app.open(File(theFiles[m]))}
catch (e) {theFails.push(theFiles[m])}
};
// list the failed images;
if (theFails.length > 0) {alert (theFails.join(", ")+" could not be opened")}
else {File(thePath).remove()};
}
else {
//
if (app.documents.length > 0) {
// collect fullnames of open images;
var pathArray = new Array;
var unsaved = new Array;
for (var n = 0; n < app.documents.length; n++) {
try {
pathArray.push(app.documents[n].fullName)
}
catch (e) {unsaved.push(app.documents[n].activedocument)}
};
if (unsaved.length > 0) {alert (unsaved.join(", ")+" seem/s to be unsaved")};
// write the list;
writePref (pathArray.join("\:"), thePath);
}
};
////// 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 ++) {
thePrefFile.write(theText[m])
};
thePrefFile.close()
}
catch (e) {};
};
//////
function selectFromArray (theList) {
var theSelected = new Array;
var dlg =
"dialog{text:'Script Interface',bounds:[100,100,350,350],"+
"panel0:Panel{bounds:[10,10,240,240] , text:'' ,properties:{borderStyle:'etched',su1PanelCoordinates:true},"+
"docs:ListBox{bounds:[10,40,220,190] , properties:{multiselect:true}},"+
"statictext0:StaticText{bounds:[50,10,160,27] , text:'the list' ,properties:{scrolling:undefined,multiline:undefined}},"+
"button0:Button{bounds:[10,200,110,220] , text:'Cancel' }},"+
"button1:Button{bounds:[130,210,230,230] , text:'ok' }}}";
var win = new Window(dlg,"Open Docs");
win.center();
for(var a = 0;a<theList.length;a++){
win.panel0.docs.add("item",theList[a]);
};
var theReturn = win.show();
if (theReturn == 1) {
for (var m = 0; m < win.panel0.docs.items.length; m++) {
var thisItem = win.panel0.docs.items[m];
if (thisItem.selected == true) {
theSelected.push(String(thisItem))
}
};
};
return theSelected
};