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)

DougAdams 06-09-2005 10:31 AM

Spotlight, mdfind, date formats
 
I want to locate files using mdfind based on the meta-data tag kMDItemLastUsedDate (or any meta-data using a date for that matter). However, Apple's prescribed method does not work for me in Terminal:

Code:

mdfind "kMDItemFSContentChangeDate == $time.this_week" -onlyin "~"
Whereas, of course, something like this works fine:

Code:

mdfind 'kMDItemMediaTypes == "Sound" ' -onlyin "/~" | sort -fd | uniq
What's my trouble with the date format? Eventually, I want to use this query in an AppleScript do shell script routine.

TIA!

mark hunte 06-09-2005 11:16 AM

Hi Doug,

this works in terminal and as a do shell script,

I have been playing with these also too use them in AS, they are very handy.

Code:

mdfind -onlyin ~/  kMDItemFSContentChangeDate == $time.today
Also here is a script to quickly check metadata, I have it as a hot key using spark.
** Edit**

Code:

(* This script will open any selected file/s in finder  and  do a shell
script " mdls " to get the metadata of the file/s and display the result in a
Texedit document for each file
©Mark Hunte 2005 - feel free to use as you wish*)

tell application "Finder"
        set SiTem to selection
        repeat with i from 1 to number of items in SiTem
                set this_item to item i of SiTem as string
                set this_item to POSIX path of this_item
                do shell script "mdls " & quoted form of this_item & " | open -f"
               
        end repeat
end tell


DougAdams 06-09-2005 12:03 PM

Mark,

Hey, I owe you a six pack! It never occurred to me to re-arrange the parameters.

Have you seen this article I wrote on basic Spotlight scripting for iTunes?

Thanks again. This opens up WORLDS for me :)

mark hunte 06-09-2005 12:16 PM

That a good read..

Thanks

DougAdams 06-09-2005 12:32 PM

Drat....

It works with ~/ but any other directory returns up "". So, OK, what is wrong with this:

Code:

mdfind -onlyin '/Volumes/Media/Music/'  kMDItemLastUsedDate == $time.today
I'm looking for the files that iTunes played today in my "Music" directory.

mark hunte 06-09-2005 01:11 PM

I will have a look at that..

in the mean time I had a play and came up with this.
another way of dealing with the " ' " single quotes.
Do not know if I really need to put the try bits in but what the heck.
Also put in a -onlyin ~/Desktop/Music/ which works

Code:

tell application "iTunes"
       
        if selection of front browser window is not {} then
                set selected_track to item 1 of selection of front browser window
                -- get the tag data
                tell selected_track to set {nom, siz} to {name, size}
               
                set the_delim1 to do shell script "echo " & quoted form of nom & " " & " |awk -F\\' '{print $1}'"
                set the_delim2 to do shell script "echo " & quoted form of nom & " " & " |awk -F\\' '{print $2}'"
                set nom1 to the_delim1 & "\\'" & the_delim2
               
        end if
end tell

try
        set the_command to ("mdfind  -onlyin ~/Desktop/Music/ " & "\"kMDItemTitle == '" & nom & "' kMDItemFSSize == '" & siz & "'\"") as string
        set returned_list to (do shell script the_command)
        try
                set the_command2 to ("mdfind  -onlyin ~/Desktop/Music/ " & "\"kMDItemTitle == '" & nom1 & "' kMDItemFSSize == '" & siz & "'\"") as string
                set returned_list2 to (do shell script the_command2)
               
        end try
        return returned_list & returned_list2
end try


stetner 06-10-2005 06:37 AM

Quote:

Originally Posted by DougAdams
Drat....
\So, OK, what is wrong with this:

Code:

mdfind -onlyin '/Volumes/Media/Music/'  kMDItemLastUsedDate == $time.today
I'm looking for the files that iTunes played today in my "Music" directory.

It looks like the meta data does not get updated on an mp3 after it has been played. (I just finished listening to Jesus Is Just Alright)

