02/10 フォルダの選択(内容確認つき)v2
「ちょっと気の利いた複数folder選択」を発展させ、選択したフォルダの一覧を確認表示するようにしたAppleScriptです。
最大の見どころは、フォルダパスを一覧表示するさいに、どのパスかを示す文字の長さをそろえて、フォルダパスの内容確認を行いやすくした「umekusaKit」です。

これで、選択した複数パスの一覧を表示し、処理前に確認するように書いておけば、ささいなミスもなくなるに違いありません。
ちなみに、この一覧表示で「Cancel」ボタンをクリックすると……

のように、処理を中断します。
どうも、プログラムを見直してみると……もっと汎用的なサブルーチンに仕立てて、もっと簡単に利用できるようにできそうな気がします。まだ、手直しできる余地が大きそうですが、使用頻度はあまり高くなさそうなので……このままかもしれません。
| スクリプト名:フォルダの選択(内容確認つき)v2 |
| property aFol : missing value property bFol : missing value property cFol : missing value set a1Mes to “コマの書類の親フォルダ” set b1Mes to “ページアップ先のフォルダ” set c1Mes to “ページ台紙が入っているフォルダ” set a2Mes to “(komaFolderServerPath)を選択” set b2Mes to “(pageUpOutputTargetPath)を選択” set c2Mes to “(pageDaishiFolder)を選択” if aFol = missing value then set aFol to choose folder with prompt (a1Mes & a2Mes) else set aFol to choose folder default location aFol with prompt (a1Mes & a2Mes) end if if bFol = missing value then set bFol to choose folder with prompt (b1Mes & b2Mes) else set bFol to choose folder default location bFol with prompt (b1Mes & b2Mes) end if if cFol = missing value then set cFol to choose folder with prompt (c1Mes & c2Mes) else set cFol to choose folder default location cFol with prompt (c1Mes & c2Mes) end if –設定内容の確認表示 set aaList to {a1Mes, b1Mes, c1Mes} set {r1, r2, r3} to makeSameString(aaList, “ ”) of umekusaKit –ウメクサ文字には全角スペースを指定 set aList to {r1 & “ = ” & aFol as string, r2 & “ = ” & bFol as string, r3 & “ = ” & cFol as string} set defaultItem to contents of item 1 of aList –最終確認 set aRes to choose from list aList with prompt “この設定でよいですか?” default items defaultItem with title “指定内容の最終確認” if aRes = false then display dialog “処理を中止します” buttons {“OK”} default button 1 with icon 1 with title “処理中止” return end if –このあとにメインの処理が入る –文字リストをchoose from listで表示させる際に長さを揃えるために作った script umekusaKit –最大の長さの文字列に合わせて、ウメクサ文字を後ろに追加する –fillCharは1文字であることを期待している –全角文字と半角文字が「混在しない」ことを期待している。あるいは、半角文字の文字長が一緒とか on makeSameString(aList, fillChar) –リスト中の文字列長の最大値を求める set lenList to {} repeat with i in aList set the end of lenList to length of (contents of i) end repeat set maxLen to item (maximumItemNoFromList(lenList) of me) of lenList –最大長に合わせて各項目の末尾にfillCharを追加する set retList to {} repeat with i in aList set newStr to contents of i set aLen to length of i repeat with ii from 1 to (maxLen - aLen) set newStr to newStr & fillChar end repeat set the end of retList to newStr end repeat return retList end makeSameString –最大値の項目番号を取得する on maximumItemNoFromList(nList) script o property nl : nList property itemNo : 1 end script set max to item 1 of o’s nl repeat with i from 2 to (count nList) set n to item i of o’s nl if n > max then set max to n set o’s itemNo to i end if end repeat return o’s itemNo end maximumItemNoFromList end script |


