AppleScript Finder“;开放式使用;问题

AppleScript Finder“;开放式使用;问题,applescript,using,finder,tell,Applescript,Using,Finder,Tell,我在编写(我认为会是)我正在处理的一个非常简单的部分时遇到了一些问题。基本上,我想告诉Finder使用特定的应用程序打开一个文件。很简单,对吧?根据我所阅读的内容,我应该能够使用: tell application "Finder" open "the_file" using "the_application" end tell 问题是Finder似乎在查找应用程序时遇到了麻烦。当我使用以下代码时: set webArcExtract to POSIX file (do shell s

我在编写(我认为会是)我正在处理的一个非常简单的部分时遇到了一些问题。基本上,我想告诉Finder使用特定的应用程序打开一个文件。很简单,对吧?根据我所阅读的内容,我应该能够使用:

tell application "Finder"
    open "the_file" using "the_application"
end tell
问题是Finder似乎在查找应用程序时遇到了麻烦。当我使用以下代码时:

set webArcExtract to POSIX file (do shell script "mdfind 'WebArchive Folderizer.app' -onlyin '/Applications/'") as string #Find the Web Archive Extraction Program

tell application "Finder" #Temporary path to save the web archive
    set tempPath to ((home as string) & "temp:")
end tell

tell application "Fake" #Magic that saves a webpage as a webarchive
    load URL "www.google.com"
    delay 3
    capture web page as Web Archive saving in tempPath & "arc.webarchive"
end tell

tell application "Finder" #Open the arc.webarchive file saved in the tempPath with the WebArchive Folderizer application
    open tempPath & "arc.webarchive" using webArcExtract
end tell
变量值如下所示:

tempPath:“OSX_数据:用户:用户:” webArcExtract:“OSX:Applications:Utilities:WebArchive Folderizer.app”

尝试运行代码时出现的错误发生在使用webArcExtract行打开的tempPath&“arc.webarchive”上。Finder会弹出一条消息,说明“找不到应用程序”

我真的被这件事弄糊涂了。我知道路径是正确的,我知道应用程序可以通过这种方式打开文件。我可以使用Finder转到我试图打开的arc.webarchive文件,右键单击该文件,然后选择“open with>webarchive Folderizer”,它可以正常工作


有什么建议吗?

这里有一些建议。 1) 获取应用程序路径的一种更简单的方法是只使用applescript的“path to”命令,这样类似的命令应该可以工作

set theFile to (path to desktop as text) & "a.txt"
set appPath to path to application "TextWrangler"
tell application "Finder" to open file theFile using appPath
2) 您不需要tempPath的查找器,再次使用“path to”

3) 最后,这里需要一个文件说明符,所以在文件路径之前添加关键字“file”,就像我在#1中所做的那样


我希望这会有帮助。

Doh!我知道这很简单。缺少“文件”名词。(facepalm)现在我觉得自己像个白痴。谢谢你的提示“路径到”技巧以及。非常方便。我会一直用那个。我想有更好的办法;值得指出的一个微妙之处是:
path to
实际上并不像人们所怀疑的那样返回路径字符串,而是一个指向文件的
alias
对象;要将此对象转换为HFS格式路径字符串,请使用
appPath as text
(如答案所示),要获取POSIX格式路径字符串,请使用appPath的
POSIX path
set tempPath to (path to home folder as text) & "temp:"
tell application "Finder"
    open file (tempPath & "arc.webarchive") using webArcExtract
end tell