PNG Metadata "Comment"

I need help.
I’m trying to extract Metadata from a .PNG file especially the comment. I need to read and write this to the PNG file.

Anyone can shed some light on this…


Hey Bill,

Try the shell command:  mdls <POSIX_Path>

Type man mdls in the Terminal for more info.

That may suffice for the read portion of your macro.

When I want the 900lb gorilla of image info tools I trot out the shell program exiftool.


If you are speaking of the metadata embedded in the PNG (not Finder/Spotlight comments) you can also get them with ImageMagick:

identify -verbose <myfile.png>

The comment should be listed under “Properties”.


You can also preformat the output, for example:

identify -format 'Comment of file "%f" is: %[comment]\n' <myfile.png>


Comment of file "myfile.png" is: A new test comment

This might be handy for batch-exporting to a text file.

Format reference here.

To write a comment you can use:

convert <myfile.png> -set comment "A new comment" <myfile-out.png>

More info here.

1 Like

Thank you Ccstone and Tom much appreciated.

I have no option except to use exiftool. Now to figure out how the heck I’ll program what I need… :slight_smile:

Hey Bill,

Just out of curiosity – why can’t you use exiftool?

Next – how about being more more specific about exactly what metadata you’re trying to get.

EXIF data?

IPTC data?

Exactly what tag or tag names?

Once we know that there’s a greater chance we can help.


No It’s very fine and very powerful I am going to be using it… I was looking for a easier way…
Exiftool is good I’m poor on programing… Though I’ll figure it out… LOL…

When I get stuck I’ll be back… For the moment my health isn’t the best. Need plenty of rest…

Thank you again Ccstone :smiley:

Hey Bill,

Well, this is why you need to give us more details, so we can help you.  :sunglasses:

This should get you started.

# Get info with tag-names rather than just descriptions.
exiftool -s ~/"Downloads/test.jpg"

# Read Description:
exiftool -Description ~/"Downloads/test.jpg"

# Write Description:
exiftool -Description='My New Description' ~/"Downloads/test.jpg"

# Read IPTC Caption-Abstract:
exiftool -Caption-Abstract ~/"Downloads/test.jpg"

# Write IPTC Caption-Abstract:
exiftool -Caption-Abstract='My New Caption-Abtract' ~/"Downloads/test.jpg"

# Write IPTC Caption-Abstract and PREVENT the original from being backuped up by exiftool.
exiftool -overwrite_original_in_place -Caption-Abstract='My New Caption-Abtract' ~/"Downloads/test.jpg"

Holler if you need more help.


1 Like

Works also for PNG comments:

exiftool -comment <myfile.png>
exiftool -comment="New comment" <myfile.png>

Here is an index of all PNG tags.


Thank you :slight_smile: Much Appreciated :slight_smile:

This is a very good start… :slight_smile:

1 Like

How can I execute these in Execute a Shell Script I have tried and always have message.

Directly in terminal no problem....
I think I'm missing something.. I'm sure... "I'm no programmer" :slight_smile:

Thank you very much,

“command not found” indicates the shell is not finding the command, which happens because the PATH is not set correctly.

See the wiki troubleshooting section.

Have tried almost everything...

It is the command that cannot be found.

Ie, exiftool

You have installed it, and it is not somewhere the system can find it without specifying the full path to the command or specifying the search PATH environment variable.

Hi Bill,

you have to set KM’s ENV_PATH variable so that KM can find the command.

Yesterday I troubleshooted an analog problem with another user, so this series of posts may be helpful for you:

If you did install exiftool not with Homebrew, then find out the path(s) of your exiftool by executing this in the Terminal:

type -a exiftool

…and use the correct path as shown in the posts.

Thank you @peternlewis and @Tom Have it working now…

Hey Bill,

This stuff confuses all shell scripting newbies.

Unix systems (and others) use an environment variable ($PATH) to keep track of where to look for executables when they are called by name.

A basic path might look like this:


Mine on the other hand has had several things added to it.


If you want to be able to call exiftool by name it MUST be within the path, so Unix can see it.

Here’s where my copy of exiftool is installed:


You can always call a Unix exe by using its full-path.

/usr/local/bin/exiftool -s ~/Downloads/test.jpg

I have a Keyboard Maestro variable called ENV_PATH set to:


That lets Keyboard Maestro see everything in the given paths, and it doesn’t change my system $PATH variable.

So I can call exiftool from Keyboard Maestro without monkeying around.

exiftool -s ~/Downloads/test.jpg

Alternatively you can set the path when you call your shell script:

export PATH=/opt/local/bin:/opt/local/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin$PATH;
exiftool -s ~/Downloads/test.jpg

This is what I used to do before I started using Keyboard Maestro’s ENV_PATH variable.

Hopefully I’ve clarified things a bit instead of adding to the confusion.



OMG! WOW! Thank you @ccstone This helps so much! It’s like magic… :slight_smile:
Now I’m flying now… Whoohoo!

1 Like

Thanks for that. I see @JMichaelTX has already added some of the info to the Execute a Shell Script action page on the wiki, and I added a little more as well.

1 Like

I'm flying now... oops I hit a wall....

File name has space or spaces Shell don’t like spaces I have searched for a fix and I was unsuccessful.
From my understanding I should replace the space with & right?

Much appreciated,

Then quote the file names or paths:

exiftool ~/"my file/path with/spaces/my image.png"

You can escape spaces with the backslash \:

exiftool ~/my\ file/path\ with/spaces/my\ image.png
1 Like