アラートダイアログ上にラジオボタン的なUIを表示して選択するAppleScriptです。
–> Downdload calImageDialog (with Library within its bundle)
本当はRadio Button的なものを作りたかったのですが、NSMatrixがmacOS 10.8で非推奨というか事実上の廃止になったことを受けて、Radio Button的なものを作ってみたのですが、割と中途半端です(見た目はスゲーいいのに)。
▲macOS 10.14+Script Editor上の動き
▲macOS 10.14+Script Debugger上の動き
一応、ボタンの画像に1月分のカレンダー画像を割り当てており、機能と見た目のバランスを取ろうとしたのですが、Radio Buttonっぽい動きにはなっていません(残念!)。
あと、1年分のカレンダー画像を作成するのに不思議なぐらい時間がかかっています。
あんな素朴なcalコマンドにmacOS 10.13から当日のハイライト表示を消すための「-h」オプションが追加されていたとは、気づきませんでした。10.14で作って10.12上で動かなかったのでcalコマンドのオプションを条件分岐で変更するように初版から修正しました。
AppleScript名:アラートダイアログ上にRadio Buttonを表示 v3 |
— Created 2019-08-07 by Takaaki Naganoya — 2019 Piyomaru Software use AppleScript version "2.5" use scripting additions use framework "Foundation" use framework "AppKit" use calImage : script "calImageKit" property NSView : a reference to current application’s NSView property NSAlert : a reference to current application’s NSAlert property NSMatrix : a reference to current application’s NSMatrix property NSButton : a reference to current application’s NSButton 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 NSRoundedBezelStyle : a reference to current application’s NSRoundedBezelStyle property NSRunningApplication : a reference to current application’s NSRunningApplication property NSAlertSecondButtonReturn : a reference to current application’s NSAlertSecondButtonReturn property theResult : 0 property returnCode : 0 set paramObj to {myMessage:"Select target month", mySubMessage:"適切なものを以下からえらんでください", matrixTitleList:{"1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12"}} –my chooseItemByRadioButton:paramObj–for Debugging my performSelectorOnMainThread:"chooseItemByRadioButton:" withObject:paramObj waitUntilDone:true return theResult 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 set aButtonCellWidth to 104 set aButtonCellHeight to 104 set colNum to 4 set rowNum to 3 set targYear to 2019 set viewWidth to aButtonCellWidth * colNum set viewHeight to aButtonCellHeight * rowNum –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(0.0, 0.0, viewWidth, viewHeight) set aView to NSView’s alloc()’s initWithFrame:(matrixRect) set aCount to 1 set tmpArray to current application’s NSMutableArray’s new() repeat with y from 1 to rowNum repeat with x from 1 to colNum set j to contents of item aCount of aMatList set tmpB to (NSButton’s alloc()’s initWithFrame:(current application’s NSMakeRect(((x – 1) * aButtonCellWidth), ((aLen – aCount) div colNum) * aButtonCellHeight, aButtonCellWidth, aButtonCellHeight))) –(tmpB’s setTitle:j) set tmpImage to makeSmallCalendarImage(targYear, aCount) of calImage (tmpB’s setImage:(tmpImage)) (tmpB’s setShowsBorderOnlyWhileMouseInside:true) (tmpB’s setTag:(aCount)) (tmpB’s setTarget:me) (tmpB’s setAction:("clicked:")) (tmpB’s setButtonType:(current application’s NSButtonTypeMomentaryPushIn)) (tmpArray’s addObject:tmpB) set aCount to aCount + 1 end repeat end repeat (aView’s setSubviews:tmpArray) — 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:aView end tell — show alert in modal loop NSRunningApplication’s currentApplication()’s activateWithOptions:0 my performSelectorOnMainThread:"doModal:" withObject:(theAlert) waitUntilDone:true if (my returnCode as number) = 1001 then error number -128 end chooseItemByRadioButton: on doModal:aParam set (my returnCode) to aParam’s runModal() end doModal: on clicked:aParam set aTag to tag of aParam set theResult to aTag end clicked: |
More from my site
(Visited 88 times, 1 visits today)