• 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:14:26 +1100

Next is popups, which were used earlier in this thread. Creating them is very simple:

-- entryList is a list of names for the menu items
on makePopup:entryList leftInset:theLeft bottom:theBottom theWidth:theWidth
set thePopup to current application's NSPopUpButton's alloc()'s initWithFrame:(current application's NSMakeRect(theLeft, theBottom, theWidth, 26)) pullsDown:false
thePopup's addItemsWithTitles:entryList
return {thePopup, theBottom + 26}
end makePopup:leftInset:bottom:theWidth:

And again, popups generally have labels, so here's a handler that builds one with a label. The approach is the similar to that used with checkboxes earlier, except this time you pass a width for the popup:

on makeLabeledPopup:entryList leftInset:theLeft bottom:theBottom maxWidth:theWidth popupWidth:popupWidth label:theLabel popupLeft:popupLeft
if popupLeft ≤ theLeft then
set {theLabel, theTop, newWidth} to my makeLabel:theLabel leftInset:theLeft bottom:(theBottom + 6) maxWidth:theWidth alignment:"left" multiLine:false
set popupLeft to (newWidth + 6)
set {thePopup, theTop} to my makePopup:entryList leftInset:popupLeft bottom:theBottom theWidth:popupWidth
else
set {theLabel, theTop, newWidth} to my makeLabel:theLabel leftInset:theLeft bottom:(theBottom + 6) maxWidth:(popupLeft - theLeft - 6) alignment:"right" multiLine:false
set {thePopup, theTop} to my makePopup:entryList leftInset:popupLeft bottom:theBottom theWidth:popupWidth
end if
return {thePopup, theLabel, theTop, popupLeft}
end makeLabeledPopup:leftInset:bottom:maxWidth:popupWidth:label:popupLeft:

The last control is the path control. This isn't used much, but it's a good alternative to choose file/folder. The popup form can show a choose file/folder dialog, and both forms support drag and drop. Setting it up is simple, and it has different depth depending on the style. You pass the initial path as a POSIX path.

-- popsUp is true for a popup path control, false for a standard path control
on makePathControlFor:thePath leftInset:theLeft bottom:theBottom theWidth:theWidth popsUp:popsUpBool
set anNSURL to current application's class "NSURL"'s fileURLWithPath:thePath
if popsUpBool then
set thePathControl to current application's NSPathControl's alloc()'s initWithFrame:(current application's NSMakeRect(theLeft, theBottom, theWidth, 26))
thePathControl's setPathStyle:(current application's NSPathStylePopUp)
set theTop to theBottom + 26
else
set thePathControl to current application's NSPathControl's alloc()'s initWithFrame:(current application's NSMakeRect(theLeft, theBottom, theWidth, 22))
thePathControl's setPathStyle:(current application's NSPathStyleStandard)
set theTop to theBottom + 22
end if
thePathControl's setURL:anNSURL
return {thePathControl, theTop}
end makePathControlFor:leftInset:bottom:theWidth:popsUp:

A path control is also likely to have a label, but it's more likely to be above it than by its side, because path controls generally need to be wide, at least in the standard style. So:

on makeTopLabeledPathControlFor:thePath leftInset:theLeft bottom:theBottom theWidth:theWidth popsUp:popsUpBool label:theLabel
set {thePathControl, theTop} to my makePathControlFor:thePath leftInset:theLeft bottom:theBottom theWidth:theWidth popsUp:popsUpBool
set {theLabel, theTop, newWidth} to my makeLabel:theLabel leftInset:theLeft bottom:(theTop + 4) maxWidth:theWidth alignment:"left" multiLine:false
return {thePathControl, theLabel, theTop}
end makeTopLabeledPathControlFor:leftInset:bottom:theWidth:popsUp:label:

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