• 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: Scripting alerts
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Scripting alerts


  • Subject: Re: Scripting alerts
  • From: Shane Stanley <email@hidden>
  • Date: Mon, 24 Nov 2014 21:20:15 +1100

So this email got lost. It takes up the story after popups and before the code to show the alert...

Radio buttons are created in groups known as matrixes. They take quite a bit more setting up in code. The handler here takes a list of button titles, the usual size values, and a boolean for whether they should run vertically  or horizontally. They can be configured to have both columns and rows, but that's a complication we will live without. So without further to-do, here's the code:

on makeMatrix:listOfNames leftInset:theLeft bottom:theBottom maxWidth:theWidth isVertical:isVertical
set theCount to count of listOfNames
if isVertical then
set rowCount to theCount
set colCount to 1
else
set colCount to theCount
set rowCount to 1
end if
set theDepth to rowCount * 18 + (rowCount - 1) * 2 -- 18 pts per button + 2 pts between
set theMatrix to current application's NSMatrix's alloc()'s initWithFrame:(current application's NSMakeRect(theLeft, theBottom, theWidth, theDepth)) mode:(current application's NSRadioModeMatrix) cellClass:(current application's NSButtonCell) numberOfRows:rowCount numberOfColumns:colCount
set theCells to theMatrix's cells() as list
repeat with i from 1 to count of theCells
((item i of theCells)'s setButtonType:(current application's NSRadioButton))
((item i of theCells)'s setTitle:(item i of listOfNames))
end repeat
theMatrix's setIntercellSpacing:(current application's NSMakeSize(8, 2))
theMatrix's setAutorecalculatesCellSize:true
theMatrix's sizeToCells()
set newSize to theMatrix's frame()'s |size|()
theMatrix's setFrameSize:{width of newSize, theDepth}
return {theMatrix, theBottom + theDepth, width of newSize}
end makeMatrix:leftInset:bottom:maxWidth:isVertical:

And because matrixes normally carry labels, this handler will build a labeled matrix, with the label to the left and aligned vertically with the first button. As with popups and checkboxes, you can also align on the first button by passing a value for matrixLeft that is greater than the leftInset value.

on makeLabeledMatrix:listOfNames leftInset:theLeft bottom:theBottom maxWidth:theWidth label:theLabel matrixLeft:matrixLeft isVertical:isVertical
if matrixLeft ≤ theLeft then
set {theLabel, theTop, newWidth} to my makeLabel:theLabel leftInset:theLeft bottom:(theBottom + 2) maxWidth:theWidth alignment:"left" multiLine:false
set matrixLeft to (newWidth + 6)
set {theMatrix, theTop, theWidth} to my makeMatrix:listOfNames leftInset:matrixLeft bottom:theBottom maxWidth:(theWidth - newWidth - 6) isVertical:isVertical
else
set {theLabel, theTop, newWidth} to my makeLabel:theLabel leftInset:theLeft bottom:(theBottom + 2) maxWidth:(matrixLeft - theLeft - 6) alignment:"right" multiLine:false
set {theMatrix, theTop, theWidth} to my makeMatrix:listOfNames leftInset:matrixLeft bottom:theBottom maxWidth:(theWidth - matrixLeft) isVertical:isVertical
end if
theLabel's setFrame:(current application's NSOffsetRect(theLabel's frame(), 0, theTop - theBottom - 18))
return {theMatrix, theLabel, theTop, matrixLeft}
end makeLabeledMatrix:leftInset:bottom:maxWidth:label:matrixLeft:isVertical:

And that's it for the controls.

-- 
Shane Stanley <email@hidden>
<www.macosxautomation.com/applescript/apps/>

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

References: 
 >Scripting alerts (From: Shane Stanley <email@hidden>)
 >Re: Scripting alerts (From: Shane Stanley <email@hidden>)
 >Re: Scripting alerts (From: Shane Stanley <email@hidden>)
 >Re: Scripting alerts (From: Shane Stanley <email@hidden>)
 >Re: Scripting alerts (From: Shane Stanley <email@hidden>)
 >Re: Scripting alerts (From: Shane Stanley <email@hidden>)
 >Re: Scripting alerts (From: Shane Stanley <email@hidden>)
 >Re: Scripting alerts (From: Shane Stanley <email@hidden>)
 >Re: Scripting alerts (From: Shane Stanley <email@hidden>)
 >Re: Scripting alerts (From: Shane Stanley <email@hidden>)
 >Re: Scripting alerts (From: Shane Stanley <email@hidden>)
 >Re: Scripting alerts (From: Shane Stanley <email@hidden>)

  • Prev by Date: Re: Scripting alerts
  • Next by Date: Re: Scripting alerts
  • Previous by thread: Re: Scripting alerts
  • Next by thread: Re: Scripting alerts
  • Index(es):
    • Date
    • Thread