Skip to main content
Gibson Editions
Inspiring
Jul 21, 2022 4:32 PM UTC
Answered

bridge script failing when added as menu item

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 is closed to new replies. Start a new post to keep the conversation going.
LumigraphicsCorrect answer
Legend
Jul 21, 2022 6:15 PM UTC

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.

6 replies

Gibson Editions
Inspiring
Jul 21, 2022 5:50 PM UTC

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? 

Translate
Gibson Editions
Inspiring
Jul 21, 2022 5:55 PM UTC

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. 

Translate
LumigraphicsCorrect answer
Legend
Jul 21, 2022 6:15 PM UTC

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.

Translate
gregreser
Legend
Jul 21, 2022 5:36 PM UTC

I'm getting an error at 

if (stripFileExtension)

stripFileExtension is undefined

Translate
Gibson Editions
Inspiring
Jul 21, 2022 5:49 PM UTC

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

Translate