Actions based on pixel height failing on some files

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

Moderator: Mr_Noodle

Hi,

I'm having a weird issue. I suspect it's mostly a Spotlight-based problem, but I'm still not sure and I'm not sure how to address it either.

I'm trying to tag movie files using Hazel based on the resolution (pixel height).
For most files it works just fine, but doesn't Hazel seems to be enable to detect the dimensions for some of the files.
If I use mdls in the Terminal, I can see the kMDItemPixelHeight value without any issue, but the Finder fails to display it (through the Preview in a window or command-i).
I used the Preview Rule command in Hazel on the same file and it gives me an error as well: -[NSDecimalNumber length]: unrecognized selector sent to instance 0x600003586900

So… I suspect something is wrong with the way Spotlight wrote the metadata it indexed on the file, but couldn't Hazel use the data obtained through mdls (which has the right values for the pixel height)?? Is there a way to get Haze to use that instead of wherever it reads the dimensions? I couldn't find a way to get it to read the directly in the rules.

Thanks!!

Corentin
cortig
 
Posts: 17
Joined: Thu Jan 06, 2022 11:49 am

As a workaround I'm trying to use a shell script like this:
Code: Select all
mdls $1 | grep kMDItemPixelHeight | awk -F \" '{if ($2 < 720) exit 1 }''

but all Hazel doesn't seem to understand the exit code trick I'm trying to play here.

Corentin
cortig
 
Posts: 17
Joined: Thu Jan 06, 2022 11:49 am

I think I found a way to get it to work through a double negative:
If note of the following conditions are met:
Passes shel script > embedded shell script > mdls $1 | grep kMDItemPixelHeight | awk -F \" '{if ($2 >= 720) exit 1 }'


A bit convoluted, but this works 100% of the time on my Mac where simply using the Pixel Height arguent in Hazel fails with that weird error code.

Now… I'm glad I found a workaround, but I'd still love to know why using Pixel Height sometimes fails.

Corentin
cortig
 
Posts: 17
Joined: Thu Jan 06, 2022 11:49 am

Is there any pattern to the files this happens with? Maybe check the app set to open that file to see if there's any pattern there?
Mr_Noodle
Site Admin
 
Posts: 11195
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

I can't figure out the difference. All files in my case are .mp4 files and for all of them, I can get the right information through the Spotlight metadata.

I tried looking at the details through dedicated apps like MediaInfo, etc, and couldn't spot what was different.

Corentin
cortig
 
Posts: 17
Joined: Thu Jan 06, 2022 11:49 am

Can you post the mdls dump for a file that works and a file that doesn't?
Mr_Noodle
Site Admin
 
Posts: 11195
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

One that works:
Code: Select all
% mdls /Users/me/Desktop/Works.mp4
_kMDItemDisplayNameWithExtensions      = "Works.mp4"
kMDItemAudioBitRate                    = 128
kMDItemAudioChannelCount               = 2
kMDItemCodecs                          = (
    "H.264",
    AAC
)
kMDItemContentCreationDate             = 2022-05-25 00:55:38 +0000
kMDItemContentCreationDate_Ranking     = 2022-05-25 00:00:00 +0000
kMDItemContentModificationDate         = 2022-05-25 03:14:47 +0000
kMDItemContentModificationDate_Ranking = 2022-05-25 00:00:00 +0000
kMDItemContentType                     = "public.mpeg-4"
kMDItemContentTypeTree                 = (
    "public.mpeg-4",
    "public.movie",
    "public.audiovisual-content",
    "public.data",
    "public.item",
    "public.content"
)
kMDItemDateAdded                       = 2022-05-26 13:11:01 +0000
kMDItemDateAdded_Ranking               = 2022-05-26 00:00:00 +0000
kMDItemDisplayName                     = "Works.mp4"
kMDItemDocumentIdentifier              = 0
kMDItemDurationSeconds                 = 6646.44
kMDItemFSContentChangeDate             = 2022-05-25 03:14:47 +0000
kMDItemFSCreationDate                  = 2022-05-25 00:55:38 +0000
kMDItemFSCreatorCode                   = ""
kMDItemFSFinderFlags                   = 0
kMDItemFSHasCustomIcon                 = (null)
kMDItemFSInvisible                     = 0
kMDItemFSIsExtensionHidden             = 0
kMDItemFSIsStationery                  = (null)
kMDItemFSLabel                         = 0
kMDItemFSName                          = "Works.mp4"
kMDItemFSNodeCount                     = (null)
kMDItemFSOwnerGroupID                  = 20
kMDItemFSOwnerUserID                   = 501
kMDItemFSSize                          = 1768827582
kMDItemFSTypeCode                      = ""
kMDItemInterestingDate_Ranking         = 2022-05-25 00:00:00 +0000
kMDItemKind                            = "MPEG-4 movie"
kMDItemLogicalSize                     = 1768827582
kMDItemMediaTypes                      = (
    Video,
    Sound
)
kMDItemPhysicalSize                    = 1768828928
kMDItemPixelHeight                     = 720
kMDItemPixelWidth                      = 1280
kMDItemStreamable                      = 0
kMDItemTotalBitRate                    = 2122
kMDItemUserTags                        = (
    HD
)
kMDItemVideoBitRate                    = 1994




