The macosxhints Forums

The macosxhints Forums (http://hintsforums.macworld.com/index.php)
-   UNIX - Newcomers (http://hintsforums.macworld.com/forumdisplay.php?f=15)
-   -   Spotlight, mdfind, date formats (http://hintsforums.macworld.com/showthread.php?t=40727)

hayne 02-17-2006 06:38 PM

It is well known that Spotlight only indexes those files that it recognizes as being textual in nature. For other types of files, it relies on applications providing an "importer".
If a file doesn't have an extension or a creator code or type code, then Spotlight will generally ignore it. It doesn't look inside the file to see if it can guess what type it is from the contents (like the 'file' command does).

I think that once it is indexed, however, the index follows it around by using its internal file-id instead of its name.

stetner 02-17-2006 06:41 PM

PS and my mp3s are still not getting updated. Listened to this in its entirety a few minutes ago with iTunes 6.03 on 10.4.5, not even a 2006 date!:

Code:

stetner 2396 $ mdls /Volumes/G5Repos/iTunes\ Music/Nena/Unknown\ Album/99\ Luft\ Balloons\ -\ German.mp3
/Volumes/G5Repos/iTunes Music/Nena/Unknown Album/99 Luft Balloons - German.mp3 -------------
kMDItemAttributeChangeDate = 1991-06-12 21:58:55 +1000
kMDItemFSContentChangeDate = 2005-06-27 00:53:52 +1000
kMDItemFSCreationDate      = 2004-06-29 00:55:37 +1000
kMDItemFSCreatorCode      = 0
kMDItemFSFinderFlags      = 0
kMDItemFSInvisible        = 0
kMDItemFSIsExtensionHidden = 0
kMDItemFSLabel            = 0
kMDItemFSName              = "99 Luft Balloons - German.mp3"
kMDItemFSNodeCount        = 0
kMDItemFSOwnerGroupID      = 80
kMDItemFSOwnerUserID      = 502
kMDItemFSSize              = 3778897
kMDItemFSTypeCode          = 0
kMDItemID                  = 693
kMDItemLastUsedDate        = 2005-06-27 00:53:52 +1000
kMDItemUsedDates          = (2005-06-27 00:53:52 +1000)


bramley 02-17-2006 06:45 PM

I ran into this problem with Spotlight in 10.4.4 from time to time.

The only way I seemed to ensure that it always worked was to calculate the number of seconds since midnight 01/01/2001 to the point in time I was interested in separately, and feed that number of seconds into the search.

I wrote an Applescript in this thread using this idea.

stetner 02-17-2006 06:49 PM

Quote:

Originally Posted by hayne
I think that once it is indexed, however, the index follows it around by using its internal file-id instead of its name.

OK, I can buy that, Actually I recall now that I have an apple bug report in on the fact that it does not index everything.

Still no joy on my mp3s and iTunes!

hayne 02-17-2006 06:50 PM

Quote:

Originally Posted by stetner
Code:

stetner 2396 $ mdls /Volumes/G5Repos/iTunes\ Music/Nena/Unknown\ Album/99\ Luft\ Balloons\ -\ German.mp3

I'm not sure if Spotlight indexes external disks by default. I think you need to do something to tell it to do that. There was at least one macosxhints article about this.

Paul Berkowitz 02-17-2006 07:24 PM

Well, it was an odd intenrion to make files 91-100 but not try to find them then. ;-) it looked to me rather as if you hadn't noticed that you had not yet incremented i yet. Never mind, that's not important.

I have to run now, but I'm going to check later. I'm wondering if maybe using $time somehow constrains mdfind not to look in subdirectories - although it does so for text attributes. That seems to peculiar that it's hard to believe, but it's the only thikng that looks even halfway plausible at the moment.

hayne 02-17-2006 07:56 PM

Quote:

Originally Posted by Paul Berkowitz
I'm wondering if maybe using $time somehow constrains mdfind not to look in subdirectories - although it does so for text attributes. That seems to peculiar that it's hard to believe, but it's the only thikng that looks even halfway plausible at the moment.

No - that isn't it either. Try this slightly modified script:
Code:

#!/bin/bash

# This script is intended for testing the 'mdfind' utility
# Cameron Hayne (macdev@hayne.net)  February 2006

dirname=`date +%s`
mkdir $dirname
echo "Created directory \"$dirname\""
cd $dirname
cwd=`pwd`
subdir="Data"
mkdir "$subdir"

for ((i=0; i < 100; i++)); do
    now=`date`
    filename="${now}.txt"
    echo "Current date is: $now" > "$subdir/$filename"
    echo "Created file #$((i+1)) \"$filename\""
    sleep 3

    if ((i % 10 == 0)); then
        criterion="'kMDItemFSCreationDate >= \$time.now(-3600)'"
        command="mdfind -onlyin $cwd $criterion"
        echo "Files found by \"$command\":"
        eval $command
    fi
done


Paul Berkowitz 02-17-2006 10:38 PM

It looks like I was right. The scrip abobe creates the files, but every time it tries to use mdfind to find them, I get this:

Files found by "mdfind -onlyin /Users/berkowit/1140233658 'kMDItemFSCreationDate >= $time.now(-3600)'":
-bash: Data/eval: No such file or directory

So there we are: OMM, mdfind -onlyin /Users/berkowit/1140233658 can't find any of the 100 files in its subfolder Data when using $time.now().

But on yours it can?

hayne 02-18-2006 12:25 AM

Quote:

Originally Posted by Paul Berkowitz
It looks like I was right. The scrip abobe creates the files, but every time it tries to use mdfind to find them, I get this:

Files found by "mdfind -onlyin /Users/berkowit/1140233658 'kMDItemFSCreationDate >= $time.now(-3600)'":
-bash: Data/eval: No such file or directory

So there we are: OMM, mdfind -onlyin /Users/berkowit/1140233658 can't find any of the 100 files in its subfolder Data when using $time.now().

No - you seem to be getting an error from the Bash script when you run it.
So the script is failing for some reason. I don't think you have really tested mdfind at all here.
I've been trying to figure out what might make the script give that error message but I haven't got any ideas yet. It is very strange.
Why would it say "Data/eval: No such file or directory" ?
I really can't figure out what circumstances would lead to that error message.

Could you please try a few things?
First off make sure that your script has the correct (Unix style) line endings. There is a section in this Unix FAQ about the line endings issue. That section has a one-line Perl script that will fix the line endings if needed. I mention that since incorrect line endings sometimes result in strange error messages.

Secondly, try changing the name of the subdir - e.g. make it be:
subdir=Paul
instead of
subdir=Data
This is just to verify that the name in the error message is indeed the name of the subdir.

stetner 02-24-2006 07:19 AM

Quote:

Originally Posted by hayne
I'm not sure if Spotlight indexes external disks by default. I think you need to do something to tell it to do that. There was at least one macosxhints article about this.

No, I thought of that one and I do have indexing on that volume :) :
Code:

sudo mdutil -s /Volumes/*
Password:
/Volumes/BackupG5:
        Status: Indexing Enabled
/Volumes/Douglas Stetner’s iPod:
        Status: Indexing Enabled
/Volumes/G5Repos:
        Status: Indexing Enabled
/Volumes/Precious:
        Status: Indexing Enabled
/Volumes/Zoideberg:
        Status: Indexing Disabled


hayne 02-24-2006 08:50 AM

Paul Berkowitz:
Any more word on that script - did you figure out what was going wrong with it? (see my suggestions above)

stetner:
Is the problem perhaps confined to iTunes? What if you manually modify one of the MP3 files on that volume - does the change show up in the results from 'mdls' and/or 'mdfind' ?

stetner 02-25-2006 12:09 AM

Quote:

Originally Posted by hayne
Is the problem perhaps confined to iTunes? What if you manually modify one of the MP3 files on that volume - does the change show up in the results from 'mdls' and/or 'mdfind' ?

If I play the tune with Quicktime it still does not update. If I 'touch' the file it updates

Code:

Original today:
kMDItemFSContentChangeDate = 2005-06-27 00:53:52 +1000
kMDItemFSCreationDate      = 2004-06-29 00:55:37 +1000
kMDItemLastUsedDate        = 2005-06-27 00:53:52 +1000
kMDItemUsedDates          = (2005-06-27 00:53:52 +1000)

After play with QT:
kMDItemFSContentChangeDate = 2005-06-27 00:53:52 +1000
kMDItemFSCreationDate      = 2004-06-29 00:55:37 +1000
kMDItemLastUsedDate        = 2005-06-27 00:53:52 +1000
kMDItemUsedDates          = (2005-06-27 00:53:52 +1000)

After touch:
kMDItemFSContentChangeDate = 2006-02-25 13:56:07 +1000
kMDItemFSCreationDate      = 2004-06-29 00:55:37 +1000
kMDItemLastUsedDate        = 2006-02-25 13:56:07 +1000
kMDItemUsedDates          = (2006-02-25 13:56:07 +1000)


hayne 02-25-2006 01:13 AM

For the songs that I have tried (that are on my internal disk), it seems that playing them in iTunes (by selecting them in the list and pressing the Play button) does not update the LastUsed entry.
But if I use the command-line 'open' to play the file then it does update "Last Used". (And 'open' does play the song in iTunes since that is the app registered for MP3's)

I selected "Free Man in Paris" from the list in iTunes and started it playing. I waited until the song ended.
Then I went into the Terminal and ran the following commands:
Code:

% mdls "iTunes/iTunes Music/Joni Mitchell/Court and Spark/Free Man In Paris.mp3" | grep Used
kMDItemLastUsedDate            = 2000-09-04 20:06:54 -0400
kMDItemUsedDates              = (2000-09-04 20:06:54 -0400)

% open "iTunes/iTunes Music/Joni Mitchell/Court and Spark/Free Man In Paris.mp3"           

% mdls "iTunes/iTunes Music/Joni Mitchell/Court and Spark/Free Man In Paris.mp3" | grep Used
kMDItemLastUsedDate            = 2006-02-25 01:06:08 -0500
kMDItemUsedDates              = (2000-09-04 20:06:54 -0400, 2006-02-24 19:00:00 -0500)


stetner 02-25-2006 01:32 AM

Now we are onto something! 'open seems to do a whole lot....
Code:

2461 $ mdls /Volumes/G5Repos/iTunes\ Music/Nena/Unknown\ Album/99\ Red\ Balloons\ \(English\).mp3
/Volumes/G5Repos/iTunes Music/Nena/Unknown Album/99 Red Balloons (English).mp3 -------------
kMDItemAttributeChangeDate = 1970-01-01 16:43:07 +1000
kMDItemFSContentChangeDate = 2005-06-27 00:53:52 +1000
kMDItemFSCreationDate      = 2004-06-29 00:56:45 +1000
kMDItemFSCreatorCode      = 0
kMDItemFSFinderFlags      = 0
kMDItemFSInvisible        = 0
kMDItemFSIsExtensionHidden = 0
kMDItemFSLabel            = 0
kMDItemFSName              = "99 Red Balloons (English).mp3"
kMDItemFSNodeCount        = 0
kMDItemFSOwnerGroupID      = 80
kMDItemFSOwnerUserID      = 502
kMDItemFSSize              = 3752147
kMDItemFSTypeCode          = 0
kMDItemID                  = 694
kMDItemLastUsedDate        = 2005-06-27 00:53:52 +1000
kMDItemUsedDates          = (2005-06-27 00:53:52 +1000)

precious 16:27:02 ~
2462 $ open  /Volumes/G5Repos/iTunes\ Music/Nena/Unknown\ Album/99\ Red\ Balloons\ \(English\).mp3

precious 16:27:13 ~
2463 $ mdls /Volumes/G5Repos/iTunes\ Music/Nena/Unknown\ Album/99\ Red\ Balloons\ \(English\).mp3
/Volumes/G5Repos/iTunes Music/Nena/Unknown Album/99 Red Balloons (English).mp3 -------------
kMDItemAttributeChangeDate    = 2006-02-25 16:27:18 +1000
kMDItemAudioBitRate            = 128
kMDItemAudioChannelCount      = 2
kMDItemAudioSampleRate        = 44100
kMDItemAuthors                = (Nena)
kMDItemComment                = "buy"
kMDItemContentCreationDate    = 2004-06-29 00:56:45 +1000
kMDItemContentModificationDate = 2005-06-27 00:53:52 +1000
kMDItemContentType            = "public.mp3"
kMDItemContentTypeTree        = (
    "public.mp3",
    "public.audio",
    "public.audiovisual-content",
    "public.data",
    "public.item",
    "public.content"
)
kMDItemDisplayName            = "99 Red Balloons (English).mp3"
kMDItemDurationSeconds        = 234
kMDItemFSContentChangeDate    = 2005-06-27 00:53:52 +1000
kMDItemFSCreationDate          = 2004-06-29 00:56:45 +1000
kMDItemFSCreatorCode          = 0
kMDItemFSFinderFlags          = 0
kMDItemFSInvisible            = 0
kMDItemFSIsExtensionHidden    = 0
kMDItemFSLabel                = 0
kMDItemFSName                  = "99 Red Balloons (English).mp3"
kMDItemFSNodeCount            = 0
kMDItemFSOwnerGroupID          = 80
kMDItemFSOwnerUserID          = 502
kMDItemFSSize                  = 3752147
kMDItemFSTypeCode              = 0
kMDItemID                      = 694
kMDItemKind                    = "MP3 Audio File"
kMDItemLastUsedDate            = 2006-02-25 16:27:13 +1000
kMDItemMediaTypes              = (Sound)
kMDItemTitle                  = "99 Red Balloons (English)"
kMDItemTotalBitRate            = 128
kMDItemUsedDates              = (2006-02-25 16:27:13 +1000, 2006-02-25 10:00:00 +1000)

Look at all the new stuff that open has put in.....

Interesting!

Hal Itosis 02-25-2006 11:46 AM

Hmmm, the composer field isn't part of a song's metadata!
Comments are included, but not the composer.
That's kinda lame.


All times are GMT -5. The time now is 10:20 PM.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.
Site design © IDG Consumer & SMB; individuals retain copyright of their postings
but consent to the possible use of their material in other areas of IDG Consumer & SMB.