ここでは、私が作ってきたスクリプトの中で使った命令を紹介します。
なお、細かい用語の解説は省きます。
【1】文字列のByte数を調べる
【2】文字列の置換
【3】データフォーク消去
【4】ドロップレットでのエイリアスの扱い
【5】他のアプリケーションの処理を待つ
【6】ダイアログ
【7】アプリケーションの有無
【8】リストダイアログ
on ByteCheck(AllStr) set ByteNum to 0 repeat with str in AllStr if (ASCII number str) < 128 then set ByteNum to ByteNum + 1 else set ByteNum to ByteNum + 2 end if end repeat return ByteNum end ByteCheck |
ByteNum = 4 and length of AllStr = 4
」
on changeDelim(cangeText, setDelim, cangeDelim) set LastDelim to AppleScript's text item delimiters set AppleScript's text item delimiters to setDelim set cangeText to text items of cangeText set AppleScript's text item delimiters to cangeDelim set cangeText to cangeText as string set AppleScript's text item delimiters to LastDelim return cangeText end changeDelim |
tell application "Finder"
set obj to
|
|
repeat until (application file of (item -1 of (processes whose frontmost = true))) /= anyApplication delay 1 end repeat |
【6】ダイアログ
「disiplay dialog」には様々な引数がありますが、それらは変数に入れても使用できます。
repeat set DlgBtn to {"OK", "OK", "OK"} set num to some number of {1, 2, 3} set item num of DlgBtn to "キャンセル" set DlgAns to item num of {return & "stop", return & "note" & return & return, "caution"} set IconNum to num - 1 set DlgTxt to item num of {"ストップ", "ノート", "コーション"} display dialog DlgTxt buttons DlgBtn default answer DlgAns default button num with icon IconNum giving up after (num * 2) end repeat |
tell application "Finder" to set obj to application file id "ttxt" |
【8】リストダイアログ
choose from listを使用することで、3つ以上の選択肢を提示することが可能ですが、選択内容はリストに表示されたテキストそのものなので、選択内容を元に処理を行うのは面倒です。
そこで、表示項目の先頭にナンバリングを行い、選択項目から数字だけを取得し、その数字から処理対象を選択することで、リストの内容自体を可変的なものにすることが可能です。
ちょっと長いですが、choose from listを使ったファイルランチャーをまるごと掲載しておきます。
property OpenFile : {} --開くファイルのパス property NameList : {} --開くファイルの名前 on run OpenDialog() end run on OpenDialog() --リスト表示 set DlgName to {} repeat with ListNum from 1 to (count NameList) --項目作成 set end of DlgName to {(ListNum & ":" & item ListNum of NameList) as string} --ナンバリング end repeat set DlogFile to {"追加"} & DlgName --リストの先頭に追加を追加 if OpenFile /= {} then set end of DlogFile to {"削除"} --リストに項目がある場合は削除を追加 set List_Res to choose from list (DlogFile as list) with prompt ツ "起動するファイルを選択して下さい。" with multiple selections allowed --リスト表示 if List_Res /= false then repeat with select_res in List_Res --選択項目判定 set select_res to select_res as string if select_res = "追加" then FileSet() OpenDialog() --項目追加後、選択に戻る else if select_res = "削除" then FileDelete(DlgName) else set SelectFile to item (character 1 of select_res) of OpenFile --↑選択項目の順番と同じ順番にあるOpenFile中のファイル FileOpen(SelectFile) --選択ファイルを開く end if end repeat end if end OpenDialog on FileSet() --ファイルの追加 set end of OpenFile to (choose file with prompt "リストに追加するファイルを選んで下さい。") tell application "Finder" to set end of NameList to {(name of last item of OpenFile) as string} end FileSet on FileOpen(SelectFile) --ファイルを開く ignoring application responses --ファイルを開けたかどうかを無視 tell application "Finder" to open file SelectFile end ignoring end FileOpen on FileDelete(DeleteList) --リスト項目削除 set Delete_Res to (choose from list DeleteList with prompt ツ "リストから削除する項目を選択して下さい。" OK button name "削除") set Delete_Num to (character 1 of (Delete_Res as string) as integer) --項目番号取得 set ItemNum to (count OpenFile) if (count NameList) /= 1 then --項目が1つではない時 if Delete_Num = 1 then --1番目の項目を選択した時 set NameList to rest of NameList set OpenFile to rest of OpenFile else if Delete_Num = (count NameList) then --最後の項目の時 set NameList to (items 1 thru (Delete_Num - 1) of NameList) set OpenFile to (items 1 thru (Delete_Num - 1) of OpenFile) else --中間の項目の時 set NameList to (items 1 thru (Delete_Num - 1) of NameList) ツ & (items (Delete_Num + 1) thru ItemNum of NameList) set OpenFile to (items 1 thru (Delete_Num - 1) of OpenFile) ツ & (items (Delete_Num + 1) thru ItemNum of OpenFile) end if else --項目が1つの時 set NameList to {} set OpenFile to {} end if end FileDelete |
御質問等がありましたらメール、掲示板にて