Button Title [Font] Size

Hi all :slight_smile:

Here my small problem of the day.

I have a button of which I would like to change, dynamically by the code, the size of the text of its title, but didn’t I find how to make that.

I tested this, but without success:


set size of title of button "btnTst" of window of theObject to 8

Somebody would have an idea?

Thanks :slight_smile:

Both the size and bounds properties provide a programmatic interface for manipulating the size of controls. Check out the bounds and size properties of the Studio interface for NSView:

NSView via AppleScript

Thank-you for reply :slight_smile:

Ok, I looked at that, Mikey-San, but the “bounds” and “size” properties of class “view” can change the dimensions of the object, but not his contents, and I want to change the font size of label of a button, in my case…

Thereafter I sought solutions in the properties of the class “control”, but I did not find anything directly accessible by AppleScript, then I looked at if there were something to make with the Cocoa methods, and I believe to have found a track interesting, in any case that functions rather well:


call method "setFont:" of (button "btnTst" of window of theObject) with parameter ¬
	(call method "labelFontOfSize:" of class "NSFont" with parameter "labelFontSize")

This code makes it possible to change the size of text font of the title of a button according to preset parameters, but it does not authorize to choose a personalized size of text. The parameters to choose are:

  • “systemFontSize” = size of the standard System font
  • “smallSystemFontSize” = size of standard small System font
  • “labelFontSize” = size of the standard Label Font

For the moment this solution is enough for my project, but if somebody found solution to choose a specific size of text, that obviously interests me.

Thanks :slight_smile: