I've got a pop-up list of system fonts a user can chose from, but it looks awful without the font names actually displaying as their actual fonts, so I thought I'd try and list them as Attributed text fonts.
Any advice please on if it's possible, and if so, where I'm going wrong.
my fontButton's removeAllItems()
#
tell application "Font Book"
set theFonts to the name of font families
end tell
set hitTheFont to 0
tell windowMain to display()
set p to 2
repeat with x from 1 to (count of theFonts)
-- here we tell the menu to create the item and add it
set eachFont to item x of theFonts as text
try
set p to 3
if eachFont as text is my theFontInUseReference as text then set hitTheFont to (x - 1) as integer
set p to 4
-- here we tell the menu to create the item and add it
tell current application's NSFont to set myFont to fontWithName_size_(eachFont as text, 16.0 as number)
set p to 5
tell current application's NSDictionary to set thisAttributedFont to dictionaryWithObject_forKey_(myFont, current application's NSFontAttributeName)
set p to 6
current application's NSLog("myFont = %@", myFont)
set p to 7
current application's NSLog("attributedFont = %@", thisAttributedFont)
tell current application's NSAttributedString to set eachAttributedFontString to alloc()'s initWithString_attributes_(eachFont as text, thisAttributedFont)
current application's NSLog("eachAttributedFont = %@", eachAttributedFontString)
set p to 8
#
# This method does not add any titles
#
my fontButton's |menu|()'s addItemWithTitle_action_keyEquivalent_(setAttributedTitle_(eachAttributedFontString), "changeTheFont:", "")
#
# This method also does not add any titles
#
#my fontButton's |menu|()'s addItemWithTitle_action_keyEquivalent_(eachAttributedFontString, "changeTheFont:", "")
on error errmsg number errnum
#
# errnum = -10000 is an empty myFont
#
if errnum ≠ -10000 then my thereHasBeenAnError("setUpMainMessagesView menu set-up loop", errmsg, errnum, 0, p)
end try
end repeat
tell windowMain to display()
my fontButton's selectItemAtIndex_(hitTheFont as integer)
The log...
2014-10-02 14:45:12.398 ApplescriptObjC Wizard[26934:303] myFont = "Monotypecom 16.00 pt. P [] (0x13c8f2f60) fobj=0x13dd139d0, spc=9.60"
2014-10-02 14:45:12.398 ApplescriptObjC Wizard[26934:303] attributedFont = {
NSFont = "\"Monotypecom 16.00 pt. P [] (0x13c8f2f60) fobj=0x13dd139d0, spc=9.60\"";
}
2014-10-02 14:45:12.398 ApplescriptObjC Wizard[26934:303] eachAttributedFont = Monotype.com{ NSFont = "\"Monotypecom 16.00 pt. P [] (0x13c8f2f60) fobj=0x13dd139d0, spc=9.60\"";
}