Copy link to clipboard
Copied
The following script will not run in when wrapped in a menu item. But the main function runs fine on its own...
Any idea whats going on.
#target bridge
var menu = MenuElement.create( "command", "Anon_forSending", "at the end of Tools");
menu.onSelect = function(m) { main() }
function main(){
var selectedThumbnails = app.documents[0].getSelection();
var modified = 0;
for (var i = 0; i < selectedThumbnails.length; ++i) {
var val = decodeURI(selectedThumbnails[i].name);
var f = new File (decodeURI(selectedThumbnails[i].path))
if (stripFileExtension)
val = val.replace(/\.[^\.]+$/, '');
p = (val.match(/_0/).index)+1
val =val.substr(p,4)
newName = val + '.psd'
var f1 = new File (f.parent + "/" + newName)
if (f1.exists == true){newName = val + '_1' + '.psd'}
var metadata = selectedThumbnails[i].synchronousMetadata;
metadata.namespace = 'http://ns.adobe.com/photoshop/1.0/';
metadata.applyMetadataTemplate("clearall", "replace")
selectedThumbnails[i].name = newName
}
}
I'm getting an error at
if (stripFileExtension)
stripFileExtension is undefined
You need to rewrite it to do the rename after a delay, or rename first and then do metadata operations on the file referencing the new name.
Copy link to clipboard
Copied
I'm getting an error at
if (stripFileExtension)
stripFileExtension is undefined
Copy link to clipboard
Copied
bingo thanks a million, was scratching my head for a while on that one
Copy link to clipboard
Copied
ive got another query on this script. After the script has run, It says the file (original filename) can no longer be found. Is there a way to avoid showing this error each time?
Copy link to clipboard
Copied
I need it to replace the metadata from the template and then rename. Its currently its renaming before the applying the metadata template. How can i get it to run one after another. thats why its throwing an error, as it can no longer find the files to clear there metadata.
Copy link to clipboard
Copied
You need to rewrite it to do the rename after a delay, or rename first and then do metadata operations on the file referencing the new name.
Copy link to clipboard
Copied
Ahh i see, i will try that many thanks