Retrieving EXIF, and adding WhereFrom

Hi,

I’m trying to solve a problem created by a recent point update to macOS Sequoia, that means the operating system is no longer generating WhereFrom metadata for video files that are airdropped to the Mac from an iOS device.

I have a nice Hazel workflow that keys on this information, which is now unfortunately broken.

The challenge is I have several iOS devices, and they each need to have different processing done upon them (moving them to set destinations), depending on what device they’re from.

I’ve found a nice commandline solution that can add the metadata necessary:

xattr -w com.apple.metadata:kMDItemWhereFroms TheWhereFromKeyWord /path/to/the.MOV

…which works a treat when applied manually to a file, the WhereFrom does its job in being picked up by Hazel (which cant work directly with EXIF), but I need to figure out if there’s a way to incorporate a step which interrogates the file’s EXIF data, finds the device model, and then applies the appropriate WhereFrom for Hazel to then key against.

Hazel has options to Run a Shell Script, AppleScript, javascript, either embedded or as an external file, which I can add as the first step when the file arrives in ~/Downloads.

For Shell scripts it advises to use $1 to refer to the file being processed, for AppleScript, use theFile to refer to the file being processed, and inputAttributes to access imported attributes…

…and that’s where my understanding of things hits the wall.

It needs some sort of if / then operation where:

 if (a model name)
    xattr -w com.apple.metadata:kMDItemWhereFroms TheFirstWhereFrom

else if (another model name)
    xattr -w com.apple.metadata:kMDItemWhereFroms TheSecondWhereFrom

…perhaps the model names need to be variables, which are set by separate functions that have the template to compare against to get a true / false answer?

My scripting / programming knowledge is barely rudimentary, so apologies… I have a sort of idea of what needs to be done, but that’s about it.

If anyone could provide pointers, I know one thing about myself, I learn concepts by seeing them working, not by understanding the theory beforehand, so help would be appreciated.

Thanks.

metaning. I don’t use Hazel and don’t completely understand your work flow. As regards the above, you can get the device model and test for that using the following AppleScript. In the if statement, I use a dialog just for testing and you would use the xattr shell command instead.

set theFile to POSIX path of (choose file) --this is just for testing to get a path

set theModel to do shell script "/usr/bin/mdls -raw -name kMDItemAcquisitionModel " & quoted form of theFile

if theModel is "Galaxy S25+" then
	display dialog "The device model is Galaxy S25+"
else if theModel is "iPhone 18" then
	display dialog "The device model is iPhone 18"
else
	display dialog "The device model was not found"
end if

This script worked as expected on my computer with macOS Golden Gate 27. It requires a folder that is indexed by Spotlight but that would normally be the case with ~/Downloads.

EDIT:

I just ran my script on an MP4 created on my phone, and the returned metadata did not include a device name or model. You can run the following in Script Editor on one of the video files to see if the metadata returned can be of use. If not, another approach will be necessary.

set theFile to POSIX path of (choose file) --this is just for testing to get a path

set theModel to do shell script "/usr/bin/mdls " & quoted form of theFile

Hi Peavine,

Just to address your edit first, this Applescript works to correctly return the WhereFrom on a file I’ve set it on:

set theFile to POSIX path of (choose file) --this is just for testing to get a path

set theModel to do shell script "/usr/bin/mdls -name kMDItemWhereFroms " & quoted form of theFile

It comes back with

"kMDItemWhereFroms = (
    Manifesto
)"

Which is the name of the Device I set with the xattr command.

I note with the version you placed results in:

