いいえ、「ファイルを選択する」または「フォルダーを選択する」という動詞ではできませんが、ファイルまたはフォルダー (または複数のファイル/フォルダー) の選択は、基になるNSOpenPanel
. したがって、AppleScriptObjC でそれを行うことができます。ASObjCRunnerを使用した例を次に示します ( hereから派生)。
script chooseFilesOrFolders
tell current application's NSOpenPanel's openPanel()
setTitle_("Choose Files or Folders") -- window title, default is "Open"
setPrompt_("Choose") -- button name, default is "Open"
setCanChooseFiles_(true)
setCanChooseDirectories_(true)
setAllowsMultipleSelection_(true) -- remove if you only want a single file/folder
get its runModal() as integer -- show the panel
if result is current application's NSFileHandlingPanelCancelButton then error number -128 -- cancelled
return URLs() as list
end tell
end script
tell application "ASObjC Runner"
activate
run the script {chooseFilesOrFolders} with response
end tell
ASObjCRunner はNSArray
、NSURL
オブジェクトの a を AppleScript のfile
s のリストに変換します。結果は次のようになります。
{file "Macintosh HD:Users:nicholas:Desktop:fontconfig:", file "Macintosh HD:Users:nicholas:Desktop:form.pdf"}