Copy link to clipboard
Copied
var XMP = new File("~/Desktop/XMP.txt");
XMP.open("e");
XMP.write(app.activeDocument.XMPString);
Why can't I write a XMPString to a file? The file stays empty. I can print XMPString using alert, so I feel like I am missing something obvious but I don't see it. Much obliged.
1 Correct answer
var XMP = new File("~/Desktop/XMP.txt");
XMP.encoding = "UTF-8";
XMP.open("e");
XMP.write(app.activeDocument.XMPString);
XMP.close;
Explore related tutorials & articles
Copy link to clipboard
Copied
Hello if you want to add new xmp to ai doc, you can use serialize method's XMPMeta object and assign the resul to app.activeDocument.XMPString.
New XMP is saved with document when you save document.
Copy link to clipboard
Copied
I think you are missing the file close statement i.e.
XMP.close()
So if app.activeDocument.XMPString has a value then adding close should write the string to the file
-Manan
Copy link to clipboard
Copied
Thanks but still fiel stays empty.
Copy link to clipboard
Copied
var XMP = new File("~/Desktop/XMP.txt");
XMP.encoding = "UTF-8";
XMP.open("e");
XMP.write(app.activeDocument.XMPString);
XMP.close;
Copy link to clipboard
Copied
Thsnks, it works!!

