我是比較新的AppleScript的,我希望有人能幫助我解決這個...打開Finder別名
我有一個腳本,做一個聚光燈搜索,並返回找到的項目爲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
不知道我是否正確地回答了您的問題,但如果您告訴Finder打開文件,它將始終由默認應用程序打開。這適用於文件,別名和文件夾。 – user309603 2014-09-11 07:06:41
這是我的假設,但正如我所說只有文件夾正確打開。別名返回錯誤。我的猜測是,我必須從別名中找出「原始」(當你點擊別名上的獲取信息時它會顯示它)。我只是不知道如何處理 – user3101259 2014-09-11 19:24:33
您的問題令人困惑,因爲「founditems」對我來說聽起來是複數。例如,這不意味着1項。因爲它是複數,我猜你實際上有一個項目清單。也許列表只包含1個項目,但它仍然是一個列表。如果我是正確的,那麼當您嘗試獲取列表的「POSIX文件」時,這是沒有意義的。這可能會導致你所有的麻煩。請展示如何使用Spotlight搜索生成Founditems,然後我們可以更好地幫助您。 – regulus6633 2014-09-11 19:59:08