IPhone – How to find out which photos were made by the iPhone and which were sent via WhatsApp

backupiphonemacmacosphotos

After a nice holiday I've often taken around 200 photos and 80% was made by myself, 10% was incoming WhatsApp pictures and 10% was some other pictures that ended up on my iPhone.

I don't even want the WhatsApp pictures automatically backed up by Carousel on my iPhone 6, but unfortunately there is no way to disable that.

Is there an easy way from my MacBook to filter out the pictures I made myself from the other pictures?

Best Answer

This makes use of the Exif info stored within the JPEG image file, some of which is indexed by Spotlight, however see the Notes: section below.

Here is a simple sample bash script to preform an action on any JPEG image files found in the working directory that was taken on a iPhone.

Copy and paste the code below into a plan text file, without an extension, and from a Terminal, make it executable using chmod +x filename where "filename" is the name you gave to the script file. Then place it in a directory that's in your $PATH, e.g /usr/local/bin, otherwise you'll have to provide the fully qualified pathname to the script file on the command line to execute it.

Now in a Terminal use the cd command to change to the target directory containing the JPEG image files you want to act upon, this becomes the target working directory, and type the name you gave to the script, then press Enter. It will echo the name of each JPEG image file that was taken on an iPhone.

  • Hint: To more easily navigate to the target working directory from within the Terminal, type cd followed by a space then drag and drop from Finder the target folder onto the Terminal window. This populates the fully qualified pathname for you and then you can just press Enter. You're now in the target working directory containing the JPEG image files.

Code:

#!/bin/bash

for f in *.jpg *.JPG; do
    x="$(mdls "$f" | grep -o 'iPhone')"
    if [[ ! -z "$x" ]]; then
        echo "$f was taken on an iPhone."
    fi
done

Now obviously you'll want it to do something other then just echo the name of a JPEG image file that was taken on an iPhone, so you'll have to add additional command(s) within the for ... done loop.

In this example I want all JPEG image files that were taken on an iPhone to be moved into a directory name "iPhone" within the working directory. So I modified the script accordingly.

Edited Code:

#!/bin/bash

if [[ ! -d "iPhone" ]]; then
    mkdir "iPhone"
fi

for f in *.jpg *.JPG; do
    x="$(mdls "$f" | grep -o 'iPhone')"
    if [[ ! -z "$x" ]]; then
        echo "$f was taken on an iPhone."
        mv -v "$f" "./iPhone/"
    fi
done

In Summary:

In the first if ... fi block [[ ! -d "iPhone" ]] tests for the existence of the "iPhone" directory within the current working directory and if it doesn't already exist, it's created by the mkdir command.

In the for ... done loop it only looks at files with extensions .jpg and .JPG. (I have both on my system.)

The $x variable will either be empty containing nothing "" or "iPhone" upon completion of the commands within the "$(...)" command substitution.

The output of the mdls command for the JPEG image file gets piped | to the grep command looking for iPhone and because of the -o option it's either going to be an empty string or the word "iPhone" that's returned, which becomes the content of the $x variable.

Therefore in the second if ... fi block [[ ! -z "$x" ]] tests to see that the "$x" variable is not an empty string and when it holds something, in this case being "iPhone", it's going to act upon that .jpg or .JPG file. In the case of $x not being an empty string, as it can only contain nothing or "iPhone", it moves that file into the "iPhone" directory within the working directory.

Notes:

Having tested this in several locations on both internal and external storage medium I noticed that in some places the files were stored and that while they did actually contain the model of the camera that created them nonetheless it was not reflected in the output of the mdls command as those locations were excluded from indexing by Spotlight. So using the, third-party supplied, exiftool command insured reading the information directly from the file itself and not relying on indexed information (or lack of indexed information) that the mdls command accesses.

So if you want to download and install ExifTool and use it, then change mdls to exiftool in the x="$(mdls "$f" | grep -o 'iPhone')" line of the script so it would look like x="$(exiftool "$f" | grep -o 'iPhone')".

In comparison on the same JPEG image file the exiftool command showed the values of 23 additional Tags that were not displayed by the mdls command. This may provide additional info to programmatically make the decision how to absolutely differentiate the source of the files by adding additional code to the script that would use info in the additional Tags, if necessary.