Why can't I write a XMPString to a file?

Explorer ,
Dec 25, 2020

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. 

 

TOPICS
How to, Scripting

Views

90

Likes

Translate

Translate

Report

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

1 Correct Answer

Enthusiast , Dec 25, 2020
femkeblanco Enthusiast , Dec 25, 2020
var XMP = new File("~/Desktop/XMP.txt"); XMP.encoding = "UTF-8"; XMP.open("e"); XMP.write(app.activeDocument.XMPString); XMP.close;

Likes

Translate

Translate
Jump to answer Jump to answer
Participant ,
Dec 25, 2020

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.

 

Likes

Translate

Translate

Report

Report
Reply
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Adobe Community Professional ,
Dec 25, 2020

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

Likes

Translate

Translate

Report

Report
Reply
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Explorer ,
Dec 25, 2020

Copy link to clipboard

Copied

Thanks but still fiel stays empty.

Likes

Translate

Translate

Report

Report
Reply
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Enthusiast ,
Dec 25, 2020

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;

Likes

Translate

Translate

Report

Report
Reply
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
cute filthy AUTHOR LATEST
Explorer ,
Dec 25, 2020

Copy link to clipboard

Copied

Thsnks, it works!!

Likes

Translate

Translate

Report

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