$ mdls /Volumes/G5Repos/iTunes\ Music/The\ Doobie\ Brothers/Best\ Of\ The\ Doobies/07\ Jesus\ Is\ Just\ Alright.mp3
/Volumes/G5Repos/iTunes Music/The Doobie Brothers/Best Of The Doobies/07 Jesus Is Just Alright.mp3 -------------
kMDItemAlbum = "Best Of The Doobies"
kMDItemAttributeChangeDate = 2005-04-29 19:03:28 +1000
kMDItemAudioBitRate = 128
kMDItemAudioChannelCount = 2
kMDItemAudioEncodingApplication = "iTunes v1.0"
kMDItemAudioSampleRate = 44100
kMDItemAuthors = ("The Doobie Brothers")
kMDItemContentCreationDate = 2001-01-14 12:27:47 +1000
kMDItemContentModificationDate = 2004-09-11 12:28:07 +1000
kMDItemContentType = "public.mp3"
kMDItemContentTypeTree = (
"public.mp3",
"public.audio",
"public.audiovisual-content",
"public.data",
"public.item",
"public.content"
)
kMDItemDisplayName = "07 Jesus Is Just Alright.mp3"
kMDItemDurationSeconds = 827
kMDItemFSContentChangeDate = 2004-09-11 12:28:07 +1000
kMDItemFSCreationDate = 2001-01-14 12:27:47 +1000
kMDItemFSCreatorCode = 1752133483
kMDItemFSFinderFlags = 264
kMDItemFSInvisible = 0
kMDItemFSLabel = 4
kMDItemFSName = "07 Jesus Is Just Alright.mp3"
kMDItemFSNodeCount = 0
kMDItemFSOwnerGroupID = 80
kMDItemFSOwnerUserID = 503
kMDItemFSSize = 4414027
kMDItemFSTypeCode = 1297106739
kMDItemID = 837
kMDItemKind = "MP3 Audio File"
kMDItemLastUsedDate = 2004-09-11 12:28:07 +1000
kMDItemMediaTypes = (Sound)
kMDItemMusicalGenre = "Rock"
kMDItemTitle = "Jesus Is Just Alright"
kMDItemTotalBitRate = 128
kMDItemUsedDates = (2004-09-11 12:28:07 +1000)

DougAdams 06-10-2005 06:47 AM

Quote:

It looks like the meta data does not get updated on an mp3 after it has been played.
If a track plays all the way through then kMDItemLastUsedDate will be updated, thus:

kMDItemLastUsedDate = 2005-06-10 06:45:37 -0400

stetner 06-10-2005 09:06 AM

Quote:

Originally Posted by stetner
It looks like the meta data does not get updated on an mp3 after it has been played. (I just finished listening to Jesus Is Just Alright)

$ mdls /Volumes/G5Repos/iTunes\ Music/The\ Doobie\ Brothers/Best\ Of\ The\ Doobies/07\ Jesus\ Is\ Just\ Alright.mp3
/Volumes/G5Repos/iTunes Music/The Doobie Brothers/Best Of The Doobies/07 Jesus Is Just Alright.mp3 -------------
...
...
kMDItemUsedDates = (2004-09-11 12:28:07 +1000)

Except it does not seem to be updating here.....

Maybe DougAdams has the same problem as me....

Paul Berkowitz 02-17-2006 02:02 PM

This is an old thread, but I'm finding the same problem now in OS 10.4.5.

I cannot get any of the $time variables to work with mdfind. Does anyone know if this is a known bug? Or a better place to ask?

Here's a simple example. Create a New Event in iCal. Wait a min ute or two until a new item turns up in ~/Library/Caches/Metadata/iCal/ : sort that folder in List view in the Finder by Date Modified. When you see a subfolder with the modification date/time of the time you made the folder jump to the top, go inside it and, also sorted by List and Date Modified, the .icalevent at the top with the same Modified and Created date/time is the event. (Double-click it to be sure - it will open iCal to the correct event.)

In Terminal, type

mdfind -onlyin

and a pace, then drag the ~/Library/Caches/Metadata/iCal/ folder there. In my own case that results in:

