ウィンドウを作成して、その上でプログレスバーと途中停止用のボタンを描画、プログレスバーのアニメーション表示を行わせるサンプルScriptです。
スクリプトエディタ上でControl-Command-Rの操作を行い、スクリプトをメインスレッドで実行する必要があります。
AppleScript名:プログレスバー+buttonを作成 |
— Created 2015-12-11 by Takaaki Naganoya — 2015 Piyomaru Software use AppleScript version "2.4" use scripting additions use framework "Foundation" use framework "AppKit" use framework "Carbon" — AEInteractWithUser() is in Carbon property windisp : false property aPBar : missing value if current application’s AEInteractWithUser(-1, missing value, missing value) is not equal to 0 then return set aMaxVal to 100 set aButtonMSG to "Abort" set aTitle to "現在進行中…" set aWin to makeProgressWindow(aMaxVal, aButtonMSG, aTitle) of me repeat with i from 1 to aMaxVal by 1 if (my windisp) = false then exit repeat end if (aPBar’s setDoubleValue:(i as real)) delay 0.01 end repeat if i is not equal to aMaxVal then tell current application display dialog "Aborted" buttons {"OK"} default button 1 end tell end if my closeWin:aWin set my aPBar to missing value set aWin to missing value on makeProgressWindow(aMaxVal, aButtonMSG, aTitle) set (my windisp) to true –set (my aSliderValMSG) to aSliderValMSG set aView to current application’s NSSplitView’s alloc()’s initWithFrame:(current application’s NSMakeRect(0, 0, 360, 40)) aView’s setVertical:false –ProgressIndicatorをつくる set aSlider to makeProgressIndicator(aMaxVal) of me –Buttonをつくる set bButton to (current application’s NSButton’s alloc()’s init()) bButton’s setTitle:aButtonMSG bButton’s setTarget:me bButton’s setAction:("clicked:") aView’s addSubview:aSlider aView’s addSubview:bButton aView’s setNeedsDisplay:true set aWin to (my makeDockLevelWinWithView(aView, 400, 80, aTitle)) return aWin end makeProgressWindow on clicked:aSender set (my windisp) to false end clicked: –make Window for Display on makeDockLevelWinWithView(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 setBackgroundColor:(current application’s NSColor’s whiteColor()) 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 NSDockWindowLevel) –プログレスバー表示用に変更 aWin’s setOpaque:false aWin’s setReleasedWhenClosed:true aWin’s |center|() aWin’s makeKeyAndOrderFront:(me) aWin’s setContentView:aView return aWin end makeDockLevelWinWithView –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: –make progress indicator on makeProgressIndicator(aMaxNum) set aPBar to current application’s NSProgressIndicator’s alloc()’s init() aPBar’s setMaxValue:aMaxNum aPBar’s setMinValue:1 aPBar’s setIndeterminate:false aPBar’s setControlSize:(current application’s NSProgressIndicatorPreferredLargeThickness) aPBar’s setDoubleValue:(1.0 as real) return aPBar end makeProgressIndicator |
More from my site
(Visited 355 times, 6 visits today)