I would like to write the profile picture of a contact to a file.
1) how to read TIFF image?
The dictionary describes the image property: image (*TIFFPicture* or missing value) : Image for person.
In the dictionary TIFFPicture is a link, but when I click it there's no additional information.
When reading it the value seems to be <>
.
How do I read it as an image?
2) how to write TIFF image?
When writing it to a file, what format should be specified?
The dictionary says: [as: type class] : how to write the data: as text, data, list, etc.
In case as:
is needed for writing an image, what type should be specified? When I use e.g. as: 'data'
the error is "Can't convert types".
Example:
var app = Application.currentApplication();
app.includeStandardAdditions = true;
myPeople = Application("Contacts").people.whose({ _and: [{lastName: "Doe" },{firstName: "John"}] });
for (i in myPeople) {
person = myPeople[i];
if (person.image() == null) continue;
var data = person.image();
var file = Path("/var/tmp/test.tiff");
app.openForAccess(file, { writePermission: true });
app.setEof(file, {to:0} ); // reset length
app.write(data, {
to: file,
//as: 'data',
});
app.closeAccess(file);
// result: file with 2 bytes ("<>")
}
data
variable when you view it in SE? JXA's bridging of Apple event datatypes to/from JavaScript has various defects, so it's possible that 1. JXA doesn't know how handle thetypeTIFF
descriptor returned by Contacts when you callperson.image()
, or 2. it doesn't know how to pack that value back into an Apple event descriptor in the subsequentwrite
command. Best thing to do is to write your script in AppleScript first: if it works there you know it's JXA being busted and crap; if it fails in AS too, the problem's probably elsewhere (e.g. Contacts). – foo"<>"
(or null when there's no image). It's been a while since I used AppleScript, so I was hoping to solve it in JXA. – wivku~/Library/Application Support/AddressBook/Images
but it appears that is no longer the case. – wivku