I was already using a counter to track which font matched a variable, so I used the same variable.
my fontButton's removeAllItems()
#
tell application "Font Book"
set theFonts to the name of font families as list
end tell
set hitTheFont to 0
tell windowMain to display()
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
if eachFont as text is my theFontInUseReference as text then set hitTheFont to (x - 2) as integer
tell current application's NSFont to set myFont to fontWithName_size_(eachFont as text, 16.0 as number)
tell current application's NSDictionary to set thisAttributedFont to dictionaryWithObject_forKey_(myFont, current application's NSFontAttributeName)
current application's NSLog("myFont = %@", myFont)
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("eachAttributedFontString = %@", eachAttributedFontString)
#
# This attempted method does absolutely nothing
#my fontButton's |menu|()'s setAttributedTitle_(eachAttributedFontString as text)
#
my fontButton's |menu|()'s addItemWithTitle_action_keyEquivalent_("", "changeTheFont:", "")
my fontButton's |menu|()'s itemAtIndex_((x - 2) as integer)'s setAttributedTitle_(eachAttributedFontString)
#
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()
On 02/10/2014, at 10:29 PM, Shane Stanley <
email@hidden> wrote:
On 2 Oct 2014, at 10:12 pm, Brian Christmas <
email@hidden> wrote:
Shane, in answer to your question 'perhaps a prayer' you're correct, mainly because I still don't know what I'm doing with translating the vagaries of Apple's documentation to ASOC, and I'm still bloody praying, cause your esoteric answer went nowhere in me resolving my coding inabilities. And it's not enough of a clue as well.
Well the code you're posting now suggests you can see the problem with what you posted, and what I was alluding to. Now you have:
my fontButton's |menu|()'s addItemWithTitle_action_keyEquivalent_("", "changeTheFont:", "")
#
# I'd already tried this, but it doesn't work.
#
my fontButton's |menu|()'s last item's setAttributedTitle_(eachAttributedFontString as text)
So you're calling the method on *something*, and you know it should be a menu item. But "last item" is hardly going to work, because that's for AppleScript lists, not NSMenus. So the question becomes: what method of NSMenu will return you its last menu item? And there isn't one, directly, but there are several that return menu items. Your choice becomes: (a) use itemAtIndex: and keep count so you know the index, (b) use itemAtIndex: and call numberOfItems every time, which is probably going to slow things down, or (c) do something creative like make your menu item with a placeholder title, and use itemWithTitle:. The latter will work, because you're going to effectively overwrite the title each time.
An alternative is to create the menu item first, using alloc and initWithTitle:action:keyEquivalent:, set its attributed title, and add it to the menu using NSMenu's addItem: method.
Do not post admin requests to the list. They will be ignored.
applescriptobjc-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden