Monday, May 25, 2020

#1 2020-05-20 03:56:58 pm

From:: Prescott, Arizona
Registered: 2018-09-04
Posts: 478

Script to Delete JPEG Photo Metadata

I occasionally need to delete metadata from JPEG photos and wrote an AppleScript for this purpose. The script uses the free ExifTool command-line utility, which can be found at:

The operation of the script is described as follows:

* The script works on a file (or files) selected in a Finder window and creates a new file in the same folder without the specified metadata.

* Entering the word all then selecting the Tag button will remove all deletable metadata except the orientation tag.

* Entering all or a portion of the name of a tag then selecting the corresponding button will remove all matching tags. Some tags cannot be deleted, and some tags can only be removed as part of a group. With a large number of files, this option can be slow.

* Entering the full name of a group then selecting the corresponding button will remove the group and the deletable tags it contains (group-name examples are exif, gps, and jfif). Some groups cannot be removed, in which case the script will notify the user.

* The output file name consists of the letters "EE"; the letter T for tag or G for group; the text entered by the user in the dialog; and finally the original file name.

Repeated saves of a JPEG file can degrade image quality but FAQ 13 on the ExifTool site reports:

ExifTool does not modify the image data itself, so editing a file with ExifTool is "lossless" as far as the image is concerned

The following is a listing of tags recognized by ExifTool:


set exifUtil to "/usr/local/bin/exiftool"

tell application "Finder" to set sourceFiles to selection as alias list
if sourceFiles = {} then errorDialog("File not selected.")

repeat with sourceFile in sourceFiles
   if sourceFile as text does not end with ".jpg" then errorDialog("A selected file may not be a JPEG file.")
end repeat

display dialog "Enter the metadata to delete:" buttons {"Cancel", "Group", "Tag"} cancel button 1 default button 3 default answer "All" with title "Exif Edit" with icon note
set {dialogButton, dialogText} to {button returned, text returned} of result

if dialogText = "" then
   errorDialog("No metadata was enetered.")
   error number -128
else if dialogText = "All" then
   set filePrefix to "EE (T All) "
   set filePrefix to "EE (" & text 1 of dialogButton & space & dialogText & ") "
end if

set targetFiles to {}

tell application "Finder"
   repeat with sourceFile in sourceFiles
       set targetName to filePrefix & (name of sourceFile)
       set targetFile to (container of sourceFile as text) & targetName
       if exists file targetFile then delete file targetFile
       set name of (duplicate sourceFile) to targetName
       set end of targetFiles to (quoted form of POSIX path of targetFile) & space
   end repeat
end tell

   if dialogText = "All" then
       do shell script exifUtil & " -overwrite_original -all= -tagsFromFile @ -orientation " & targetFiles
   else if dialogButton = "Tag" then
       do shell script exifUtil & " -overwrite_original \"-*" & dialogText & "*=\" " & targetFiles
   else if dialogButton = "Group" then
       do shell script exifUtil & " -overwrite_original -" & dialogText & ":all= " & targetFiles
   end if
on error errorText
   do shell script "rm -f " & targetFiles
   display alert "ExifTool reported the following error:" message errorText as critical
end try

on errorDialog(errorText)
   display dialog errorText buttons "OK" cancel button 1 default button 1 with title "Exif Edit" with icon stop
end errorDialog

Last edited by peavine (Today 07:26:34 pm)

2018 Mac mini - macOS Catalina



Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)