Javascript 编辑:在AdobeBridge中编辑元数据的脚本-我应该如何放置;关键词;(单独的单词)转换成代码?

Javascript 编辑:在AdobeBridge中编辑元数据的脚本-我应该如何放置;关键词;(单独的单词)转换成代码?,javascript,function,extendscript,photoshop-script,adobe-bridge,Javascript,Function,Extendscript,Photoshop Script,Adobe Bridge,我有一个在AdobeBridge中编辑元数据的简单脚本,它具有查找和替换功能。仅用于说明部分 我需要让它只为关键字部分工作。我试图将description更改为keywords(带和不带descriptionkeywords),但最终结果是脚本无法工作。为了实现我的需求,还需要更改或添加哪些内容 编辑: 我试图将description更改为title,以使脚本在title部分工作,它成功了 所以问题是,到底应该用什么来代替description,才能使关键字部分发挥作用? 我在一个脚本中看到,对

我有一个在AdobeBridge中编辑元数据的简单脚本,它具有查找和替换功能。仅用于说明部分

我需要让它只为关键字部分工作。我试图将
description
更改为
keywords
(带和不带
description
keywords
),但最终结果是脚本无法工作。为了实现我的需求,还需要更改或添加哪些内容

编辑

我试图将
description
更改为
title
,以使脚本在title部分工作,它成功了

所以问题是,到底应该用什么来代替
description
,才能使关键字部分发挥作用? 我在一个脚本中看到,对于Bridge,它应该是
关键字
(单独的),因此如果是这样,我应该如何在代码中编写它?(是的,我是javascript的noob)

在Description.jsx中查找Replace-


我发现了一个不同的脚本,它提供了我需要的功能,甚至更好,因为它提供了添加和删除关键字的选项:

#target bridge  

   if( BridgeTalk.appName == "bridge" ) {  
keyReplace = MenuElement.create("command", "Add-Replace-Remove Keyword", "at the end of tools");
}
keyReplace.onSelect = function () { 
      mainReplaceKeyword();
      }

