Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


How to open PDF file with Applescript

Posted on 2008-10-24
Medium Priority
Last Modified: 2010-04-29
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.

tell application "Finder"
open document file "test.pdf"
end tell

Open in new window

Question by:SatelliteCreative
  • 3
  • 2

Expert Comment

ID: 22795845
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


Author Comment

ID: 22796041
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?

Accepted Solution

dscl earned 2000 total points
ID: 22796111
Ahh, script editor!  Script editor has a long standing bug that causes path to me to refer to Script Editor rather than the script itself.  When you deploy your script are you going to be doing so as a AppleScript Application (self-running) or thru a script that actually needs to be ran thru the editor.

If you are doing an application (File > Save As > Application) then everything will work.  If you intend to run the script thru the editor then we need to work up another solution.  If you always know the CD name this would be trivial to do.

About the bug though.  If you do a lot of AppleScripting I would recommend you take a look at a product called Script Debugger.  It's not free, but it's a godsend for AppleScripters and doesn't contain many of the bugs (including this one) that Script Debugger does.

Author Comment

ID: 22796857
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!


Expert Comment

ID: 22796916
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.

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Preface   In the first 100 days of the Macintosh release in January 1984, Apple sold 72,000 of the computers. Relatively cheap, easy-to-use personal computer with a graphical operating system. I've never seen this model. I did see this one:   …
CocoaPods is the best way to manage library dependencies in iOS and OS X projects. By using cocoa pods there is no need of downloading the code from github and copying to your project. There are plenty of open source libraries now available with C…
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…

571 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question