• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers

bridge script failing when added as menu item

Participant ,
Jul 21, 2022 Jul 21, 2022

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
 
        }

            }



        
TOPICS
Scripting

Views

64

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 2 Correct answers

Community Expert , Jul 21, 2022 Jul 21, 2022

I'm getting an error at 

if (stripFileExtension)

stripFileExtension is undefined

Likes

Translate

Translate
Community Expert , Jul 21, 2022 Jul 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.

Likes

Translate

Translate
Community Expert ,
Jul 21, 2022 Jul 21, 2022

Copy link to clipboard

Copied

I'm getting an error at 

if (stripFileExtension)

stripFileExtension is undefined

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jul 21, 2022 Jul 21, 2022

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jul 21, 2022 Jul 21, 2022

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? 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jul 21, 2022 Jul 21, 2022

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. 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 21, 2022 Jul 21, 2022

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.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jul 21, 2022 Jul 21, 2022

Copy link to clipboard

Copied

LATEST

Ahh i see, i will try that many thanks 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines