MP3 tag from Finder

Hi.
It’s time to make order on my Playlist.

Can Finder read tags of a MP3?

I’ve seen one or two AS that, from iTunes, change the name of a file from name of a song with or without artis name (track1.mp3 → Tool - Wings For Marie.mp3).

But best for me si a droplet that read one of tag and change name of a track, hope without disturb iTunes.

A droplet like this

on open these_items
	repeat with i from 1 to number of items in these_items
		 set this_item to item i of these_items
		 set nametrack to something -- I need to know how to read name of a track from MP3
		 try
		 tell application "Finder" to set the name of this_item to nametrack
		 on error e
		 display dialog {nametrack & " already exists: write a new name:"} default answer ""  buttons {"OK"} default button 1 with icon note
end try
	end repeat
end open

Tnx to everyone

I’m pretty positive the finder cannot manipulate the id3 container. Your best bet, IMO, would be to install a command line app like id3tool and use that, via a droplet, to manipulate your songs.

Oh, I don’t want to manipolate, only read. I’ve cecked your link, but the apps appears too much difficult. I’ve seen that QuickTime can make this for me.

on run
	set these_items to choose file with prompt "Choose your file/s" with multiple selections allowed without invisibles
	process_item(these_items)
end run

on open these_items
	process_item(these_items)
end open

on process_item(these_items)
	tell application "QuickTime Player"
		launch
		activate
		close every movie saving no
		repeat with i from 1 to number of items in these_items
			set this_item to item i of these_items
			
			open this_item
			tell movie 1
				set nametrack to the full text of annotation "Full Name"
			end tell
			close every movie saving no
			
			tell application "Finder"
				set this_info to info for this_item
				set current_extension to the name extension of this_info
				
				set extension hidden of this_item to true
				set the name of this_item to (nametrack & "." & current_extension)
			end tell
		end repeat
	end tell
end process_item

This script works fine, but it also open every MP3 file in Quicktime for read “Full Name”: not much good and certanly not too much mac like. Any ideas for reading name of file without open it?

Hi Matteo,

I don’t know exactly, which name do you want to read,
but maybe Spotlight could help you

on run
	set these_items to choose file with prompt "Choose your file/s" with multiple selections allowed without invisibles
	process_item(these_items)
end run

on open these_items
	process_item(these_items)
end open

on process_item(these_items)
	repeat with i in these_items
		set theName to (do shell script "mdls " & quoted form of POSIX path of i & "| grep kMDItemTitle |cut -f 2 -d '\"' | cut -f 1 -d '\"'")
		tell application "Finder"
			set extension hidden of contents of i to true
			set name of contents of i to (theName & "." & name extension of i)
		end tell
	end repeat
end process_item

to read all spotlight metatags of a file use:

set inputFile to quoted form of POSIX path of (choose file with prompt "Select file" without invisibles)
set MetaData to (do shell script "mdls " & inputFile)

That’s fantastic!
Lot of tanks. Lot of lots!

Uhm.
I’ve studied. Now I’ve undestand what you mean with this command.
Then, I’ve add a Artist choice: but the problem is that if the Artist is a single word, the return is
kMDItemAuthors = (Enigma)

maybe if the Artist is two or more the return will becomes as
kMDItemAuthors = (“Gianna Nannini”)

So, here you are the solution.

set theAuthor to (do shell script "mdls " & quoted form of POSIX path of i & "| grep kMDItemAuthor |cut -f 2 -d '\"' | cut -f 1 -d '\"'")
		if theAuthor contains "kMDItemAuthor" then
			display dialog "change" -- this is only for debug
			set theAuthor to (do shell script "mdls " & quoted form of POSIX path of i & "| grep kMDItemAuthor | cut -f 2 -d '(' | cut -f 1 -d ')'")
		end if

So, the only problem that I have is that, in the full return of “mdls” I can’t see the track number. Is that impossibile?

Bye

ciao Matteo,

