AppleScript Finder“打开使用”问题

问题描述:

我遇到了一些问题脚本(我认为会)是我正在处理的一个非常简单的部分。基本上,我想告诉Finder打开一个特定应用程序的文件。很简单,对吧?从我读过,我应该能够使用:AppleScript Finder“打开使用”问题

tell application "Finder" 
    open "the_file" using "the_application" 
end tell 

麻烦的是查找似乎有一个时间找到应用赫克。当我使用下面的代码:是

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:用户:用户:” webArcExtract:“OSX:应用:公用事业:WebArchive Folderizer。应用arc.webarchive”

试图运行代码时,我得到的错误在开放TEMPPATH &发生‘’使用webArcExtract线。从Finder弹出一条消息,声明“无法找到应用程序”。

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

有什么建议吗?

这里有几点建议。 1)一个更简单的方法来获得路径的应用程序只使用AppleScript的的“路径”命令,所以这样的事情应该工作...

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 ,又只是用“路径” ......

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

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

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

我希望这有助于。

+0

Doh!我知道这很简单。缺少“文件”名词。 (* facepalm *)现在我觉得自己像个白痴。感谢您提供关于“路径”技巧的提示。超级方便。我会一直使用那个。我想有一个更好的方法来做到这一点。 – EightQuarterBit 2011-04-27 03:01:16

+0

+1;值得指出的一点是:'path to'并不实际返回_path string_,正如人们可能会怀疑的那样,而是一个指向文件的别名_object_;要将此对象转换为HFS格式的路径字符串,请使用'appPath as text'(如答案中所示)来获取POSIX格式的路径字符串,使用'appPath的POSIX路径'。 – mklement0 2014-05-02 03:22:32