Script snippet to get the "full name" of a font from the font file

In the Finder. when I do a Get Info on a font file, among the items listed is the “Full Name” of the font, right after the “modified” date. Yet that full name doesn’t appear in the array returned by Applescript’s “get info for”. Everything else appears to be there.

How do I extract the Full Name from a font file in Applescript? Any help :cool: will be appreciated!

Model: Early 2009 iMac
AppleScript: 2.2.2
Browser: Safari 536.25
Operating System: Mac OS X (10.8)

I think you will have to use :

do shell script "mdls " & filepatth

The name(s) you need will show after the com_apple_ats_name_full = ( line and end with \n).

Good tip. In Terminal, this works:

mdls -name com_apple_ats_name_full filePath [ when I drag & drop the file to the command line]

Now to work that into applescript. My experience level is neophyte or less.

Thanks.

Thanks for the expertise. The following seems to be working. The critical eye of an AS expert would be further appreciated!

set theSourceFolder to (choose folder with prompt “Select a folder whose font files you wish to rename:”)

tell application “Finder”
set filesArray to every file of theSourceFolder

repeat with theFile in filesArray
	
	set fileAlias to theFile as alias
	set fileExtension to name extension of fileAlias
	
	set filePOSIXPath to POSIX path of fileAlias
	set mdlsName to (do shell script "mdls -name com_apple_ats_name_full " & quoted form of filePOSIXPath)
	
	set oldDelims to AppleScript's text item delimiters
	set AppleScript's text item delimiters to {"\""}
	
	try
		set fullName to second text item of mdlsName
		set newName to fullName & fileExtension
		set name of theFile to newName
		
		display dialog "Full Name is: " & fullName
		display dialog "fileExtension is " & fileExtension
		
		set AppleScript's text item delimiters to oldDelims
		
	on error
		
		set AppleScript's text item delimiters to oldDelims
		
	end try
	
end repeat

end tell

display dialog “Done!”

Here’s something you can play with. Try using the Font Book application. It’s probably slower than your current solution but if your solution isn’t exact enough then this could work. The font book app knows a lot about fonts. For example if I run a script like the following I can see that a font has a “FBFaceLocation” property which is the path to the actual font file on the computer and a “FBFaceFullName” which is the name you are looking for.

tell application "Font Book"
	launch
	set theFonts to every typeface
	return (get properties of (item 1 of theFonts))
end tell

As such if you knew the path to a font file you could gets its full name like this…

set posixPath to "/Library/Fonts/Microsoft/Abadi MT Condensed Extra Bold"

tell application "Font Book"
	launch
	set theFont to first typeface whose typeface additional info contains posixPath
	set additionalnfo to typeface additional info of (get properties of theFont)
	set fontFullName to FBFaceFullName of additionalnfo
end tell

Be aware that when mdls returns ( \r … \r) it’s a return separated list.

Some files may contain more then one name.

I use something like this, generic, when some data is a list some not:

	set islist to false
repeat with k from 1 to count of paragraphs of rs
			set p to paragraph k of rs
			if islist then
				if text 1 of p is ")" then
					set islist to false
					set x to x & "}}"
					try
						set prs to prs & (run script x)
					end try
				else
					set x to x & p
				end if
			else
				set i to offset of "=" in p
				if i > 1 then
					set x to "{" & (text 1 thru (i - 1) of p) & ":"
					if text (i + 2) of p = "(" then
						set x to x & "{"
						set islist to true
					else
						set x to x & text (i + 2) thru -1 of p & "}"
						set prs to prs & (run script x)
					end if
				end if
				
			end if
		end repeat
		
		copy prs to end of info

Thanks for sharing your expertise, mouramartins and regulus6633, and for the valuable scriptlets! :D:D