I’m trying to do something very simple and have run into a vexing problem.
From another app, I’m generating a pdf file with the intent of opening it in Preview. Since I can’t script Preview (I’m trying to come up with a deployable solution) I’m doing the following:
tell application “Finder”
open “my computer:Users:my domain:Library:Application Support:my app:tmp:test.pdf”
end tell
Problem is, sometimes the file doesn’t open. I’ve confirmed that the file is where it is expected to be but still the applescript won’t open it and no error is reported after running the script. When this occurs, I can continue to generate more files and they too won’t open until suddenly, one opens. All files generated after that one open flawlessly.
Any ideas what the issue may be?
Thanks for the help.
-Alan
It’s also possible without the shell
tell application "Finder"
open ((path to application support from user domain as text) & "my app:tmp:test.pdf") using (path to application "Preview")
end tell
StefanK,
when I try that in the applescript editor I get the error message: “Finder got an error: Handler can’t handle objects in this class.”
When I remove (path to application support from user domain as text) the error goes away.
-Alan
Tom, my testing indicates that when my applescript fails to open the file, your one liner will. That’s great!
I have a couple questions for you if you don’t mind:
Do you have any idea why my script fails and yours works?
Is there any way to modify your one liner to force the pdf to be opened in Preview?
Thanks.
-Alan
Probably Tiger and Leopard behave different.
This should work in both systems
set myFile to ((path to application support from user domain as Unicode text) & "my app:tmp:test.pdf")
tell application "Finder"
open myFile using (path to application "Preview")
end tell