Script for kMD metadata attributes - Mail Attachment

Get help. Get answers. Let others lend you a hand.

Moderator: Mr_Noodle

I need some conditions that don’t exist on the “Other…” menu.

I need to pass them one at a time

kMDItemDestinationRecipients
kMDItemOriginSenderHandle
kMDItemOriginSubject


I don’t have programming skills so I searched the forum for a solution using a script.
Here are some I tried but didn't work

https://www.noodlesoft.com/forums/viewtopic.php?f=4&t=2021&p=8434&hilit=THE+VALUE+THAT+YOU+ARE+INTERESTED+IN+MATCHING#p8434

https://www.noodlesoft.com/forums/viewtopic.php?f=4&t=688&p=21236&hilit=mdls#p21236

Here is the mdls output of the file I need to pass the conditions

joaoaraujo@MBP-M1-Joao-Araujo ~ % mdls /Users/joaoaraujo/Local\ Documents/Hazel\ Local\ Action/Hazel\ com\ senha/Fatura\ Claro.pdf
_kMDItemDisplayNameWithExtensions = "Fatura Claro.pdf"
com_apple_metadata_modtime = 734447919.65694
kMDItemContentCreationDate = 2024-04-10 13:18:39 +0000
kMDItemContentCreationDate_Ranking = 2024-04-10 00:00:00 +0000
kMDItemContentModificationDate = 2024-04-10 13:18:39 +0000
kMDItemContentType = "com.adobe.pdf"
kMDItemContentTypeTree = (
"com.adobe.pdf",
"public.data",
"public.item",
"public.composite-content",
"public.content"
)
kMDItemDateAdded = 2024-04-10 20:16:06 +0000
kMDItemDestinationRecipients = (
“XXXXXX@icloud.com"
)
kMDItemDisplayName = "Fatura Claro.pdf"
kMDItemDocumentIdentifier = 0
kMDItemFSContentChangeDate = 2024-04-10 13:18:39 +0000
kMDItemFSCreationDate = 2024-04-10 13:18:39 +0000
kMDItemFSCreatorCode = ""
kMDItemFSFinderFlags = 0
kMDItemFSHasCustomIcon = (null)
kMDItemFSInvisible = 0
kMDItemFSIsExtensionHidden = 0
kMDItemFSIsStationery = (null)
kMDItemFSLabel = 0
kMDItemFSName = "Fatura Claro.pdf"
kMDItemFSNodeCount = (null)
kMDItemFSOwnerGroupID = 20
kMDItemFSOwnerUserID = 501
kMDItemFSSize = 385947
kMDItemFSTypeCode = ""
kMDItemInterestingDate_Ranking = 2024-04-10 00:00:00 +0000
kMDItemKind = "PDF document"
kMDItemLogicalSize = 385947
kMDItemOriginApplicationIdentifier = "com.apple.mail"
kMDItemOriginMessageID = "27488"
kMDItemOriginSenderDisplayName = "Fatura Claro"
kMDItemOriginSenderHandle = "Fatura Claro <faturadigital@minhaclaro.com.br>"
kMDItemOriginSubject = "Sua fatura Claro Net por e-mail - 04/2024"
kMDItemPhysicalSize = 389120
SYDocumentRelatedUniqueIdentifierKey = "27488"
joaoaraujo@MBP-M1-Joao-Araujo ~ %
Last edited by aljjspam on Thu Apr 18, 2024 3:09 pm, edited 1 time in total.
aljjspam
 
Posts: 13
Joined: Wed May 15, 2019 1:51 pm

Re: Script for kMD metadata attributes Fri Apr 12, 2024 10:39 am • by Mr_Noodle
Are you sure it doesn't appear in the "Other" list? Even if you drop the "kMDItem" part, it might not have the same name.

As for the scripts, can you post your version of them that didn't work?
Mr_Noodle
Site Admin
 
Posts: 11255
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Re: Script for kMD metadata attributes Fri Apr 12, 2024 3:08 pm • by aljjspam
Mr_Noodle wrote:Are you sure it doesn't appear in the "Other" list? Even if you drop the "kMDItem" part, it might not have the same name.

As for the scripts, can you post your version of them that didn't work?


I'm sure there's no option on other, I also tried with HoudahSpot to see if I could find the name of the attribute since you can search by the KMD there. No luck.

I can find the file on Spotlight using kMDItemDestinationRecipients: XXXXXX@icloud.com

Is there a condition on Hazel to use custom attribute?

Thank you!


This are the scripts I tried:

Code: Select all
if [ "$(mdls -name kMDItemDestinationRecipients "$1"  | awk -F " = " '{print $2}')" == "XXXXXX@icloud.com" ];then exit 0; else exit 1; fi


Code: Select all
if [ `mdls -name kMDItemDestinationRecipients $1 | cut -d '"' -f2 -s | head -n 1 | grep "XXXXXX@icloud.com" ` ]; then
   exit 0
else
   exit 1
fi



I found this Post from 2014 asking the same thing:
https://www.noodlesoft.com/forums/viewtopic.php?f=2&t=3306
aljjspam
 
Posts: 13
Joined: Wed May 15, 2019 1:51 pm

Re: Script for kMD metadata attributes Mon Apr 15, 2024 8:33 am • by Mr_Noodle
Have you tried the scripts outside of Hazel? It will be easier to debug there.
Mr_Noodle
Site Admin
 
Posts: 11255
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Re: Script for kMD metadata attributes Thu Apr 18, 2024 3:08 pm • by aljjspam
Mr_Noodle wrote:Have you tried the scripts outside of Hazel? It will be easier to debug there.



I managed to make it work!
Thank you for replaying.

This is the code:

Code: Select all
if [ `mdls -name kMDItemDestinationRecipients "$1" | cut -d '"' -f2 -s | head -n 1 | grep “xxxx@icloud.com" ` ]; then
   exit 0
else
   exit 1
fi
aljjspam
 
Posts: 13
Joined: Wed May 15, 2019 1:51 pm


Return to Support

cron