[List]選択中フォルダ内のリスト
シンプルにパスが必要な『ダケ』ならFinderで
色々条件あるならcontentsOfDirectoryAtURL
NSOpenPanelはアプリケーションに書き出さないと利用できない
tell application "Finder"
-->ファインダで選択中の項目の戻り値は『リスト』
set listSelection to selection as list
-->リストに格納されている個数を数えて
set numCntListItem to (count of listSelection) as number
-->リストの項目が1つなら
if numCntListItem = 1 then
set strKind to kind of item 1 of listSelection as Unicode text
-->選択中の項目が『フォルダ』なら
if strKind is "フォルダ" then
set listContents to every item of (entire contents of (item 1 of listSelection)) as list
else
return "フォルダ以外を選択時には実行しない"
end if
else
return "複数選択時には実行しない"
end if
end tell
#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
#
#
#
# com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
use AppleScript version "2.8"
use framework "Foundation"
use scripting additions
property refMe : a reference to current application
property refNSString : a reference to refMe's NSString
property refNSURL : a reference to refMe's NSURL
set objFileManager to refMe's NSFileManager's defaultManager()
tell application "Finder"
-->ファインダで選択中の項目の戻り値は『リスト』
set listSelection to selection as list
end tell
-->リストに格納されている個数を数えて
set numCntListItem to (count of listSelection) as number
-->リストの項目が1つなら
if numCntListItem = 1 then
set strKind to kind of item 1 of listSelection as Unicode text
-->選択中の項目が『フォルダ』なら
if strKind is "フォルダ" then
set aliasFolderPath to item 1 of listSelection as alias
set strFolderPath to POSIX path of aliasFolderPath as text
set ocidFolderPath to refNSString's stringWithString:strFolderPath
set ocidFolderPathURL to refNSURL's alloc()'s initFileURLWithPath:ocidFolderPath
set listContentsAndError to objFileManager's contentsOfDirectoryAtURL:ocidFolderPathURL includingPropertiesForKeys:(missing value) options:(refMe's NSDirectoryEnumerationSkipsHiddenFiles) |error|:(reference)
(*##NSURLResourceKey
フォルダ関連のキーは2つ
NSURLIsDirectoryKey
NSURLParentDirectoryURLKey
*)
(* ##NSDirectoryEnumerationOptions
フォルダ関連のオプションは3つ
NSDirectoryEnumerationSkipsSubdirectoryDescendants:0
NSDirectoryEnumerationSkipsPackageDescendants:1
NSDirectoryEnumerationSkipsHiddenFiles:2
*)
-->戻り値 MutableArray (*__NSArrayM*)
log item 1 of listContentsAndError as list
-->エラーの場合の戻り値エラーがなければmissing valueが戻り値
log item 2 of listContentsAndError
else
return "フォルダ以外を選択時には実行しない"
end if
else
return "複数選択時には実行しない"
end if
#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
#
#
#
# com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
use AppleScript version "2.8"
use framework "Foundation"
use scripting additions
property refMe : a reference to current application
property refNSString : a reference to refMe's NSString
set objFileManager to refMe's NSFileManager's defaultManager()
tell application "Finder"
-->ファインダで選択中の項目の戻り値は『リスト』
set listSelection to selection as list
end tell
-->リストに格納されている個数を数えて
set numCntListItem to (count of listSelection) as number
-->リストの項目が1つなら
if numCntListItem = 1 then
set strKind to kind of item 1 of listSelection as Unicode text
-->選択中の項目が『フォルダ』なら
if strKind is "フォルダ" then
set aliasFolderPath to item 1 of listSelection as alias
set strFolderPath to POSIX path of aliasFolderPath as text
set ocidFolderPath to refNSString's stringWithString:strFolderPath
set listContentsAndError to objFileManager's contentsOfDirectoryAtPath:ocidFolderPath |error|:(reference)
-->戻り値 MutableArray (*__NSArrayM*)
log item 1 of listContentsAndError as list
-->エラーの場合の戻り値エラーがなければmissing valueが戻り値
log item 2 of listContentsAndError
else
return "フォルダ以外を選択時には実行しない"
end if
else
return "複数選択時には実行しない"
end if
| 固定リンク
「AppleScript entire contents」カテゴリの記事
- [Finder] list folder フォルダ内のファイル名の収集 から フォルダを作ってフォルダの中へ移動させる (重複制御あり)(2025.05.26)
- [Finder] entire contents whose コンテンツの収集 から フォルダを作ってフォルダの中へ移動させる (重複制御あり)(2025.05.24)
- [Finder] entire contents whose コンテンツの収集 から フォルダを作ってフォルダの中へ移動させる(2025.05.23)
- [Finder] entire contents コンテンツの収集(2025.04.29)
- [sort by]ファイルパスのソート (Finderのサイズ・ファイル名・日付等)(2025.03.26)