• 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 17:11:40 +1100

Now for checkboxes. I covered these in the "Choosing files" thread, but this time some fitting is needed, plus the ability to set the initial state. So:

on makeCheckbox:checkTitle leftInset:theLeft bottom:theBottom maxWidth:theWidth initialState:initialState
set theCheckbox to current application's NSButton's alloc()'s initWithFrame:(current application's NSMakeRect(theLeft, theBottom, theWidth, 18))
tell theCheckbox
its setButtonType:(current application's NSSwitchButton)
its setTitle:checkTitle
its setState:initialState
set theSize to its fittingSize()
its setFrameSize:theSize
end tell
-- return theCheckbox, the top of theCheckbox, and its width
return {theCheckbox, theBottom + 18, width of theSize}
end makeCheckbox:leftInset:bottom:maxWidth:initialState:

Sometimes checkboxes also require labels, so it makes sense to have a handler that builds both together. This is similar to the way I handled a text field with a label to its left: there is a checkboxLeft parameter, and if this is less than the leftInset, the label is made to size, and the checkbox positioned after it, otherwise the checkbox is positioned according to checkboxLeft, and the label positioned next to it. To make the first case work, the actual width of the label needs to be known, which is why the handler above returns it. So:

on makeLabeledCheckbox:checkTitle leftInset:theLeft bottom:theBottom maxWidth:theWidth label:theLabel checkboxLeft:checkboxLeft checkState:checkState
if checkboxLeft ≤ theLeft then
set {theLabel, theTop, newWidth} to my makeLabel:theLabel leftInset:theLeft bottom:(theBottom + 2) maxWidth:theWidth alignment:"left" multiLine:false
set checkboxLeft to (newWidth + 6)
set {theCheckbox, theTop, theWidth} to my makeCheckbox:checkTitle leftInset:checkboxLeft bottom:theBottom maxWidth:(theWidth - newWidth - 6) checkState:checkState
else
set {theLabel, theTop, newWidth} to my makeLabel:theLabel leftInset:theLeft bottom:(theBottom + 2) maxWidth:(checkboxLeft - theLeft - 6) alignment:"right" multiLine:false
set {theCheckbox, theTop, theWidth} to my makeCheckbox:checkTitle leftInset:checkboxLeft bottom:theBottom maxWidth:(theWidth - checkboxLeft) checkState:checkState
end if
return {theCheckbox, theLabel, theTop, checkboxLeft}
end makeLabeledCheckbox:leftInset:bottom:maxWidth:label:checkboxLeft:checkState:

-- 
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

  • Follow-Ups:
    • Re: Scripting alerts
      • From: Shane Stanley <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>)

  • 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