"_kMDItemDisplayNameWithExtensions                = \"IMG_0695.MOV\"
kMDItemAestheticScore                            = 0.2020264
kMDItemAudioBitRate                              = 151
kMDItemAudioChannelCount                         = 2
kMDItemCodecs                               = (
    HEVC,
    \"MPEG-4 AAC\",
    \"Timed Metadata\"
)
kMDItemContentCreationDate                       = 2026-12-03 06:21:34 +0000
kMDItemContentCreationDate_Ranking               = 2026-12-03 00:00:00 +0000
kMDItemContentModificationDate                   = 2026-12-03 06:21:34 +0000
kMDItemContentRating                             = 0
kMDItemContentType                               = \"com.apple.quicktime-movie\"
kMDItemContentTypeTree                           = (
    \"com.apple.quicktime-movie\",
    \"public.movie\",
    \"public.audiovisual-content\",
    \"public.data\",
    \"public.item\",
    \"public.content\"
)
kMDItemDateAdded                               = 2026-12-03 16:24:40 +0000
kMDItemDisplayName                               = \"IMG_0695.MOV\"
kMDItemDocumentIdentifier                        = 0
kMDItemDurationSeconds                           = 7.926666666666667
kMDItemEncodingApplications                      = (
    \"18.7.8\"
)
kMDItemFSContentChangeDate                       = 2026-12-03 06:21:34 +0000
kMDItemFSCreationDate                            = 2026-12-03 06:21:34 +0000
kMDItemFSCreatorCode                             = \"\"
kMDItemFSFinderFlags                             = 0
kMDItemFSHasCustomIcon                           = 0
kMDItemFSInvisible                               = 0
kMDItemFSIsExtensionHidden                       = 0
kMDItemFSIsStationery                            = 0
kMDItemFSLabel                               = 0
kMDItemFSName                               = \"IMG_0695.MOV\"
kMDItemFSNodeCount                               = 11052540
kMDItemFSOwnerGroupID                            = 20
kMDItemFSOwnerUserID                             = 502
kMDItemFSSize                               = 11052540
kMDItemFSTypeCode                               = \"\"
kMDItemInterestingDate_Ranking                   = 2026-12-03 00:00:00 +0000
kMDItemKind                               = \"QuickTime movie\"
kMDItemLatitude                               = -26.3979
kMDItemLogicalSize                               = 11052540
kMDItemLongitude                               = 153.0682
kMDItemMediaAnalysisLastAttempt                  = (null)
kMDItemMediaTypes                               = (
    Video,
    Sound,
    Metadata
)
kMDItemPhotosCharacterRecognitionAnalysisVersion = (null)
kMDItemPhotosSceneAnalysisVersion                = (null)
kMDItemPhotosSceneClassificationConfidences      = (null)
kMDItemPhotosSceneClassificationIdentifiers      = (null)
kMDItemPhotosSceneClassificationLabels           = (null)
kMDItemPhotosSceneClassificationMediaTypes       = (null)
kMDItemPhotosSceneClassificationSynonyms         = (null)
kMDItemPhotosSceneClassificationSynonymsCounts   = (null)
kMDItemPhotosSceneClassificationTypedIdentifiers = (
    \"1-16796\",
    \"1-15169\"
)
kMDItemPhotosSceneClassificationTypes            = (null)
kMDItemPhysicalSize                              = 11055104
kMDItemPixelHeight                               = 1920
kMDItemPixelWidth                               = 1080
kMDItemProfileName                               = \"HD (1-1-1)\"
kMDItemStreamable                               = 0
kMDItemTotalBitRate                              = 11138
kMDItemVideoBitRate                              = 10952
kMDItemWhereFroms                               = (
    Manifesto
)"

What it’s not returning is EXIF data: al the GPS data, the LensModel[Keys], Make[Keys] and Model[Keys]

If there’s no capability within the built in commandline tools to get EXIF, would a path be to install EXIFTool and hook into its commandline tools to get the Device / Camera, and then pass that through to the xattr command based on the result it returns?


To continue,

Thanks for the response - I probably should have included screen captures of the app to be clear for folks who don’t use Hazel (It’s conceptually similar to Automator plus Folder Actions)…

Here’s the workflow as it was:

The thought would be to add a step before the file is moved to ~/Movies:

And the script can be edited in here, or referred to as an external file:

In set the model, is that navigating to the path where the command resides that I would normally be calling upon when entering the command in terminal?

You’re suggesting instead of dispay dialogue, I just put in:

xattr -w com.apple.metadata:kMDItemWhereFroms TheWhereFromKeyWord

without a path to the file, because that’s implicit in the AppleScript as a whole being invoked against the file?

Do I include the first line at all, given is looks to me like its purpose is to spawn a file browser, and Hazel is feeding a file to the script?

I really appreciate your help, this is looking like it’ll be very empowering if it works out.