Last active
February 7, 2021 09:00
-
-
Save zimonitrome/eb70f99c45a05231bf20d4e562106568 to your computer and use it in GitHub Desktop.
Photoshop script to open next numbered file in sequence with saving.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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