250-166:~ berkowit$ mdfind -onlyin /Users/berkowit/Library/Caches/Metadata/iCal/

Now if you look for events with the name of the new one (e.g. "New Event") this way:

250-166:~ berkowit$ mdfind -onlyin /Users/berkowit/Library/Caches/Metadata/iCal/ "kMDItemTitle == '*New Event*'"

and press Return, that metadata file does show up in the list of results. (It will have the long GUUID name you see in the Finder.)

But if you use any of the $time methods, looking for items created or modified today, or since yesterday, or in the last hour (now(-3600)), you get no results at all:

mdfind -onlyin '/Users/berkowit/Library/Caches/Metadata/iCal/' "kMDItemContentModificationDate == $time.today"

mdfind -onlyin '/Users/berkowit/Library/Caches/Metadata/iCal/' "kMDItemContentModificationDate > $time.now(-3600)"

mdfind -onlyin '/Users/berkowit/Library/Caches/Metadata/iCal/' "kMDItemContentModificationDate > $time.yesterday"

mdfind -onlyin '/Users/berkowit/Library/Caches/Metadata/iCal/' "kMDItemContentCreationDate > $time.yesterday"

all produce zero results.

Am I doing something wrong, or is this a bug with mdfind?

Someone I know who does Carbon programming did it with MDQuery and says it works fine that way. (You have to create an application first...)

hayne 02-17-2006 02:27 PM

The following command works fine for me (on 10.4.5):

mdfind 'kMDItemFSCreationDate >= $time.yesterday'

Use 'mdls' to check one of the files you are expecting to find to see if the metadata is there.

Paul Berkowitz 02-17-2006 02:55 PM

I get no results for

mdfind 'kMDItemFSCreationDate >= $time.yesterday'

either, even omitting the -onlyin option. I.e., supposedly I have no files anywhere at all created on my computer since yesterday.

When I do an mdls on the file in question, all these date attributes show up there:

kMDItemContentCreationDate = 2006-02-17 10:32:06 -0800
kMDItemContentModificationDate = 2006-02-17 10:32:06 -0800
kMDItemFSContentChangeDate = 2006-02-17 10:32:06 -0800
kMDItemFSCreationDate = 2006-02-17 10:32:06 -0800

So why isn't mdfind finding it? I also tried:

mdfind "kMDItemFSCreationDate >= $time.iso(2006-02-17 10:32:06 -0800)"

and got no results.

Paul Berkowitz 02-17-2006 02:58 PM

Oops:

mdfind "kMDItemFSCreationDate >= $time.iso('2006-02-17 10:32:06 -0800')"

got no results either.

Paul Berkowitz 02-17-2006 03:00 PM

man mdfind has no mention of the $time variable anywhere - I just got that out of the Spotlight Carbon docs. Is there maybe something you need to enable somewhere to get it working?

hayne 02-17-2006 03:08 PM

Quote:

Originally Posted by Paul Berkowitz
Is there maybe something you need to enable somewhere to get it working?

Not as far as I know. I certainly didn't do anything special.
But do you have the developer tools installed? That might be one difference.

Paul Berkowitz 02-17-2006 03:51 PM

Yes, I have Xcode Tools 2.1 installed (about to install 2.2.1). But that shouldn't make any difference. This should work on any OS 10.4 computer: in fact it's essential of shell scripts I write are going to work on other users' computers.

It must be something else. I'll try a reboot soon.

hayne 02-17-2006 05:08 PM

