アラートダイアログを作成し、その上にpath controlを2つ表示してパスの選択を行うAppleScriptです。
path controlには、対象のフォルダ/ファイルをドラッグ&ドロップしてファイルのパスを指定できます。使いやすい一方で、choose folderコマンドのようにフォルダの新規作成までサポートしているわけではありません。
スクリプトエディタ、Script Debugger、Appletなどでは正常に動作しますが、スクリプトメニュー上から呼び出すとアラートダイアログが最前面に表示されず、前に出す操作が必要になります。
AppleScript名:アラートダイアログ上のpath control x2を表示 |
— 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 theResult : 0 property returnCode : 0 set paramObj to {myMessage:"項目選択", mySubMessage:"どれか選択してください。", fromPathMes:"移動元:", toPathMes:"移動先:"} set segRes to my chooseTwoPath:paramObj –> {fromPathRes:"/Users/me/Documents/AppleScript/パスコントロール", toPathRes:"/Users/me/Documents/AppleScript/タッチバー"} on chooseTwoPath:paramObj set aMainMes to myMessage of paramObj set aSubMes to mySubMessage of paramObj set fromLabel to fromPathMes of paramObj set toLabel to toPathMes of paramObj — create a view set theView to current application’s NSView’s alloc()’s initWithFrame:(current application’s NSMakeRect(0, 0, 800, 60)) — create two path control & text field set aPathControl to current application’s NSPathControl’s alloc()’s initWithFrame:(current application’s NSMakeRect(100, 35, 700, 20)) set bPathControl to current application’s NSPathControl’s alloc()’s initWithFrame:(current application’s NSMakeRect(100, 0, 700, 20)) aPathControl’s setBackgroundColor:(current application’s NSColor’s cyanColor()) bPathControl’s setBackgroundColor:(current application’s NSColor’s yellowColor()) set aHome to current application’s |NSURL|’s fileURLWithPath:(current application’s NSHomeDirectory()) –initial dir aPathControl’s setURL:aHome bPathControl’s setURL:aHome set a1TF to current application’s NSTextField’s alloc()’s initWithFrame:(current application’s NSMakeRect(0, 35, 100, 20)) set a2TF to current application’s NSTextField’s alloc()’s initWithFrame:(current application’s NSMakeRect(0, 0, 100, 20)) a1TF’s setEditable:false a2TF’s setEditable:false a1TF’s setStringValue:fromLabel a2TF’s setStringValue:toLabel a1TF’s setDrawsBackground:false a2TF’s setDrawsBackground:false a1TF’s setBordered:false a2TF’s setBordered:false theView’s setSubviews:{a1TF, aPathControl, a2TF, bPathControl} — set up alert set theAlert to current application’s NSAlert’s alloc()’s init() tell theAlert its setMessageText:aMainMes its setInformativeText:aSubMes its addButtonWithTitle:"OK" its addButtonWithTitle:"Cancel" its setAccessoryView:theView 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 set s1Val to (aPathControl’s |URL|’s |path|()) as string set s2Val to (bPathControl’s |URL|’s |path|()) as string return {fromPathRes:s1Val, toPathRes:s2Val} end chooseTwoPath: on doModal:aParam set (my returnCode) to aParam’s runModal() end doModal: |
More from my site
(Visited 55 times, 1 visits today)