可以一次使用AppleScript选择文件或文件夹吗?
现在我可以使用
tell application "SystemUIServer" to return POSIX path of (choose file)
要么
tell application "SystemUIServer" to return POSIX path of (choose folder)
获取文件或文件夹。但是我无法一次获得文件或文件夹。
不,您不能使用“选择文件”或“选择文件夹”动词来执行此操作,但底层NSOpenPanel. 所以你可以使用 AppleScriptObjC 来完成。这是使用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
ASObjCRunner 将 a 对象转换NSArray为NSURLAppleScript s 列表file;结果可能类似于:
{file "Macintosh HD:Users:nicholas:Desktop:fontconfig:", file "Macintosh HD:Users:nicholas:Desktop:form.pdf"}
| 归档时间: | 
 | 
| 查看次数: | 10528 次 | 
| 最近记录: |