アラートダイアログを作成し、その上にRadio Buttonを表示して位置座標の選択を行うAppleScriptです。
任意の選択肢をlist(配列)で指定すると、その通りのRadio Buttonを表示します。ユーザーが選択した項目のtitle文字列を返します。項目番号ではありません。
AppleScript名:アラートダイアログ上にRadio Buttonを表示 v2 |
— Created 2019-02-14 by Takaaki Naganoya — 2019 Piyomaru Software use AppleScript version "2.5" use scripting additions use framework "Foundation" use framework "AppKit" property NSAlert : a reference to current application’s NSAlert property NSMatrix : a reference to current application’s NSMatrix property NSButtonCell : a reference to current application’s NSButtonCell property NSRadioButton : a reference to current application’s NSRadioButton property NSRadioModeMatrix : a reference to current application’s NSRadioModeMatrix property NSAlertSecondButtonReturn : a reference to current application’s NSAlertSecondButtonReturn property theResult : 0 property returnCode : 0 set paramObj to {myMessage:"項目の選択", mySubMessage:"適切なものを以下からえらんでください", matrixTitleList:{"なし", "りんご", "ひよこ", "ぎょうざ", "すなぎも", "ぼんじり", "もも"}} set aRes to my chooseItemByRadioButton:paramObj on chooseItemByRadioButton:paramObj set aMainMes to myMessage of paramObj set aSubMes to mySubMessage of paramObj set aMatList to (matrixTitleList of paramObj) as list set aLen to length of aMatList –create the radio button prototype set aProto to NSButtonCell’s alloc()’s init() aProto’s setTitle:"Options" aProto’s setButtonType:(NSRadioButton) –define the matrix size where you’ll put the radio buttons set matrixRect to current application’s NSMakeRect(20.0, 20.0, 200.0, (20.0 * aLen)) set aMatrix to NSMatrix’s alloc()’s initWithFrame:matrixRect mode:(NSRadioModeMatrix) prototype:aProto numberOfRows:(aLen) numberOfColumns:1 set cellList to aMatrix’s cells() set aCount to 0 repeat with i in aMatList set j to contents of i ((cellList’s objectAtIndex:aCount)’s setTitle:j) set aCount to aCount + 1 end repeat — set up alert set theAlert to NSAlert’s alloc()’s init() tell theAlert its setMessageText:aMainMes its setInformativeText:aSubMes its addButtonWithTitle:"OK" its addButtonWithTitle:"Cancel" its setAccessoryView:aMatrix end tell — show alert in modal loop current application’s NSRunningApplication’s currentApplication()’s activateWithOptions:0 my performSelectorOnMainThread:"doModal:" withObject:(theAlert) waitUntilDone:true if (my returnCode as number) = 1001 then error number -128 return (aMatrix’s selectedCell()’s title()) as string end chooseItemByRadioButton: on doModal:aParam set (my returnCode) to aParam’s runModal() end doModal: |
More from my site
(Visited 291 times, 1 visits today)