Solved

How to open PDF file with Applescript

Posted on 2008-10-24
5
3,623 Views
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.

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

Open in new window

0
Comment
Question by:SatelliteCreative
  • 3
  • 2
5 Comments
 
LVL 2

Expert Comment

by:dscl
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

0
 
LVL 3

Author Comment

by:SatelliteCreative
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?
0
 
LVL 2

Accepted Solution

by:
dscl earned 500 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.
0
 
LVL 3

Author Comment

by:SatelliteCreative
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!


0
 
LVL 2

Expert Comment

by:dscl
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.
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

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:   …
Do you come here a lot? Are you lazy like me and don't want to go through the "trouble" of having to click your Dock's Safari icon and then having to click your Experts Exchange Favorites bookmark to get here? Well then this article is for you.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

790 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