• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Trying to set pop-up button list of fonts to attributed font names
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Trying to set pop-up button list of fonts to attributed font names


  • Subject: Re: Trying to set pop-up button list of fonts to attributed font names
  • From: Brian Christmas <email@hidden>
  • Date: Thu, 02 Oct 2014 22:12:00 +1000

G'day Scripters

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.

Because I'm not sure how to use 'setAttributedTitle', I cannot check if the previous three lines of code are correct, so I'm in a bind. But, if you like to play mind games with me, then I'll have to ask other members of this group if my code is correct, and hope for a concrete answer, 'cause there's nothin' on the net about this (at least not understandable to me).



So, if there's anyone out there who knows how to set up a string with a set font, and use that string in setting the 'setAttributedTitle' of a pop-up button, then I'd appreciate your looking over my code, and advising me where I'm going wrong. 

I'm also presuming two things…

•  That I still need to use 'addItemWithTitle', because 'setAttributedTitle' does not seem to add a new item as far as I can tell.

•  That 'setAttributedTitle' is used to alter the state of an existing menu item.


Regards

Santa

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
  if eachFont as text is my theFontInUseReference as text then set hitTheFont to (x - 2) as integer
#
# Are  the three non-logging lines of code that follow correct?
#
#
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, except add a single empty line,
# which makes me think there might be something wrong with my first three lines 
# of code, but I'm not <sure>.
#
# my fontButton's |menu|()'s setAttributedTitle_(eachAttributedFontString as text)
#
  # Are  the two lines of code that follow correct?
#
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)
#
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


 The log…

2014-10-02 21:11:52.350 ApplescriptObjC Wizard[29004:303] myFont = "Monotypecom 16.00 pt. P [] (0x13e5645f0) fobj=0x13d8b98e0, spc=9.60"
2014-10-02 21:11:52.351 ApplescriptObjC Wizard[29004:303] attributedFont = {
    NSFont = "\"Monotypecom 16.00 pt. P [] (0x13e5645f0) fobj=0x13d8b98e0, spc=9.60\"";
}
2014-10-02 21:11:52.351 ApplescriptObjC Wizard[29004:303] eachAttributedFontString = Monotype.com{
    NSFont = "\"Monotypecom 16.00 pt. P [] (0x13e5645f0) fobj=0x13d8b98e0, spc=9.60\"";
}


On 02/10/2014, at 7:44 PM, Shane Stanley <email@hidden> wrote:

I mis-typed -- it's setAttributedTitle:.

My point was simply that you've done the research and found the method, but haven't used it.

But now that I look at your code again, you *have* tried to use it -- it just wasn't where I'd expect to see it. So this gets back to my list of points:

Are you calling methods on the right things?

Here's your code:

my fontButton's |menu|()'s addItemWithTitle_action_keyEquivalent_(setAttributedTitle_(eachAttributedFontString), "changeTheFont:", "")

And we know it's -setAttributedTitle:, so therefore it's an instance method, and we know from the documentation it's an NSMenuItem method. So what are you calling it on? Your code shows that you're not calling it on anything it all, except perhaps a prayer.

Is that enough of a clue?


 _______________________________________________
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

  • Follow-Ups:
    • Re: Trying to set pop-up button list of fonts to attributed font names
      • From: Shane Stanley <email@hidden>
References: 
 >Trying to set pop-up button list of fonts to attributed font names (From: Brian Christmas <email@hidden>)
 >Re: Trying to set pop-up button list of fonts to attributed font names (From: Shane Stanley <email@hidden>)
 >Re: Trying to set pop-up button list of fonts to attributed font names (From: Brian Christmas <email@hidden>)
 >Re: Trying to set pop-up button list of fonts to attributed font names (From: Shane Stanley <email@hidden>)

  • Prev by Date: Re: Trying to set pop-up button list of fonts to attributed font names
  • Next by Date: Re: Trying to set pop-up button list of fonts to attributed font names
  • Previous by thread: Re: Trying to set pop-up button list of fonts to attributed font names
  • Next by thread: Re: Trying to set pop-up button list of fonts to attributed font names
  • Index(es):
    • Date
    • Thread