I want to document the informations, Font Book knows about the available fonts. But the information window (⌘4) excludes the font representations.
Using the AppleScript Editor I got an interesting list, but . difficult to parse due to its inhomogeneous (font dependant) records.
Perhaps you will have a look yourself:
set PropList to {""}
tell application "Font Book"
launch
set MyCount to count typefaces
repeat with ii from 1 to MyCount
set PropRec to typeface additional info of typeface ii
set PropList to PropList & return & {PropRec}
end repeat
end tell
PropList
For the present I helped myself by copying the result to TextEdit window, “parsing” midst Del- & Return.
Do you know a method,
¢ either to parse this result by AppleScript itself ?
¢ or to make AppleScript write this result to a text file ?
In this context: has anybody discovered, if & how to write Applescript Editor’s Log/Result field to a text file ?. The dictionary didn’t help me.
Thank you in advance .
Peter
Model: iMac 24 | OS X 10.6.7
AppleScript: 2.1.2
Browser: Firefox 4.0.1
Operating System: Mac OS X (10.6)
Since you’re mostly talking about scripting Font Book, your subject line for this thread is very misleading.
The script below saves ‘typeface additional info’ details to a text file on the desktop. It works on my machine, but you may need to adjust it if any of your fonts have other properties besides the ones mine have, or if they’re missing any of the basic thirteen properties which all of mine have. You can make the adjustment by adding properties, with ‘missing value’ values, to the record concatentated to PropRec at the top of the makeTextEntry() handler.
main()
on main()
set entryList to {}
tell application "Font Book"
launch
set MyCount to count typefaces
repeat with ii from 1 to MyCount
set PropRec to (typeface additional info of typeface ii)
set end of entryList to my makeTextEntry(PropRec)
end repeat
end tell
set astid to AppleScript's text item delimiters
set AppleScript's text item delimiters to return & return
set fullText to entryList as text
set AppleScript's text item delimiters to astid
set fRef to (open for access file ((path to desktop as text) & "Installed font details.txt") with write permission)
try
set eof fRef to 0
write «data rdatEFBBBF» to fRef -- UTF-8 BOM
write fullText as «class utf8» to fRef
end try
close access fRef
end main
-- Turn each PropRec record into a font entry for the final text.
on makeTextEntry(PropRec)
-- Make sure each record contains the 19 known possibilities. On my machine, all records contain at least 13 of them as a basic set.
set PropRec to PropRec & {FBFaceManufacturerName:missing value, FBFaceDesignerName:missing value, FBFaceLicenseName:missing value, FBFaceDescriptionName:missing value, FBFaceTrademarkName:missing value, FBFaceLanguages:missing value}
-- Construct the text for this font entry.
set entry to {}
set end of entry to "FBFaceFullName: " & check(PropRec's FBFaceFullName)
set end of entry to "FBFaceManufacturerName: " & check(PropRec's FBFaceManufacturerName)
set end of entry to "FBFaceDesignerName: " & check(PropRec's FBFaceDesignerName)
set end of entry to "FBFaceLicenseName: " & check(PropRec's FBFaceLicenseName)
set end of entry to "FBFaceSubFamilyName: " & check(PropRec's FBFaceSubFamilyName)
set end of entry to "FBFacePostScriptName: " & check(PropRec's FBFacePostScriptName)
set end of entry to "FBFaceIsDuplicate: " & check(PropRec's FBFaceIsDuplicate)
set end of entry to "FBFaceLocation: " & check(PropRec's FBFaceLocation)
set end of entry to "FBFaceCopyProtection: " & check(PropRec's FBFaceCopyProtection)
set end of entry to "FBFaceKind: " & check(PropRec's FBFaceKind)
set end of entry to "FBFaceIsEnabled: " & check(PropRec's FBFaceIsEnabled)
set end of entry to "FBFaceCopyrightName: " & check(PropRec's FBFaceCopyrightName)
set end of entry to "FBFaceUniqueName: " & check(PropRec's FBFaceUniqueName)
set end of entry to "FBFaceFamilyName: " & check(PropRec's FBFaceFamilyName)
set end of entry to "FBFaceDescriptionName: " & check(PropRec's FBFaceDescriptionName)
set end of entry to "FBFaceEmbedding: " & check(PropRec's FBFaceEmbedding)
set end of entry to "FBFaceVersionName: " & check(PropRec's FBFaceVersionName)
set end of entry to "FBFaceTrademarkName: " & check(PropRec's FBFaceTrademarkName)
set end of entry to "FBFaceLanguages: " & check(PropRec's FBFaceLanguages)
set astid to AppleScript's text item delimiters
set AppleScript's text item delimiters to return
set entry to entry as text
set AppleScript's text item delimiters to astid
return entry
end makeTextEntry
-- Turn non-text values into suitable text.
on check(val)
if (val is missing value) then
set val to "(unspecified)"
else if (val's class is boolean) then
set val to word ((val as integer) + 1) of "false true"
else if (val's class is list) then
set astid to AppleScript's text item delimiters
set AppleScript's text item delimiters to ", "
set val to val as text
set AppleScript's text item delimiters to astid
end if
return val
end check
many, many thanks for your elaborated script reply in such a short time. You have solved my problem excellently.
Your script worked immediately successful, after I had added “FBFaceCopyrightName:missing value” to the initial line of the ‘makeTextEnty(PropRec)’ handler.
While I was relatively content with my mini-script - I could somehow utilize the interesting font infos - I failed completely exporting the AppleScript Editor’s log/result field to file, except by copy & paste. The secondary task got in the foreground and into my subject line. And I am still curious, wether there is a solution .
It turns out to be better to save the text as UTF-8 Unicode, as there are some fonts with non-Latin-script names. I’ve changed it in my post above and have used the idea below.
It doesn’t appear to be possible to use AppleScript Editor’s scripting implementation for this, but it’s possible to use GUI Scripting without resorting to copy-and-paste. However, as always with GUI Scripting, it’s not possible to guarantee it’ll work after the next application update:
tell application "System Events"
tell application process "AppleScript Editor"
-- Assuming Peter's Font Book script's been run and the result's showing in another window's Event Log/Result pane:
tell window 2 -- or window "<name of script>.scpt"
set fullText to value of text area 1 of scroll area 1 of group 1 of group 1 of splitter group 1
end tell
end tell
end tell
set fRef to (open for access file ((path to desktop as text) & "Installed font details.txt") with write permission)
try
set eof fRef to 0
write «data rdatEFBBBF» to fRef -- UTF-8 BOM
write fullText as «class utf8» to fRef
end try
close access fRef