Skip to main content
Gibson Editions
Inspiring
July 21, 2022
Answered

bridge script failing when added as menu item

  • July 21, 2022
  • 2 replies
  • 587 views

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
 
        }

            }



        
This topic has been closed for replies.
Correct answer Lumigraphics

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.

2 replies

Gibson Editions
Inspiring
July 21, 2022

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? 

Gibson Editions
Inspiring
July 21, 2022

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. 

LumigraphicsCorrect answer
Brainiac
July 21, 2022

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.

gregreser
Brainiac
July 21, 2022

I'm getting an error at 

if (stripFileExtension)

stripFileExtension is undefined

Gibson Editions
Inspiring
July 21, 2022

bingo thanks a million, was scratching my head for a while on that one