Hey Carsten, I had a similar problem when making ProStacker. The solution I found was to create an object using the data.split method you posted and then get the EXIF value I wanted by referencing the key from the object.
Since I needed to display the EXIF field as its normal name (instead of “137386”), I also had to replace many of the strings in the EXIF info before making the object. Someone probably knows a smarter way of doing that…
Here’s the code I used, hope it helps:
(Apologies @Pierre_G for forgetting to mark your answer as solution, thanks for the help)
// Get current opened doc EXIF (String)
const get_EXIF = await require("photoshop").action.batchPlay(
[{
"_obj": "get",
"_target": [{
"_property": "EXIF"
},
{
"_ref": "document",
"_enum": "ordinal",
"_value": "targetEnum"
}
]
}], {});
const data = get_EXIF[0].EXIF;
const mapObj = {
100000: "GPS Version ID :",
100001: "GPS Latitude Ref :",
100002: "GPS Latitude :",
100003: "GPS Longitude Ref :",
100004: "GPS Longitude :",
100005: "GPS Altitude Ref :",
100006: "GPS Altitude :",
100007: "GPS Time Stamp :",
100011: "GPS Img Direction :",
100012: "GPS Speed Ref :",
100013: "GPS Speed :",
100016: "GPS Img Direction Ref :",
100017: "GPS Img Direction :",
100023: "GPS Dest Bearing Ref :",
100024: "GPS Dest Bearing :",
100029: "GPS Version ID Number :",
100031: "Unknown :",
100256: "Image Width :",
100257: "Image Length :",
100258: "Bits Per Sample :",
100262: "Photometric Interpretation :",
100270: "Image Description :",
100271: "Make :",
100272: "Model :",
100274: "Orientation :",
100277: "Samples Per Pixel :",
100282: "X Resolution :",
100283: "Y Resolution :",
100296: "Resolution Unit :",
100305: "Software :",
100306: "Date Time :",
100315: "Artist :",
100322: "Tile Width :",
100323: "Tile Length :",
104097: "Related Image Width :",
104098: "Related Image Length :",
100530: "YCbCr YCbCr Sub Sampling :",
100531: "YCbCr Positioning :",
133432: "Copyright :",
133434: "Exposure Time :",
133437: "F Number :",
134850: "Exposure Program :",
134855: "ISO Speed Ratings :",
134864: "Sensitivity Type :",
134865: "Standard Output Sensitivity :",
134866: "Recommended Exposure Index :",
136864: "Exif Version :",
136867: "Date Time Original :",
136868: "Date Time Digitized :",
136880: "Offset Time :",
136881: "Offset Time Original :",
136882: "Offset Time Digitized :",
137121: "Components Configuration :",
137122: "Compressed Bits Per Pixel :",
137377: "Shutter Speed Value :",
137378: "Aperture Value :",
137379: "Brightness Value :",
137380: "Exposure Bias Value :",
137381: "Max Aperture Value :",
137383: "Metering Mode :",
137384: "Light Source :",
137385: "Flash :",
137386: "Focal Length :",
137396: "Subject Area :",
137510: "User Comment :",
137520: "SubSec Time :",
137521: "SubSec Time Original :",
137522: "SubSec Time Digitized :",
140960: "Flashpix Version :",
140961: "Color Space :",
140962: "Pixel X Dimension :",
140963: "Pixel Y Dimension :",
141486: "Focal Plane X Resolution :",
141487: "Focal Plane Y Resolution :",
141488: "Focal Plane Resolution Unit :",
141495: "Sensing Method :",
141728: "File Source :",
141729: "Scene Type :",
141730: "CFA Pattern :",
141985: "Custom Rendered :",
141986: "Exposure Mode :",
141987: "White Balance :",
141988: "Digital Zoom Ratio :",
141989: "Focal Length In 35mm Film :",
141990: "Scene Capture Type :",
141991: "Gain Control :",
141992: "Contrast :",
141993: "Saturation :",
141994: "Sharpness :",
141995: "Device Setting Description :",
141996: "Subject Distance Range :",
142016: "Image Unique ID :",
142033: "Body Serial Number :",
142034: "Lens Specification :",
142035: "Lens Make :",
142036: "Lens Model :"
};
// Replace EXIF codes with strings from above
const re = new RegExp(Object.keys(mapObj).join("|"), "gi");
const dataClean = data.replace(re, function (matched) {
return mapObj[matched];
});
const exifArray = dataClean.split("EXIF tag ");
// Tidy up junk at start and end
exifArray.shift();
exifArray.pop();
const metadataObject = {};
for (let i = 0; i < exifArray.length; i++) {
metadataObject[exifArray[i].split(" : ")[0]] = decodeURI(exifArray[i].split(" : ")[1]);
}
console.log(metadataObject["Focal Length"])