我有一个简单的脚本,用于在Adobe Bridge中编辑具有查找和替换功能的元数据。它仅用于描述部分。
我只需要让它适用于关键字部分。我尝试将description
更改为keywords
(有和没有Description
> Keywords
),但最终结果是脚本不起作用。为了达到我的需要,需要改变或添加什么(其他)?
修改:
我尝试将description
更改为title
,以使脚本适用于标题部分,并且有效。
description
以使其适用于关键字部分?我在一个脚本中看到,对于Bridge,它应该是Key Words
(单独),所以如果是这样的话,我应该如何在代码中编写它? (是的,我是javascript中的菜鸟)
在Description.jsx中找到替换 - link to github
#target bridge
if( BridgeTalk.appName == "bridge" ) {
ReplaceDescription = new MenuElement("command", "Find and Replace", "at the end of tools");
}
ReplaceDescription.onSelect = function () {
var win = new Window( 'dialog', 'Find && Replace' );
g = win.graphics;
var myBrush = g.newBrush(g.BrushType.SOLID_COLOR, [0.99, 0.99, 0.99, 1]);
g.backgroundColor = myBrush;
win.orientation='column';
win.p1= win.add("panel", undefined, undefined, {borderStyle:"black"});
win.p1.preferredSize=[380,100];
win.g1 = win.p1.add('group');
win.g1.orientation = "row";
win.title = win.g1.add('statictext',undefined,'Caption Editor');
win.title.alignment="fill";
var g = win.title.graphics;
g.font = ScriptUI.newFont("Georgia","BOLDITALIC",22);
win.p6= win.p1.add("panel", undefined, undefined, {borderStyle:"black"}); //Replace
win.p6.preferredSize=[380,100];
win.g600 =win.p6.add('group');
win.g600.orientation = "row";
win.g600.alignment='fill';
win.g600.st1 = win.g600.add('statictext',undefined,'Replace');
win.g600.st1.preferredSize=[75,20];
win.g600.et1 = win.g600.add('edittext');
win.g600.et1.preferredSize=[200,20];
win.g610 =win.p6.add('group');
win.g610.orientation = "row";
win.g610.alignment='fill';
win.g610.st1 = win.g610.add('statictext',undefined,'With');
win.g610.st1.helpTip="Leave this field blank if you want to remove the characters";
win.g610.st1.preferredSize=[75,20];
win.g610.et1 = win.g610.add('edittext');
win.g610.et1.preferredSize=[200,20];
win.g620 =win.p6.add('group');
win.g620.orientation = "row";
win.g620.alignment='fill';
win.g620.cb1 = win.g620.add('checkbox',undefined,'Global');
win.g620.cb1.helpTip="Replace all occurrences of";
win.g620.cb2 = win.g620.add('checkbox',undefined,'Case Insensitive');
win.g620.cb2.value=true;
win.g620.cb3 = win.g620.add('checkbox',undefined,'Remove any ()[]');
win.g620.cb3.value=false;
win.g1000 =win.p1.add('group');
win.g1000.orientation = "row";
win.g1000.alignment='center';
win.g1000.bu1 = win.g1000.add('button',undefined,'Process');
win.g1000.bu1.preferredSize=[170,30];
win.g1000.bu2 = win.g1000.add('button',undefined,'Cancel');
win.g1000.bu2.preferredSize=[170,30];
win.g1000.bu1.onClick=function(){
if(win.g600.et1.text == ''){
alert("No replace value has been entered!");
return;
}
win.close(0);
var sels = app.document.selections;
for(var a in sels){
var thumb = sels[a];
md = thumb.synchronousMetadata;
if(win.g620.cb1.value && !win.g620.cb2.value) var patt = new RegExp (win.g600.et1.text.toString(),"g");
if(!win.g620.cb1.value && win.g620.cb2.value) var patt = new RegExp (win.g600.et1.text.toString(),"i");
if(win.g620.cb1.value && win.g620.cb2.value) var patt = new RegExp (win.g600.et1.text.toString(),"gi");
if(!win.g620.cb1.value && !win.g620.cb2.value) var patt = new RegExp (win.g600.et1.text.toString());
md.namespace = "http://purl.org/dc/elements/1.1/";
var Caption = md.description ? md.description[0] : "";
if(Caption == "") continue;
var result=patt.test(Caption.toString());
if(result == true){
var newCaption = Caption.replace(patt,win.g610.et1.text.toString());
if(win.g620.cb3.value) newCaption = newCaption.replace(/["'\(\)]/g, "");
md.description='';
md.description = newCaption;
}
}
}
win.show();
app.document.chooseMenuItem("PurgeCacheForSelected");
};
答案 0 :(得分:1)
我找到了一个不同的脚本,它提供了我需要的功能,甚至更好,因为它提供了添加和删除关键字的选项:
#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;
}