function mainReplaceKeyword(){
if(app.version.substr(0,app.version.indexOf('.'))==1){
alert("Sorry You Need CS3 or CS4 to run this script!"); 
return;
    }
var dlg =
"dialog{text:'Script Interface',bounds:[100,100,500,310],"+
"panel0:Panel{bounds:[10,10,390,200] , text:'' ,properties:{borderStyle:'etched',su1PanelCoordinates:true},"+
"title:StaticText{bounds:[60,10,350,40] , text:'Add/Replace/Remove Keyword' ,properties:{scrolling:undefined,multiline:undefined}},"+
"panel1:Panel{bounds:[10,40,370,150] , text:'' ,properties:{borderStyle:'etched',su1PanelCoordinates:true},"+
"addKey:Checkbox{bounds:[20,10,160,31] , text:'Add Keyword' },"+
"statictext1:StaticText{bounds:[20,40,119,60] , text:'Replace' ,properties:{scrolling:undefined,multiline:undefined}},"+
"From:EditText{bounds:[120,40,350,60] , text:'' ,properties:{multiline:false,noecho:false,readonly:false}},"+
"statictext2:StaticText{bounds:[20,80,90,97] , text:'With' ,properties:{scrolling:undefined,multiline:undefined}},"+
"To:EditText{bounds:[120,80,350,100] , text:'' ,properties:{multiline:false,noecho:false,readonly:false}}},"+
"button0:Button{bounds:[10,160,180,181] , text:'Ok' },"+
"button1:Button{bounds:[200,160,370,181] , text:'Cancel' }}};";
var win = new Window(dlg,"Replace Keyword");
win.center();

win.panel0.title.graphics.font = ScriptUI.newFont("Times","BOLDITALIC",20);
g = win.graphics;
b=win.panel0.title.graphics;
var myBrush = g.newBrush(g.BrushType.SOLID_COLOR, [0.99, 0.99, 0.20, 1]);
g.backgroundColor = myBrush;
var myPen =b.newPen (g.PenType.SOLID_COLOR, [0.00, 0.00, 0.99, 1],lineWidth=1);
var myPen2 =b.newPen (g.PenType.SOLID_COLOR, [0.99, 0.00, 0.00, 1],lineWidth=1);
g.foregroundColor = myPen;
b.foregroundColor = myPen2;
win.panel0.panel1.From.active=true;
win.panel0.panel1.addKey.onClick = function() { 
if(win.panel0.panel1.addKey.value) {
    win.panel0.panel1.statictext1.text = "New Keyword";
    win.panel0.panel1.From.active=true;
    win.panel0.panel1.statictext2.visible=false;
    win.panel0.panel1.To.visible=false;
    }
if(!win.panel0.panel1.addKey.value) {
    win.panel0.panel1.statictext1.text = "Replace";
    win.panel0.panel1.statictext2.visible=true;
    win.panel0.panel1.To.visible=true;
    win.panel0.panel1.From.active=true;
    }
}
win.center();
var done = false; 
    while (!done) { 
      var x = win.show(); 
      if (x == 0 || x == 2) {
        win.canceled = true;
        done = true; 
      } else if (x == 1) { 
        done = true; 
       var result = valiDate();
        if(result != true) {
            alert(result);
            return;
        }else{    
            var Replace = win.panel0.panel1.From.text;
            var With = win.panel0.panel1.To.text;
            var addKey = win.panel0.panel1.addKey.value;
            processKeyword(Replace,With,addKey);
        }
      } 
   } 

function valiDate(){
    if(win.panel0.panel1.From.text =='') return "No Keyword Entered!";
return true;
}
function processKeyword(Replace,Witha,ddKey){
try{
loadXMPScript();
}catch(e){
alert("Can not load XMPScript\r" + e.message);  
    }

var items = app.document.selections;
  for (var i = 0; i < items.length; i++){ 
      var file=new Thumbnail(items[i]);
try{
var xmpFile = new XMPFile(file.path, XMPConst.UNKNOWN,XMPConst.OPEN_FOR_UPDATE);
}catch(e){
        alert("Problem opening xmp for update:-\r" + file.path +"\r" +e.message);
        return;
    }
try{
var xmp = xmpFile.getXMP();
}catch(e){
        alert("Problem opening xmp data:-\r"  + e.message);
        return;
    }
try{
var tmpCount =  xmp.countArrayItems(XMPConst.NS_DC, "subject");
}catch(e){
    alert("Cannot get count \r" + e.message);
    }
            if(addKey){
                xmp.appendArrayItem(XMPConst.NS_DC, "subject", Replace, 0,XMPConst.ARRAY_IS_ORDERED);
                }
if(tmpCount >0 && !addKey){
        for (var a =0;a<tmpCount;a++){
            var     Keyword = xmp.getArrayItem(XMPConst.NS_DC,'subject', a+1);
            if(Keyword == Replace && With == '') {
                xmp.deleteArrayItem(XMPConst.NS_DC,'subject', a+1);
                }
            if(Keyword == Replace && With != ''){
                xmp.setArrayItem(XMPConst.NS_DC,'subject', a+1,With);
                }
        }
}

if (xmpFile.canPutXMP(xmp)) {
xmpFile.putXMP(xmp);
}else{
alert(e.message);   
    }
xmpFile.closeFile(XMPConst.CLOSE_UPDATE_SAFELY);
}
unloadXMPScript();
}
}

