tell application "Finder"
activate
set objResult to ¬
choose file default location (path to fonts folder from user domain) ¬
of type ¬
{"public.truetype-ttf-font", "public.truetype-collection-font", "public.opentype-font", "com.apple.truetype-datafork-suitcase-font", "com.adobe.postscript-lwfn-font"} invisibles true ¬
with multiple selections allowed without showing package contents
end tell
repeat with objFiles in objResult
tell application "Finder"
set theFileIAlias to objFiles as alias
set theFontName to (name of (info for objFiles) as list) as text
set theFileDir to (container of objFiles) as text
set theUnixFilePath to (POSIX path of theFileIAlias) as text
end tell
set theMdlsResult to do shell script "/usr/bin/mdls -name com_apple_ats_name_family \"" & theUnixFilePath & "\""
set AppleScript's text item delimiters to {"\r"}
set theResultList to (every text item of theMdlsResult) as list
set AppleScript's text item delimiters to {""}
set numListLine to (count of theResultList) as number
if numListLine is 3 then
set theLineData to (item 2 of theResultList) as text
set theResultText to my doReplace(theLineData, "\t", "") as text
set theResultText to my doReplace(theResultText, "\"", "") as text
set theResultText to my doReplace(theResultText, " ", "") as text
else if numListLine is 4 then
set theLineData to (item 3 of theResultList) as text
set theResultText to my doReplace(theLineData, "\t", "") as text
set theResultText to my doReplace(theResultText, "\"", "") as text
set theResultText to my doReplace(theResultText, " ", "") as text
else
end if
set theResultText to my doReplace(theResultText, "\\U", "\\u") as text
set thePregReplace to "php -r 'echo preg_replace(\"/\\\\\\u([0-9abcdef]{4})/\", \"&#x$1;\", \"" & theResultText & "\");'" as text
set theResultText to (do shell script thePregReplace) as text
set thePregReplace to "php -r 'echo preg_replace(\"/\\\\\\u([0-9abcdef]{2})/\", \"&#x$1;\", \"" & theResultText & "\");'" as text
set theResultText to (do shell script thePregReplace) as text
set theMbConvertEncoding to "php -r 'echo mb_convert_encoding(\"" & theResultText & "\", \"UTF-8\", \" HTML-ENTITIES \");'" as text
set theResultText to (do shell script theMbConvertEncoding) as text
tell application "Finder"
try
make new folder at (theFileDir) with properties ¬
{name:theResultText ¬
, owner privileges:read write ¬
, group privileges:read write ¬
, everyones privileges:read write ¬
, comment:theFontName ¬
, description:theFontName ¬
}
end try
end tell
tell application "Finder"
try
move (objFiles) to alias (theFileDir & theResultText & ":")
end try
end tell
tell application "Finder"
activate
open theFileDir
end tell
end repeat
to doReplace(theText, orgStr, newStr)
set oldDelim to AppleScript's text item delimiters
set AppleScript's text item delimiters to orgStr
set tmpList to every text item of theText
set AppleScript's text item delimiters to newStr
set tmpStr to tmpList as text
set AppleScript's text item delimiters to oldDelim
return tmpStr
end doReplace