Copy link to clipboard
Copied
I need a script to add words in my keywords. It's possible?
I'm trying this:
activeDocument.XMPString ("ok Script");
ActiveDocument.Save (); // dont work
Thank cooperation!
As an option:
function save(doc, path, name){
try{
doc.save();
}catch(e){
doc.saveAs( File(path + '/' + name) );
}
}
function setKeywords(keywords){
var xmp = activeDocument.XMPString.toString(),
startSubject = '<dc:subject><rdf:Bag>',
endSubject = '</rdf:Bag></dc:subject>',
words = keywords.split('\n');
keywords = '';
for(var i = 0; i < words.length; i++){
keywords += '<rdf:li>' + words + '</rdf:li>';
}
if( xmp.indexOf(startSubj
...Copy link to clipboard
Copied
function save(doc, path){
try{
doc.save();
}catch(e){
doc.saveAs( Folder(path) );
}
}
save( app.activeDocument, '~/Desktop' );
Copy link to clipboard
Copied
Try it:
var key = prompt("Input keyword","");
if (key!=null) {
var st = app.activeDocument.XMPString;
var str = "";
if (st.match(/dc:subject/)==null) {
str = "<dc:subject><rdf:bag><rdf:li>"
+ key + "</rdf:li></rdf:bag></dc:subject></dc:title>";
st.replace("</dc:title>",str);
app.activeDocument.XMPString = st;
}
else {
str = "<rdf:li>" + key + "</rdf:li></rdf:Bag>";
st = st.replace("</rdf:Bag>",str);
app.activeDocument.XMPString = st;
}
app.activeDocument.save();
}
Copy link to clipboard
Copied
Hello my friends,
I ran the scripts but my Keywords still empty.
Am I doing something wrong?
Thanks for the collaboration..
Copy link to clipboard
Copied
As an option:
function save(doc, path, name){
try{
doc.save();
}catch(e){
doc.saveAs( File(path + '/' + name) );
}
}
function setKeywords(keywords){
var xmp = activeDocument.XMPString.toString(),
startSubject = '<dc:subject><rdf:Bag>',
endSubject = '</rdf:Bag></dc:subject>',
words = keywords.split('\n');
keywords = '';
for(var i = 0; i < words.length; i++){
keywords += '<rdf:li>' + words + '</rdf:li>';
}
if( xmp.indexOf(startSubject) > 0 ){
activeDocument.XMPString = xmp.replace( xmp.slice(xmp.indexOf(startSubject) + startSubject.length, xmp.indexOf(endSubject)), keywords );
}
else{
activeDocument.XMPString = xmp.replace('</dc:title>', '</dc:title>' + startSubject + keywords + endSubject);
}
save( app.activeDocument, '~/Desktop', 'Add keywords from script' );
}
setKeywords('One\nTwo\nThree\nFour\nFive');