custom document properties of pdf files

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

Moderator: Mr_Noodle

custom document properties of pdf files Tue Mar 12, 2013 11:39 am • by Graf_Wetter
Hi,
I want Hazel to go into custom document properties of pdf files.
These custom properties are added to the files in former workflows.
For example:
custom property = "colormode"
value = "cmyk"

Now I want Hazel to look for these custom values for further handling.

Possible ? Maybe with a script ?


Thanks,
Jorg
Graf_Wetter
 
Posts: 37
Joined: Thu Aug 25, 2011 7:18 am

Re: custom document properties of pdf files Tue Mar 12, 2013 12:24 pm • by a_freyer
Yes, there are several ways that you can access this kind of custom data. But first, you need to know the actual name of the custom property.

To do this, open terminal, and run mdls on the file:

Code: Select all
mdls /path/to/my/file.pdf


Scan the result for what you're interested in, and make a note of the name of the property. Odds are, it will have a prefix like kMDItemCustomProperty.

Matching based on known custom properties

If you want to MATCH based on a property's value, you can do this:

Code: Select all
if [ "$(mdls -name kMDItemName "$1"  | awk -F " = " '{print $2}')" == "THE VALUE THAT YOU ARE INTERESTED IN MATCHING" ];then exit 0; else exit 1; fi


And place this embedded script within an "passes shell script" condition. Your rule will match every file whose custom property is what you're interested in finding.


Using custom properties as tokens
You can use this applescript and applescript hazel tokens to extract custom field information.

Code: Select all
set posixPath to quoted form of (POSIX path of theFile) as string
set theCustomToken to (do shell script "/usr/bin/mdls -name kMDItemName " & posixPath & " | awk -F ' = ' '{print $2}'")
return {hazelExportTokens:{theCustomTokenValue:theCustomToken}}


Then you can use the token however you'd like!
a_freyer
 
Posts: 631
Joined: Tue Sep 30, 2008 9:21 am
Location: Colorado

Thanks for your reply.

I tried running mdls on a test-pdf with a custom property "test" and its value "testvalue" added.
Unfortunatelly mdls doesn´t list them.

This is the output:

Code: Select all
mdls /Users/jpreussmann/Desktop/Test.pdf
kMDItemContentCreationDate          = 2013-03-13 12:05:25 +0000
kMDItemContentModificationDate      = 2013-03-13 12:05:42 +0000
kMDItemContentType                  = "com.adobe.pdf"
kMDItemContentTypeTree              = (
    "com.adobe.pdf",
    "public.data",
    "public.item",
    "public.composite-content",
    "public.content"
)
kMDItemDateAdded                    = 2013-03-13 12:05:25 +0000
kMDItemDisplayName                  = "Test.pdf"
kMDItemEncodingApplications         = (
    "Enfocus PitStop Pro 10, update 3"
)
kMDItemFSContentChangeDate          = 2013-03-13 12:05:42 +0000
kMDItemFSCreationDate               = 2013-03-13 12:05:25 +0000
kMDItemFSCreatorCode                = "CARO"
kMDItemFSFinderFlags                = 8
kMDItemFSHasCustomIcon              = 0
kMDItemFSInvisible                  = 0
kMDItemFSIsExtensionHidden          = 0
kMDItemFSIsStationery               = 0
kMDItemFSLabel                      = 4
kMDItemFSName                       = "Test.pdf"
kMDItemFSNodeCount                  = 8948
kMDItemFSOwnerGroupID               = 20
kMDItemFSOwnerUserID                = 501
kMDItemFSSize                       = 8948
kMDItemFSTypeCode                   = "PDF "
kMDItemKind                         = "Adobe PDF document"
kMDItemLastUsedDate                 = 2013-03-13 12:30:37 +0000
kMDItemLogicalSize                  = 8948
kMDItemNumberOfPages                = 1
kMDItemPageHeight                   = 841.89
kMDItemPageWidth                    = 595.276
kMDItemPhysicalSize                 = 12288
kMDItemSecurityMethod               = "None"
kMDItemUseCount                     = 2
kMDItemUsedDates                    = (
    "2013-03-12 23:00:00 +0000"
)
kMDItemVersion                      = "1.6"
kMDLabel_kqde5prblvaibjifrcn4saxjwi = 2013-03-13 12:07:00 +0000
Graf_Wetter
 
Posts: 37
Joined: Thu Aug 25, 2011 7:18 am

Re: custom document properties of pdf files Wed Mar 13, 2013 11:00 am • by a_freyer
Alright, lets move from here. In what program/workflow are you entering these custom values?
a_freyer
 
Posts: 631
Joined: Tue Sep 30, 2008 9:21 am
Location: Colorado

Acrobat Pro

my custom properties seem to become xmp metadata:

Image
Image
Graf_Wetter
 
Posts: 37
Joined: Thu Aug 25, 2011 7:18 am

Re: custom document properties of pdf files Wed Mar 13, 2013 4:36 pm • by a_freyer
If I'm not mistaken, exiftool can read this. If you'd like, install and try:

Code: Select all
/usr/bin/exiftool -XMP -b /my/pdf.pdf
a_freyer
 
Posts: 631
Joined: Tue Sep 30, 2008 9:21 am
Location: Colorado

Re: custom document properties of pdf files Tue Mar 19, 2013 12:58 pm • by Graf_Wetter
Success !
It works with exiftool.

This is the script with the few changes for exiftool, with "AN" as the custom XMP property:
Code: Select all
set posixPath to quoted form of (POSIX path of theFile) as string
set AN to (do shell script "/usr/bin/exiftool -AN " & posixPath & " | awk -F ' : ' '{print $2}'")
return {hazelExportTokens:{Auftragsnummer:AN}}

In fact the only thing to remember is to change the delimiter from "=" to ":"

a_freyer, thanks for your ideas ...
Graf_Wetter
 
Posts: 37
Joined: Thu Aug 25, 2011 7:18 am

Re: custom document properties of pdf files Tue Mar 19, 2013 1:00 pm • by a_freyer
Great! I'm glad you found success!
a_freyer
 
Posts: 631
Joined: Tue Sep 30, 2008 9:21 am
Location: Colorado

Re: custom document properties of pdf files Thu Jun 27, 2013 12:41 am • by ThomasJohn
My many doubts have been clear after reading the above things as I was also little bit confused about it.
ThomasJohn
 
Posts: 1
Joined: Thu Jun 27, 2013 12:38 am


Return to Support