Link to home
Start Free TrialLog in
Avatar of SatelliteCreative
SatelliteCreative

asked on

How to open PDF file with Applescript

Hi, I am trying to open a PDF on a CD with an Applescript saved in the same directory as the script.

The attached code doesn't work, and I suspect I'm not giving enough of a path to the 'open' function.

Any pointers? I want to be able to do this without buying/installing any custom scripts/components/apps.

Thanks!
tell application "Finder"
 
activate
 
open document file "test.pdf"
 
end tell

Open in new window

Avatar of dscl
dscl

Okay assuming I am following you correctly.  You want a applescript that will open a pdf located in the same folder as the script on a CD right?

If so give this a try.



set myPath to path to me as Unicode text
set {tid, text item delimiters} to {text item delimiters, ":"}
set vol to text items 1 thru -2 of myPath as string
set text item delimiters to tid
tell application "Finder" to open file (vol & ":test.pdf")

Open in new window

Avatar of SatelliteCreative

ASKER

Ok thanks, can you tell me whether I should be able to test that from a folder NOT on the CD? I've tried to run it and I get the error:

Finder got an error: Cant get file \"Macintosh HD:Users:Monolith:Desktop:Script Editor.app:test.pdf\"."

so I imagine its looking for the pdf IN the script editor?
ASKER CERTIFIED SOLUTION
Avatar of dscl
dscl

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi, it's fine to work standalone as an application, so now I've saved as you suggest it works perfectly.

Unfortunately now I can't get flash's fscommand to run the script from a 'projector' file! Anyway, I'll probably post another question about this.

Thanks very much for your help!


you might try running it as a script thru the fscommand.  I'm honestly not sure what would happen in that case, but it might, and hopefully would, work as we want/expect it too.