在使用“从文件中选择”提示时,您如何才允许用户选择文件夹?此外,一旦他们选择了文件,您将如何获取文件路径返回的文本。 (因此返回的文本为/Users/myname/Desktop/afile
)
我目前的工作代码如下:
set d to the text returned of (choose file with prompt "Please choose a file:" of type {"??", "??"} default location "/Users/myname/Desktop")
在AppleScript中运行时,它只允许您选择文件,一旦您这样做,我会收到错误
error "Can’t get text returned of alias \"Macintosh HD:Users:myname:Desktop:filename.extention:\"." number -1728 from text returned of alias "Macintosh HD:Users:myname:Desktop:filename.extention:"
答案 0 :(得分:1)
choose file
会向所选文件返回alias
说明符。您将其与display dialog
混合,后者返回包含text returned
的记录。
要获得斜杠分隔的POSIX路径,请将POSIX path
放在表达式
set d to POSIX path of (choose file with prompt "Please choose a file:" default location (path to desktop))
如果要使用choose folder
选择文件夹,请使用相同的语法
set d to POSIX path of (choose folder with prompt "Please choose a folder:" default location (path to desktop))