function loadXMPScript()
{
    var results = new XMPLibMsg("XMPScript Library already loaded", 0, false);

    if (!ExternalObject.AdobeXMPScript)
    {
        try
        {
            ExternalObject.AdobeXMPScript = new ExternalObject('lib:AdobeXMPScript');       
            results.message = "XMPScript Library loaded";
        }
        catch (e)
        {
            alert("Could not load AdobeXMPScript \r" + e.message);
            results.message = "ERROR Loading AdobeXMPScript: " + e;
            results.line = e.line;
            results.error = true;
        }
    }

    return results;
}
function unloadXMPScript()
{
    var results = new XMPLibMsg("XMPScript Library not loaded", 0, false);

    if( ExternalObject.AdobeXMPScript ) 
    {
        try
        {
            ExternalObject.AdobeXMPScript.unload();
            ExternalObject.AdobeXMPScript = undefined;
            results.message = "XMPScript Library successfully unloaded";
        }
        catch (e)
        {
            results.message = "ERROR unloading AdobeXMPScript: " + e;
            results.line = e.line;
            results.error = true;
        }
    }

    return results;
}
function XMPLibMsg (inMessage, inLine, inError)
{
    this.message = inMessage;
    this.line = inLine;
    this.error = inError;
}
#目标网桥
如果(BridgeTalk.appName==“bridge”){
keyReplace=menueElement.create(“命令”、“添加替换删除关键字”、“在工具末尾”);
}
keyReplace.onSelect=函数(){
main替换关键字();
}
函数mainReplaceKeyword(){
if(app.version.substr(0,app.version.indexOf('.'))==1){
警报(“抱歉,您需要CS3或CS4才能运行此脚本!”);
回来
}
var dlg=
对话框{文本:'Script Interface',边界:[100500310]+
panel0:面板{bounds:[10,10390200],文本:'',属性:{borderStyle:'etched',su1PanelCoordinates:true}+
“标题:StaticText{bounds:[60,10350,40],文本:'Add/Replace/Remove Keyword',属性:{滚动:未定义,多行:未定义}”+
panel1:面板{bounds:[10,40370150],文本:'',属性:{borderStyle:'etched',su1PanelCoordinates:true}+
addKey:复选框{bounds:[20,10160,31],文本:'Add Keyword'}+
statictext1:StaticText{bounds:[20,40119,60],文本:'Replace',属性:{滚动:未定义,多行:未定义}+
From:EditText{bounds:[120,40350,60],文本:“”,属性:{multiline:false,noecho:false,readonly:false}+
statictext2:StaticText{bounds:[20,80,90,97],文本:'With',属性:{滚动:未定义,多行:未定义}+
“收件人:EditText{bounds:[120,80350100],文本:'',属性:{multiline:false,noecho:false,readonly:false}”+
button0:按钮{bounds:[10160180181],文本:'Ok'}+
“button1:按钮{bounds:[200160370181],文本:'Cancel'}};”;
var win=新窗口(dlg,“替换关键字”);
win.center();
win.panel0.title.graphics.font=ScriptUI.newFont(“Times”,“BOLDITALIC”,20);
g=win.graphics;
b=win.panel0.title.graphics;
var myBrush=g.newBrush(g.BrushType.SOLID_COLOR,[0.99,0.99,0.20,1]);
g、 backgroundColor=myBrush;
var myPen=b.newPen(g.PenType.SOLID_COLOR,[0.00,0.00,0.99,1],线宽=1);
var myPen2=b.newPen(g.PenType.SOLID_COLOR,[0.99,0.00,0.00,1],线宽=1);
g、 foregroundColor=myPen;
b、 foregroundColor=myPen2;
win.panel0.panel1.From.active=true;
win.panel0.panel1.addKey.onClick=function(){
if(win.panel0.panel1.addKey.value){
win.panel0.panel1.statictext1.text=“新建关键字”;
win.panel0.panel1.From.active=true;
win.panel0.panel1.statictext2.visible=false;
win.panel0.panel1.To.visible=false;
}
如果(!win.panel0.panel1.addKey.value){
win.panel0.panel1.statictext1.text=“替换”;
win.panel0.panel1.statictext2.visible=true;
win.panel0.panel1.To.visible=true;
win.panel0.panel1.From.active=true;
}
}
win.center();
var done=false;
当(!完成){
var x=win.show();
如果(x==0 | | x==2){
win.canceled=true;
完成=正确;
}如果(x==1){
完成=正确;
var result=valiDate();
如果(结果!=真){
警报(结果);
回来
}否则{
var Replace=win.panel0.panel1.From.text;
var=win.panel0.panel1.To.text;
var addKey=win.panel0.panel1.addKey.value;
processKeyword(替换、替换为、addKey);
}
} 
} 
函数验证(){
如果(win.panel0.panel1.From.text='')返回“未输入关键字!”;
返回true;
}
函数processKeyword(替换,使用,ddKey){
试一试{
loadXMPScript();
}捕获(e){
警报(“无法加载XMPScript\r”+e.message);
}
变量项=app.document.selections;
对于(var i=0;i0&!addKey){

对于(var a=0;aI以前使用过元数据,这应该是一个用另一个字符串替换字符串的简单问题。您是否尝试过将脚本提取为最小代码-获取和警报描述并进行更改?我只是在Adobe Bridge中测试了脚本。另外,我对javascript知之甚少,所以什么时候我查看此代码idk除了将
描述
更改为
关键字
之外,还有什么可以做的…当我将标题部分更改为“title”时,它会起作用。我在某个地方看到,也许我应该将
关键字
而不是
关键字
-如何将其放入代码中
#target bridge  

   if( BridgeTalk.appName == "bridge" ) {  
keyReplace = MenuElement.create("command", "Add-Replace-Remove Keyword", "at the end of tools");
}
keyReplace.onSelect = function () { 
      mainReplaceKeyword();
      }

function mainReplaceKeyword(){
if(app.version.substr(0,app.version.indexOf('.'))==1){
alert("Sorry You Need CS3 or CS4 to run this script!"); 
return;
    }
var dlg =
"dialog{text:'Script Interface',bounds:[100,100,500,310],"+
"panel0:Panel{bounds:[10,10,390,200] , text:'' ,properties:{borderStyle:'etched',su1PanelCoordinates:true},"+
"title:StaticText{bounds:[60,10,350,40] , text:'Add/Replace/Remove Keyword' ,properties:{scrolling:undefined,multiline:undefined}},"+
"panel1:Panel{bounds:[10,40,370,150] , text:'' ,properties:{borderStyle:'etched',su1PanelCoordinates:true},"+
"addKey:Checkbox{bounds:[20,10,160,31] , text:'Add Keyword' },"+
"statictext1:StaticText{bounds:[20,40,119,60] , text:'Replace' ,properties:{scrolling:undefined,multiline:undefined}},"+
"From:EditText{bounds:[120,40,350,60] , text:'' ,properties:{multiline:false,noecho:false,readonly:false}},"+
"statictext2:StaticText{bounds:[20,80,90,97] , text:'With' ,properties:{scrolling:undefined,multiline:undefined}},"+
"To:EditText{bounds:[120,80,350,100] , text:'' ,properties:{multiline:false,noecho:false,readonly:false}}},"+
"button0:Button{bounds:[10,160,180,181] , text:'Ok' },"+
"button1:Button{bounds:[200,160,370,181] , text:'Cancel' }}};";
var win = new Window(dlg,"Replace Keyword");
win.center();

win.panel0.title.graphics.font = ScriptUI.newFont("Times","BOLDITALIC",20);
g = win.graphics;
b=win.panel0.title.graphics;
var myBrush = g.newBrush(g.BrushType.SOLID_COLOR, [0.99, 0.99, 0.20, 1]);
g.backgroundColor = myBrush;
var myPen =b.newPen (g.PenType.SOLID_COLOR, [0.00, 0.00, 0.99, 1],lineWidth=1);
var myPen2 =b.newPen (g.PenType.SOLID_COLOR, [0.99, 0.00, 0.00, 1],lineWidth=1);
g.foregroundColor = myPen;
b.foregroundColor = myPen2;
win.panel0.panel1.From.active=true;
win.panel0.panel1.addKey.onClick = function() { 
if(win.panel0.panel1.addKey.value) {
    win.panel0.panel1.statictext1.text = "New Keyword";
    win.panel0.panel1.From.active=true;
    win.panel0.panel1.statictext2.visible=false;
    win.panel0.panel1.To.visible=false;
    }
if(!win.panel0.panel1.addKey.value) {
    win.panel0.panel1.statictext1.text = "Replace";
    win.panel0.panel1.statictext2.visible=true;
    win.panel0.panel1.To.visible=true;
    win.panel0.panel1.From.active=true;
    }
}
win.center();
var done = false; 
    while (!done) { 
      var x = win.show(); 
      if (x == 0 || x == 2) {
        win.canceled = true;
        done = true; 
      } else if (x == 1) { 
        done = true; 
       var result = valiDate();
        if(result != true) {
            alert(result);
            return;
        }else{    
            var Replace = win.panel0.panel1.From.text;
            var With = win.panel0.panel1.To.text;
            var addKey = win.panel0.panel1.addKey.value;
            processKeyword(Replace,With,addKey);
        }
      } 
   } 

function valiDate(){
    if(win.panel0.panel1.From.text =='') return "No Keyword Entered!";
return true;
}
function processKeyword(Replace,Witha,ddKey){
try{
loadXMPScript();
}catch(e){
alert("Can not load XMPScript\r" + e.message);  
    }

var items = app.document.selections;
  for (var i = 0; i < items.length; i++){ 
      var file=new Thumbnail(items[i]);
try{
var xmpFile = new XMPFile(file.path, XMPConst.UNKNOWN,XMPConst.OPEN_FOR_UPDATE);
}catch(e){
        alert("Problem opening xmp for update:-\r" + file.path +"\r" +e.message);
        return;
    }
try{
var xmp = xmpFile.getXMP();
}catch(e){
        alert("Problem opening xmp data:-\r"  + e.message);
        return;
    }
try{
var tmpCount =  xmp.countArrayItems(XMPConst.NS_DC, "subject");
}catch(e){
    alert("Cannot get count \r" + e.message);
    }
            if(addKey){
                xmp.appendArrayItem(XMPConst.NS_DC, "subject", Replace, 0,XMPConst.ARRAY_IS_ORDERED);
                }
if(tmpCount >0 && !addKey){
        for (var a =0;a<tmpCount;a++){
            var     Keyword = xmp.getArrayItem(XMPConst.NS_DC,'subject', a+1);
            if(Keyword == Replace && With == '') {
                xmp.deleteArrayItem(XMPConst.NS_DC,'subject', a+1);
                }
            if(Keyword == Replace && With != ''){
                xmp.setArrayItem(XMPConst.NS_DC,'subject', a+1,With);
                }
        }
}

if (xmpFile.canPutXMP(xmp)) {
xmpFile.putXMP(xmp);
}else{
alert(e.message);   
    }
xmpFile.closeFile(XMPConst.CLOSE_UPDATE_SAFELY);
}
unloadXMPScript();
}
}

function loadXMPScript()
{
    var results = new XMPLibMsg("XMPScript Library already loaded", 0, false);

    if (!ExternalObject.AdobeXMPScript)
    {
        try
        {
            ExternalObject.AdobeXMPScript = new ExternalObject('lib:AdobeXMPScript');       
            results.message = "XMPScript Library loaded";
        }
        catch (e)
        {
            alert("Could not load AdobeXMPScript \r" + e.message);
            results.message = "ERROR Loading AdobeXMPScript: " + e;
            results.line = e.line;
            results.error = true;
        }
    }

    return results;
}
function unloadXMPScript()
{
    var results = new XMPLibMsg("XMPScript Library not loaded", 0, false);

    if( ExternalObject.AdobeXMPScript ) 
    {
        try
        {
            ExternalObject.AdobeXMPScript.unload();
            ExternalObject.AdobeXMPScript = undefined;
            results.message = "XMPScript Library successfully unloaded";
        }
        catch (e)
        {
            results.message = "ERROR unloading AdobeXMPScript: " + e;
            results.line = e.line;
            results.error = true;
        }
    }

    return results;
}
function XMPLibMsg (inMessage, inLine, inError)
{
    this.message = inMessage;
    this.line = inLine;
    this.error = inError;
}