AppleScript Finder "打开使用"问题



我在编写(我认为会是)一个非常简单的部分时遇到了一些麻烦。基本上,我想告诉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:用户:用户:"webbarcextract: "OSX:Applications:Utilities: webbarchive folder .app"

当我试图运行代码时,我得到的错误发生在打开tempPath &"弧。webbarchive "使用webbarcextract line。Finder会弹出一条消息:"找不到应用程序"。

我真的被这个弄糊涂了。我知道路径是正确的,我知道应用程序可以通过这种方式打开文件。我可以用Finder找到弧线。我想打开的webchive文件,右键单击该文件,选择"打开> webchive文件夹",它工作得很好。

有什么建议吗?

这里有一些建议。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"…

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

最新更新