AppleScript名:複数入力フィールドつきダイアログを表示 |
— Created 2017-09-23 by Takaaki Naganoya — 2017 Piyomaru Software use AppleScript version "2.4" use scripting additions use framework "Foundation" use framework "AppKit" property windisp : false property wController : false set fieldList to {"field 1", "field 2", "field 3", "field 4", "field 5", "field 6", "field 7", "field 8", "field 9", "field 10"} –set fieldList to {"field 1", "field 2"} set aButtonMSG to "OK" set aWinTitle to "Multiple Text Field Input" set aVal to getMultiTextFieldValues(fieldList, aWinTitle, aButtonMSG, 180) of me on getMultiTextFieldValues(fieldList, aWinTitle, aButtonMSG, timeOutSecs) set (my windisp) to false set fLen to (length of fieldList) + 1 set aView to current application’s NSView’s alloc()’s initWithFrame:(current application’s NSMakeRect(0, 0, 360, (20 * fLen))) set a1y to (30 * fLen) set tList to {} repeat with i in fieldList set a1TF to (current application’s NSTextField’s alloc()’s initWithFrame:(current application’s NSMakeRect(60, a1y, 80, 20))) (a1TF’s setEditable:false) (a1TF’s setStringValue:(i as string)) (a1TF’s setDrawsBackground:false) (a1TF’s setBordered:false) set a2TF to (current application’s NSTextField’s alloc()’s initWithFrame:(current application’s NSMakeRect(140, a1y, 200, 20))) (a2TF’s setEditable:true) (a2TF’s setDrawsBackground:true) (a2TF’s setBordered:true) (aView’s addSubview:a1TF) (aView’s addSubview:a2TF) set the end of tList to a2TF set a1y to a1y – 30 end repeat –Buttonをつくる set bButton to (current application’s NSButton’s alloc()’s initWithFrame:(current application’s NSMakeRect(110, 10, 180, 40))) bButton’s setButtonType:(current application’s NSMomentaryLightButton) bButton’s setBezelStyle:(current application’s NSRoundedBezelStyle) bButton’s setTitle:aButtonMSG bButton’s setTarget:me bButton’s setAction:("clicked:") bButton’s setKeyEquivalent:(return) aView’s addSubview:bButton aView’s setNeedsDisplay:true –NSWindowControllerを作ってみた set aWin to (my makeWinWithView(aView, 400, ((fLen + 1) * 30), aWinTitle)) set wController to current application’s NSWindowController’s alloc() wController’s initWithWindow:aWin set (my windisp) to true wController’s showWindow:me set aCount to timeOutSecs * 10 set hitF to false repeat aCount times if (my windisp) = false then set hitF to true exit repeat end if delay 0.1 set aCount to aCount – 1 end repeat my closeWin:aWin if hitF = true then set aResList to {} repeat with i in tList set the end of aResList to (i’s stringValue()) as string end repeat else return false end if return aResList end getMultiTextFieldValues on clicked:aSender set (my windisp) to false end clicked: –make Window for Display on makeWinWithView(aView, aWinWidth, aWinHeight, aTitle) set aScreen to current application’s NSScreen’s mainScreen() set aFrame to {{0, 0}, {aWinWidth, aWinHeight}} set aBacking to current application’s NSTitledWindowMask set aDefer to current application’s NSBackingStoreBuffered — Window set aWin to current application’s NSWindow’s alloc() (aWin’s initWithContentRect:aFrame styleMask:aBacking backing:aDefer defer:false screen:aScreen) aWin’s setTitle:aTitle aWin’s setDelegate:me aWin’s setDisplaysWhenScreenProfileChanges:true aWin’s setHasShadow:true aWin’s setIgnoresMouseEvents:false aWin’s setLevel:(current application’s NSNormalWindowLevel) aWin’s setOpaque:false aWin’s setReleasedWhenClosed:true aWin’s |center|() aWin’s setContentView:aView return aWin end makeWinWithView –close win on closeWin:aWindow repeat with n from 10 to 1 by -1 (aWindow’s setAlphaValue:n / 10) delay 0.02 end repeat aWindow’s |close|() end closeWin: |
More from my site
(Visited 1,114 times, 1 visits today)