I wanted to create an AppleScript whereby for the photos I post online, it'd remove all my exif data, change format from HEIC to JPG, and (as a bonus) resize the images. Is that possible?
A command-line application and Perl library for reading and writing EXIF, GPS, IPTC, XMP, makernotes and other meta information in image, audio and video files. For Windows, MacOS, and Unix systems.
A command-line application and Perl library for reading and writing EXIF, GPS, IPTC, XMP, makernotes and other meta information in image, audio and video files. For Windows, MacOS, and Unix systems.
I won't code the AppleScript, but, the nuclear option to remove all exif information from a file via ExifTool is:
Code:
exiftool -all= -P mypic.jpg
To be more discreet, first, run following:
Code:
exiftool -s mypic.jpg
That will give you a list of all the tags on the photo and their values.
To clear a specific tag:
Code:
exiftool -TAGNAME= -P mypic.jpg
To do a whole folder of pictures, all tags:
Code:
cd path-to-folder-to-process
exiftool -all= -P -r -progress .
ADD: And quick look at AppleScript Photos class, there is an export method that will convert whatever is passed into jpg.
Code:
export v : Export media items to the specified location as files
export list of media item : The list of media items to export.
to file : The destination of the export.
[using originals boolean] : Export the original files if true, otherwise export rendered jpgs. defaults to false.
I was surprised there aren't easily available scripts for this purpose, so I made two:
ConvertHEICtoJPEG.scpt uses Apple's Image Events to convert HEIC/HEIF files to JPEG, no additional software required, but it doesn't remove metadata
Code:
--https://developer.apple.com/library/archive/documentation/LanguagesUtilities/Conceptual/MacAutomationScriptingGuide/ManipulateImages.html
--https://developer.apple.com/library/archive/documentation/AppleScript/Conceptual/AppleScriptLangGuide/reference/ASLR_cmds.html
set theSourceFolder to choose folder with prompt "Please select the folder containing HEIC/HEIF files"
set theOutputFolder to choose folder with prompt "Please select an output folder"
--Source and Output can be the same folder
tell application "Finder"
set theFiles to the files of theSourceFolder
repeat with currentFile in theFiles
if name extension of currentFile is in {"HEIC", "HEIF"} then
--setting extension to hiddden in order to get only the file name
set extension hidden of currentFile to true
set theName to displayed name of currentFile
--the extension can be displayed again
--set extension hidden of currentFile to false
tell application "Image Events"
launch
set theImage to open currentFile as string
save theImage as JPEG in (theOutputFolder & theName & ".jpg" as string)
close theImage
end tell
--the original file can be moved to Trash
--delete currentFile
end if
end repeat
end tell
--This is just a visual confirmation, it can be deleted
set ConvertedFiles to do shell script "ls " & (POSIX path of theOutputFolder) & " | grep 'jpg' "
display dialog "The file(s):" & return & return & ConvertedFiles & return & return & "saved in: " & POSIX path of theOutputFolder buttons {"Close"} default button 1
NConvertHEICtoJPEG.scpt uses NConvert to convert HEIC/HEIF files to JPEG and remove metadata.
"NConvert is provided as FREEWARE (NO Adware, NO Spyware) for private or educational use (including non-profit organizations)." https://www.xnview.com/en/nconvert/
Code:
--NConvert is provided as FREEWARE (NO Adware, NO Spyware) for private or educational use (including non-profit organizations). https://www.xnview.com/en/nconvert/
--NConvert for macOS http://download.xnview.com/NConvert-macosx64.tgz
set theSourceFolder to choose folder with prompt "Please select the folder containing HEIC/HEIF files"
tell application "Finder"
set theFiles to the files of theSourceFolder
repeat with currentFile in theFiles
if name extension of currentFile is in {"HEIC", "HEIF"} then
set theImage to quoted form of POSIX path of (currentFile as string)
do shell script "/Applications/NConvert/nconvert -rmeta -out jpeg " & theImage
end if
end repeat
end tell
Unlike exiftool, NConvert does not require installation, it can be just extracted anywhere.
Further improvements of the scripts might be posted here https://github.com/b0gdanw/AppleScripts