AppleScript的选择文件或文件夹 [英] AppleScript choose file or folder

查看:1516
本文介绍了AppleScript的选择文件或文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以使用AppleScript的选择无论是文件或文件夹在一个时间?

can I use AppleScript to choose either file or folder in one time?

现在我可以使用

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

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

获取文件或文件夹。但是我不能让文件或文件夹中的一次。

to get file or folder. However I cannot get file or folder in one time.

推荐答案

没有,你不能以选择文件或选择文件夹动词,但选择一个文件的的文件夹,这样做(或多个文件/文件夹)是由底层 NSOpenPanel 支持。所以,你可以用AppleScriptObjC做到这一点。下面是使用 ASObjCRunner (一个例子,从的here ):

No, you can't do it with "choose file" or "choose folder" verbs, but choosing a file or folder (or multiple files/folders) is supported by the underlying NSOpenPanel. So you can do it with AppleScriptObjC. Here's an example using ASObjCRunner (derived from 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转换 NSURL 的NSArray 对象插入的一个AppleScript列表文件 S;其结果可能是这个样子:

ASObjCRunner converts a NSArray of NSURL objects into an AppleScript list of files; the results can look something like:

{file "Macintosh HD:Users:nicholas:Desktop:fontconfig:", file "Macintosh HD:Users:nicholas:Desktop:form.pdf"}

这篇关于AppleScript的选择文件或文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