Here's a Bash script that tests 'mdfind':
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`

for ((i=0; i < 100; i++)); do
    now=`date`
    filename="${now}.txt"
    echo "Current date is: $now" > "$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

Be careful that you haven't excluded the folders you are testing from Spotlight. When I first tried the above script it didn't seem to work since I was running it in a sub-folder of my ~/Dev folder which I had excluded from Spotlight.

I note that 'mdls' seems to list the metadata even if the files are not being indexed by Spotlight. E.g. the files under my ~/Dev folder show results from 'mdls' even though they are not subject to Spotlight.

Paul Berkowitz 02-17-2006 06:06 PM

Well, it works. Thank you, hayne. I was afraid it was going to keep going forever - when run from the Terminal it did not stop with the original 'now' because you keep resetting it, so thanks for that i < 100.

if ((i % 10 == 0)) may not quite work quite as you intended, but close enough. It made the folder, made one file, found it, made 10 more (up to 11) found them, etc. up to 91, made 9 more (up to 100) but never got to find them. It also never printed "Current date is: ..."

But it certainly found 91 files using
"mdfind -onlyin /Users/berkowit/1140216408 'kMDItemFSCreationDate >= $time.now(-3600)'"

(Each time it printed all of thm to date, so there were 91 at the end.)

Therefore $time.now(-3600) works in that directory. I can't understand why it doesn't work in the ~/Library/Metadata/iCal/ directory when it has not been excluded and mdfind works perfectly well on text attributes there.

Does this make any sense?

hayne 02-17-2006 06:18 PM

Quote:

Originally Posted by Paul Berkowitz
if ((i % 10 == 0)) may not quite work quite as you intended, but close enough. It made the folder, made one file, found it, made 10 more (up to 11) found them, etc. up to 91, made 9 more (up to 100) but never got to find them. It also never printed "Current date is: ..."

No - it works as intended.
Initially the index 'i' is zero, so the test 'if ((i % 10 == 0))' succeeds. The next time it succeeds is when i is 10 (the 11th iteration).
The "Current date is: ..." is being printed into the files that are created. Look at one of the files with 'cat' or your favourite text editor.

Quote:

Therefore $time.now(-3600) works in that directory. I can't understand why it doesn't work in the ~/Library/Metadata/iCal/ directory when it has not been excluded and mdfind works perfectly well on text attributes there.
Try running the script from that directory.
I.e. do:
cd ~/Library/Metadata/iCal
and then run the script (using the full path to the script if necessary)

stetner 02-17-2006 06:32 PM

Well, I would say it is a bit flakey (foo is an empty file) :
Code:

# 2362 $ touch foo

precious 09:25:12 ~
# 2362 $ mdls foo
foo -------------
kMDItemAttributeChangeDate = 1970-01-01 10:00:00 +1000
kMDItemFSContentChangeDate = 2006-02-18 09:20:48 +1000
kMDItemFSCreationDate      = 2006-02-18 09:20:48 +1000
kMDItemFSCreatorCode      = 0
kMDItemFSFinderFlags      = 0
kMDItemFSInvisible        = 0
kMDItemFSIsExtensionHidden = 0
kMDItemFSLabel            = 0
kMDItemFSName              = "foo"
kMDItemFSNodeCount        = 0
kMDItemFSOwnerGroupID      = 502
kMDItemFSOwnerUserID      = 502
kMDItemFSSize              = 0
kMDItemFSTypeCode          = 0
kMDItemID                  = 3275794
kMDItemLastUsedDate        = 2006-02-18 09:20:48 +1000
kMDItemUsedDates          = (2006-02-18 09:20:48 +1000)

precious 09:25:16 ~
# 2363 $ cat foo

precious 09:25:22 ~
# 2364 $ mdfind -onlyin '/Users/stetner/' 'kMDItemLastUsedDate > $time.now(-36000)' | grep foo

precious 09:25:26 ~
# 2365 $ mdfind -onlyin '/Users/stetner/' 'kMDItemLastUsedDate > $time.now(-360)' | grep foo

precious 09:25:33 ~
# 2366 $ mv foo foo.txt

precious 09:25:45 ~
# 2367 $ mdfind -onlyin '/Users/stetner/' 'kMDItemLastUsedDate > $time.now(-360)' | grep foo
/Users/stetner/foo.txt

precious 09:25:48 ~
# 2368 $ mv foo.txt foo

precious 09:26:22 ~
# 2369 $ mdfind -onlyin '/Users/stetner/' 'kMDItemLastUsedDate > $time.now(-360)' | grep foo
/Users/stetner/foo

So it did not see it untile I moved it to a '.txt' file but now it still sees it if I move it back to a file with no extension.

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.