Solved

How to open PDF file with Applescript

Posted on 2008-10-24
5
3,613 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

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.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

728 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now