And one that doesn't:
Code: Select all
% mdls /Users/me/Desktop/Doesn’t\ Work.mp4
_kMDItemDisplayNameWithExtensions      = "Does’t Work.mp4"
kMDItemAudioBitRate                    = 64
kMDItemAudioChannelCount               = 1
kMDItemCodecs                          = (
    "H.264",
    AAC
)
kMDItemContentCreationDate             = 2022-05-24 21:32:00 +0000
kMDItemContentCreationDate_Ranking     = 2022-05-24 00:00:00 +0000
kMDItemContentModificationDate         = 2022-05-24 21:32:51 +0000
kMDItemContentModificationDate_Ranking = 2022-05-24 00:00:00 +0000
kMDItemContentType                     = "public.mpeg-4"
kMDItemContentTypeTree                 = (
    "public.mpeg-4",
    "public.movie",
    "public.audiovisual-content",
    "public.data",
    "public.item",
    "public.content"
)
kMDItemDateAdded                       = 2022-05-26 12:59:28 +0000
kMDItemDateAdded_Ranking               = 2022-05-26 00:00:00 +0000
kMDItemDisplayName                     = "Does’t Work.mp4"
kMDItemDocumentIdentifier              = 0
kMDItemDurationSeconds                 = 2589.42
kMDItemFSContentChangeDate             = 2022-05-24 21:32:51 +0000
kMDItemFSCreationDate                  = 2022-05-24 21:32:00 +0000
kMDItemFSCreatorCode                   = ""
kMDItemFSFinderFlags                   = 0
kMDItemFSHasCustomIcon                 = (null)
kMDItemFSInvisible                     = 0
kMDItemFSIsExtensionHidden             = 0
kMDItemFSIsStationery                  = (null)
kMDItemFSLabel                         = 0
kMDItemFSName                          = "Does’t Work.mp4"
kMDItemFSNodeCount                     = (null)
kMDItemFSOwnerGroupID                  = 20
kMDItemFSOwnerUserID                   = 501
kMDItemFSSize                          = 309047805
kMDItemFSTypeCode                      = ""
kMDItemInterestingDate_Ranking         = 2022-05-24 00:00:00 +0000
kMDItemKind                            = "MPEG-4 movie"
kMDItemLogicalSize                     = 309047805
kMDItemMediaTypes                      = (
    Video,
    Sound
)
kMDItemPhysicalSize                    = 309051392
kMDItemPixelHeight                     = "720"
kMDItemPixelWidth                      = 1280
kMDItemStreamable                      = 0
kMDItemTotalBitRate                    = 945
kMDItemVideoBitRate                    = 881


It's interesting… One lists the pixel height with quotes and the other without. No idea why, but it might explain why the rule fails. Hazel might not be expecting the quotes.
cortig
 
Posts: 17
Joined: Thu Jan 06, 2022 11:49 am

Yeah, I believe what is happening is that while the property is defined as a number, the Spotlight importer is setting it as a string. Maybe try the mdimport command to see which Spotlight importer is handling that file.
Mr_Noodle
Site Admin
 
Posts: 11195
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

I tried that already :-)
Interestingly, the files I tried it on had pixel width as a string as well, and after running mdimporter, the value was converted to a number, but it didn't happen for pixel height. No matter how many times I tried it remained a string.

Corentin
cortig
 
Posts: 17
Joined: Thu Jan 06, 2022 11:49 am

Have you determined which importer is being used?
Mr_Noodle
Site Admin
 
Posts: 11195
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Mr_Noodle wrote:Have you determined which importer is being used?


These are standard mp4 files. They should be indexed with the built-in CoreMedia.mdimporter.
I checked my list of mdimporters and didn’t see anything else that might be susceptible to index them.

Is there any way to confirm which mdimporter was used to import the metadata?
cortig
 
Posts: 17
Joined: Thu Jan 06, 2022 11:49 am

It should be shown when doing "mdimport -t -d 3".
Mr_Noodle
Site Admin
 
Posts: 11195
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Mr_Noodle wrote:It should be shown when doing "mdimport -t -d 3".



My guess was accurate:
imported with plugIn /System/Library/Spotlight/CoreMedia.mdimporter

Corentin
cortig
 
Posts: 17
Joined: Thu Jan 06, 2022 11:49 am

…and s a side note, I noticed the if the rule I created fails because the height is between quotes, Hazel won’t run the following rule in the list and will just return a notification that it had failed.

Corentin
cortig
 
Posts: 17
Joined: Thu Jan 06, 2022 11:49 am

What version of macOS are you running?

EDIT:
Also, can you check the logs and see if you can find the error? Send me the full dump, plus a few lines before and after.
Mr_Noodle
Site Admin
 
Posts: 11195
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Next

Return to Support