1

I'm having some trouble scripting (what I thought would be) a very easy section of something I'm working on. Basically, I want to tell Finder to open a file with a specific application. Simple, right? From what I've read I should be able to use:

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

The trouble is Finder seems to be having one heck of a time finding the application. When I use the following code:

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

The values of the variables are as follows:

tempPath: "OSX_Data:Users:user:" webArcExtract: "OSX:Applications:Utilities:WebArchive Folderizer.app"

The error I get when trying to run the code occurs on the open tempPath & "arc.webarchive" using webArcExtract line. A message pops up from Finder stating "The Application cannot be found."

Im really befuddled by this one. I KNOW the path is right and I KNOW the application can open files this way. I can use Finder to go to the arc.webarchive file I'm trying to open, right-click on the file, and select "open with > WebArchive Folderizer" and it works perfectly.

Any suggestions?

1 Answer 1

3

Here's a couple suggestions. 1) an easier method to get the path to an application is to just use applescript's "path to" command so something like this should work...

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) You do not need the Finder for the tempPath, again just use "path to"...

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

3) finally you need a file specifier here, so add the keyword "file" before the file path as I did in #1...

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

I hope that helps.

2
  • Doh! I knew it was something simple. Missing "file" noun. (facepalm) Now I feel like an idiot. Thanks for the tip on the "path to" trick as well. Super handy. I'll use that one all the time. I figured there was a better way to do that. Apr 27, 2011 at 3:01
  • +1; one subtlety worth pointing out: path to doesn't actually return a path string, as one might suspect, but an alias object pointing to the file; to turn this object into an HFS-format path string, use appPath as text (as in the answer), to obtain the POSIX-format path string, use POSIX path of appPath.
    – mklement0
    May 2, 2014 at 3:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.