AppleScript选择文件或文件夹

时间:2013-10-23 04:16:38

标签: macos applescript

我可以使用AppleScript一次选择文件或文件夹吗?

现在我可以使用

tell application "SystemUIServer" to return POSIX path of (choose file)

tell application "SystemUIServer" to return POSIX path of (choose folder)

获取文件或文件夹。但是我无法一次获取文件或文件夹。

2 个答案:

答案 0 :(得分:4)

不,你不能用“选择文件”或“选择文件夹”动词来做,但是底层{{{{{{ 1}}。所以你可以用AppleScriptObjC做到这一点。以下是使用ASObjCRunner(源自here)的示例:

NSOpenPanel

ASObjCRunner将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 NSArray个对象转换为NSURL s的AppleScript列表;结果可能类似于:

file

答案 1 :(得分:0)

首先,你不需要告诉它。

POSIX path of (choose file)

其次,目前尚不清楚为什么需要这个。你的意思是你想要选择一个文件和它的文件夹?那不是你怎么做的;您选择文件然后解析包含文件夹的文件路径或使用许多方法之一来做到这一点,如

set f to (choose file)
set posixF to POSIX path of f
tell application "Finder" to set filesDir to container of f as alias as text
set posixDir to POSIX path of filesDir

{f, posixF, filesDir, posixDir}

如果您希望能够同时选择多个文件夹和文件,我认为没有“纯AppleScript”方法(除了使用拖放式删除脚本应用程序之外)。< / p>

相关问题