我对Applescript比较陌生,我希望有人可以帮我解决这个问题......
我有一个执行聚光灯搜索的脚本,并将找到的项目返回为founditems
。结果将是文件夹或文件夹的别名。我想打开找到的项目,如果结果是一个文件夹,它可以工作,但我无法弄清楚如何处理别名。使用别名我得到错误包含在代码中
try
set theapp to default application of (get info for (POSIX file founditems)) as string
tell application theapp to open (POSIX file founditems as string)
activate application theapp
on error e
display dialog "An error has occured trying to open your file:" & return & return & e buttons {"OK"} default button 1
end try
我收到10665错误代码。我的猜测是合并original path
可能会解决别名问题,但我不确定如何将其插入...非常感谢
founditems
以这种方式创建:
set input_var to "12345"
set spotlightquery to "\"kMDItemFinderComment == '" & input_var & "'\""
set thefolders to {POSIX file "/Volumes/RAIDvolume"}
set founditems to {}
repeat with i in thefolders
set thepath to quoted form of POSIX path of i
if exists thepath then
set command to "mdfind -onlyin " & thepath & " " & spotlightquery
set founditems to founditems & (paragraphs of (do shell script command))
end if
end repeat
答案 0 :(得分:1)
所以这是一个列表,因为你使用""段落我现在可以看到,创新项目是一个posix路径列表。因此,无论路径是文件,文件夹还是别名,以下内容都将使用默认应用程序打开它。
set founditems to {"/Users/hmcshane/Desktop/aaa alias"}
set macPath to POSIX file (item 1 of founditems)
tell application "Finder" to open macPath