Filename to Title Tag for .m4a files?

Hi All,
I’m a returning Mac user (devoted follower from '87-'00, switched to Windows 'cause of a new job, now back to Mac as of 2 months ago).

Here’s what I’m trying to do:

I have a folder of .m4a files. I want to import them to iTunes but their Title tags are blank. Consequently when I import them they don’t get song titles. The names of the files accurately reflect the song titles, so, I’d like to copy the filenames (minus the “.m4a” extension) to the Title field of the tag so that when I import them all to iTunes they’ll be cataloged correctly.

I’ve searched high and low for an Applescript or Automator script to copy the filename and replace the Title tag with it but haven’t turned up anything. This seems pretty basic so I’m wondering if I’m missing something.

Any ideas?

Many thanks in advance!
n

Welcome. :slight_smile:

Try something like this:

tell application "iTunes"
	set selectedTracks to selection
	
	if selectedTracks is {} then
		display alert "No tracks selected." message "You must select tracks in iTunes before using this script." buttons {"Cancel"} default button 1 cancel button 1
	end if
	
	repeat with thisItem in selectedTracks
		-- Ignore tracks that aren't local files
		if class of thisItem is file track then
			nameWithoutExtension of me for (location of thisItem)
			set name of thisItem to result
		end if
	end repeat
end tell

on nameWithoutExtension for someAlias
	tell (info for someAlias) to return text 1 thru ((my (offset of ("." & name extension & ":") in (name & ":"))) - 1) of name
end nameWithoutExtension

Edit: Alternate repeat loop:

	repeat with thisItem in selectedTracks
		tell thisItem to if its class is file track then
			set name to nameWithoutExtension of me for (location)
		end if
	end repeat

Hi Bruce,
Thanks for the quick reply! I ran the script but it seems to assume the files are already imported into iTunes. I want to perform the action on a set of files that have not yet been imported into iTunes. I’ve found that when I import them as is, the filenames are overwritten by the Title tags (which are incorrect). So, my thinking is that if I can use an AS that copies the filename to the Title tag field I’m all set.

Let me know if any of this isn’t clear.

Thanks again!
n

Ah, I see.

Try something like this:

choose file with prompt "Add these files to iTunes:" with multiple selections allowed
set theseItems to result

repeat with thisItem in theseItems
	set thisName to nameWithoutExtension for thisItem
	
	tell application "iTunes"
		add thisItem
		set name of result to thisName
	end tell
end repeat

on nameWithoutExtension for someAlias
	tell (info for someAlias) to return text 1 thru ((my (offset of ("." & name extension & ":") in (name & ":"))) - 1) of name
end nameWithoutExtension

Works brilliantly! Thanks so much Bruce!!

n