1

我在编写我正在处理的事情的一个非常简单的部分时遇到了一些麻烦(我认为会是这样)。基本上,我想告诉 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_Data:Users:user:" webArcExtract: "OSX:Applications:Utilities:WebArchive Folderizer.app"

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

我真的被这个弄糊涂了。我知道路径是正确的,我知道应用程序可以通过这种方式打开文件。我可以使用 Finder 转到我试图打开的 arc.webarchive 文件,右键单击该文件,然后选择“使用 > WebArchive 文件夹打开”,它可以完美运行。

有什么建议么?

4

1 回答 1

3

这里有几个建议。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)您不需要临时路径的Finder,再次使用“路径”......

set tempPath to (path to home folder as text) & "temp:"

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

tell application "Finder"
    open file (tempPath & "arc.webarchive") using webArcExtract
end tell

我希望这会有所帮助。

于 2011-04-26T22:47:53.313 回答