Skip to content

Instantly share code, notes, and snippets.

@zimonitrome
Last active February 7, 2021 09:00
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zimonitrome/eb70f99c45a05231bf20d4e562106568 to your computer and use it in GitHub Desktop.
Save zimonitrome/eb70f99c45a05231bf20d4e562106568 to your computer and use it in GitHub Desktop.
Photoshop script to open next numbered file in sequence with saving.
var folderPath = activeDocument.path
var filePieces = activeDocument.name.split('.');
var fileName = filePieces[0];
var fileExtension = filePieces[1];
// We need to unpad the string for some reason, otherwise PS-JS
// thinks it's a past layer some times when using parseInt.
fileNameStart = 0;
for (var i = 0; i < fileName.length - 1; i++) {
digit = fileName[i];
if (digit == '0') {
fileNameStart++;
} else {
break
};
}
fileNameUnpadded = fileName.slice(fileNameStart);
var nextFileNumber = parseInt(fileNameUnpadded) + 1;
// Yes it's haxxy I know...
var padTemp = ("000000000000000" + nextFileNumber.toString());
var nextFileName = padTemp.slice(padTemp.length - 5);
var nextFilePath = folderPath + '/' + nextFileName + '.' + fileExtension;
activeDocument.close(SaveOptions.SAVECHANGES);
try {
var docRef = open(new File(nextFilePath));
}
catch (e) {
alert("No more files in the directory!");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment