-- 選択ディレクトリの(POSIX)パス名+「(拡張子なしの)全ファイル名」を取得(パラメータ:ファイル拡張子) on getFileListOfFolderExt(fileExtension) -- AppleScriptは、文字列比較で大文字と小文字の文字を区別しません set promptStr to "フォルダを選択してください!" -- フォルダ選択時のプロンプト文字列 set LF to (ASCII character (10)) -- 区切り文字に LF を利用 set isFirst to true --最初かどうか? try activate --アプリケーションを前面に移動する命令 set theAlias to (choose folder with prompt promptStr) --選択フォルダの「エイリアス値」が返る tell application "Finder" set aliasList to (every file of theAlias) -- 指定フォルダ内の ファイル List を取得 repeat with f in aliasList set fExt to (f's name extension as text) --「拡張子のみ」を取得 if (fExt = fileExtension) then -- 指定拡張子を持つファイルのみを対象! if (isFirst) then set fDirHFS to (f's folder as text) -- (フォルダ)HFSパス set thePaths to (POSIX path of fDirHFS) --(フォルダ)POSIXパス end if -- set fName to (f's name as text) -- 「ファイル名+拡張子」を取得 --「ファイル名(拡張子なし)」を取得 123.scpt -> items 1 thru -6 set fName to ((f's name as text)'s items 1 thru -((fExt's length) + 2) as text) set thePaths to (thePaths & LF & fName) set isFirst to false end if end repeat end tell on error set thePaths to "" -- 「(文字列の)返り値」を初期化 display dialog "★ AppleScriptTask (getFileListOfFolderExt) ★" & return & return & "   キャンセル あるいは 異常終了" buttons {"10秒で閉じます!"} with icon caution giving up after 10 end try -- 「キャンセル」ボタン押下時用のエラーハンドリング return thePaths -- display dialog thePaths as string end getFileListOfFolderExt -- 選択ディレクトリの(POSIX)パス名+「(拡張子ありの)全ファイル名」を取得(パラメータ:初期表示フォルダ) on getFileListOfFolder(defaultLocation) -- 拡張子を指定しないため、フォルダ内の全ファイルを返す set promptStr to "フォルダを選択してください!" --フォルダ選択時のプロンプト文字列 set LF to (ASCII character (10)) -- 区切り文字に LF を利用 set isFirst to true --最初かどうか? try activate --アプリケーションを前面に移動する命令 -- 選択フォルダの「エイリアス値」が返される set theAlias to (choose folder with prompt promptStr default location defaultLocation) tell application "Finder" set aliasList to (every file of theAlias) -- 指定フォルダ内の ファイル List を取得 repeat with f in aliasList if (isFirst) then set fDirHFS to (f's folder as text) -- (フォルダ)HFSパス set thePaths to (POSIX path of fDirHFS) --(フォルダ)POSIXパス set isFirst to false end if set fName to (f's name as text) --「ファイル名+拡張子」を取得 --「ファイル名(拡張子なし)」を取得 123.scpt -> items 1 thru -6 -- set fName to ((f's name as text)'s items 1 thru -((fExt's length) + 2) as text) set thePaths to (thePaths & LF & fName) end repeat end tell on error set thePaths to "" --「(文字列の)返り値」を初期化 display dialog "★ AppleScriptTask (getFileListOfFolder) ★" & return & return & "   キャンセル あるいは 異常終了" buttons {"10秒で閉じます!"} with icon caution giving up after 10 end try -- 「キャンセル」ボタン押下時用のエラーハンドリング return thePaths -- display dialog thePaths as string end getFileListOfFolder -- 選択したファイルのパスを取得する(複数ファイルの選択不可)(パラメータ:初期表示フォルダ) on getFilePath(defaultLocation) set promptStr to "ファイルの選択(複数ファイルの選択不可)" -- フォルダ選択時のプロンプト文字列 set LF to (ASCII character (10)) -- 区切り文字に LF を利用 try activate --アプリケーションを前面に移動する命令 -- 選択したファイルの「エイリアス値」が返される set f to (choose file with prompt promptStr default location defaultLocation) tell application "Finder" set fDirHFS to (f's folder as text) -- (フォルダ)HFSパス set fDir to (POSIX path of fDirHFS) --(フォルダ) POSIXパス set fNameExt to (f's name as text) -- 拡張子付きファイル名 end tell set thePath to (fDir & LF & fNameExt) on error set thePath to "" --「(文字列の)返り値」を初期化 display dialog "★ AppleScriptTask (getFilePath) ★" & return & return & "   キャンセル あるいは 異常終了" buttons {"10秒で閉じます!"} with icon caution giving up after 10 end try -- 「キャンセル」ボタン押下時用のエラーハンドリング return thePath -- display dialog thePath as text end getFilePath -- 選択した(複数)ファイルのパスを取得する(複数ファイルの選択可能)(パラメータ:初期表示フォルダ) on getMultiFilePath(defaultLocation) set multiFile to true set promptStr to "ファイルの選択(複数ファイルの選択可能)" -- フォルダ選択時のプロンプト文字列 set LF to (ASCII character (10)) -- 区切り文字に LF を利用 set isFirst to true --最初かどうか? try activate --アプリケーションを前面に移動する命令 --「選択したファイルのエイリアス値」の List が返される set aliasList to (choose file with prompt promptStr default location defaultLocation multiple selections allowed multiFile) tell application "Finder" repeat with f in aliasList set fDirHFS to (f's folder as text) -- (フォルダ)HFSパス set fDir to (POSIX path of fDirHFS) -- (フォルダ)POSIXパス set fNameExt to (f's name as text) -- 拡張子付きファイル名 if (isFirst) then set thePaths to (fDir & LF & fNameExt) set isFirst to false else set thePaths to (thePaths & LF & fNameExt) end if end repeat end tell on error set thePaths to "" --「(文字列の)返り値」を初期化 display dialog "★ AppleScriptTask (getMultiFilePath) ★" & return & return & "   キャンセル あるいは 異常終了" buttons {"10秒で閉じます!"} with icon caution giving up after 10 end try -- 「キャンセル」ボタン押下時用のエラーハンドリング return thePaths -- display dialog thePaths as string end getMultiFilePath