I’m trying to populate an NSMenu with fonts and each NSMenuItem in the respective font. So far I have this, but it’s not working
property NSMenu : class "NSMenu"
property NSMenuItem : class "NSMenuItem"
property NSFontManager : class "NSFontManager"
property NSFont : class "NSFont"
property NSMutableAttributedString : class "NSMutableAttributedString"
property fontMenu : missing value
on applicationWillFinishLaunching_(notification)
set sharedManager to NSFontManager's sharedFontManager
set allFonts to sharedManager's availableFontFamilies
fontMenu's removeAllItems()
repeat with a in allFonts
set menuItem to (my NSMenuItem's alloc)'s init
menuItem's setTitle_(a as string)
menuItem's setTarget_(me)
menuItem's setAction_("setFont:")
set attributed to (my NSMutableAttributedString's alloc)'s initWithString_(a as string)
attributed's addAttribute_(NSFont's fontWithName_(a as string)'s size_(14))
menuItem's setAttributedTitle_(attributed)
menuItem's setEnabled_(true)
fontMenu's addItem_(menuItem)
attributed's release()
menuItem's release()
end repeat
end applicationWillFinishLaunching_