if you want to get multiple tags, there is a better way than calling the shell script a couple of times.
With the following script you get Track Number, Author and Title of the track.
The result is a list “nameList”, which contains the names of the tag and “valueList”, which contains the values.
Using text item delimiters solves also your problem with single or multiple word(s).
You can add further tags to to quoted argument after grep, separated by \|

set inputFile to quoted form of POSIX path of (choose file with prompt "Select file" without invisibles)
set kMDtags to paragraphs of (do shell script "mdls " & inputFile & "| grep 'kMDItemTitle\\|kMDItemAuthors\\|kMDItemAudioTrackNumber'")
set {nameList, valueList} to {{}, {}}
set TID to text item delimiters
repeat with i in kMDtags
	set text item delimiters to "="
	set end of nameList to word 1 of text item 1 of i
	set temp to words of text item 2 of i
	set text item delimiters to space
	set end of valueList to temp as string
end repeat
set text item delimiters to TID
nameList --> names of tags
valueList --> values of tags

Hey!
Your script is very, very intresting. Complicated as the others, but very usefull. Now, it’s time to study (again…)

I’ve tried to implement it into my script. But there is a problem in select area: your script works fine, but if I put it in a subroutine, it give me an error.

on open these_items
	process_method() -- this help me to indicate what the script have to do, not important here
	process_item(these_items)
end open

on process_item(these_items)
	
	repeat with i from 1 to number of items in these_items -- here! Script cannot gets number of item: why?
		set this_item to item i of these_items
		
		set kMDtags to paragraphs of (do shell script "mdls " & this_item & "| grep 'kMDItemTitle\\|kMDItemAuthors\\|kMDItemAudioTrackNumber'")
		display dialog "kMDtags= " & kMDtags
(...)
end process_item

Hi Matteo,

this_item is an alias, within a shell script you need a (quoted) POSIX path

set kMDtags to paragraphs of (do shell script "mdls " & quoted form of POSIX path of this_item & "| grep 'kMDItemTitle\\|kMDItemAuthors\\|kMDItemAudioTrackNumber'")

Right.
I know, I have many problem with alias. (so, have you any web reference to explain me everythin about alias in AppleScript???)

But in this case the script goes in error before “do shell script”!

The problem is here

repeat with i from 1 to number of items in these_items -- here! Script cannot gets number of item: why?

do you need the index variable? If not, use the repeat with oneItem in aList form

repeat with this_item in these_items 
	set kMDtags to paragraphs of (do shell script "mdls " & quoted form of POSIX path of this_item & "| grep 'kMDItemTitle\\|kMDItemAuthors\\|kMDItemAudioTrackNumber'")
	display dialog "kMDtags= " & kMDtags

otherwise try this form:

repeat with i from 1 to count these_items

Here is a tutorial for AppleScript beginners (in english), in chapter 12 is a good description about the several file classes
http://www.fischer-bayern.de/as/as4as/AS4AS_e.pdf

Uhm.
This command works fine ONLY if audio file is on startup disk. On others disk shell script give me an error.

:frowning:

The script uses spotlight to get the metadata. On a disk without a spotlight index (e.g. network volumes) it doesn’t work

yes. You are right.
mdls result is less longer when audio file is on another disk (I’ve tried another local HD).

This is a BIG problem.
do you think that the ONLY way to do this can be to

[i]- copy file on a temp folder on startup disk

  • do mdls command to this new one
  • delete it and, after, rename the original copy[/i]

I’m investigating… :confused:

Matteo, if your external volume is a local volume (i.e. not a network volume)
Spotlight can index it and you can retrieve the data with mdls.
(Spotlight can even index network volumes but will “forget” the information after a restart)

If indexing is disabled on a volume, you can enable it with the terminal:

sudo mdutil -i on "/Volumes/path to Volume"

note: the quotes are only needed, if there are spaces in the path

To start the indexing process type

sudo mdutil -E "/Volumes/path to Volume"