Opening a PDF from a CD

Hi to all.

I’m absolutely new to AppleScript and I need a urgent hand on a simple operation that I have to do.

I’m preparing a CD-ROM and I have a pdf folder in the root of my CD. Then I have a MAC folder on the same level and a subfolder named FSCOMMAND in this last folder, that should contain my applescript.

I have to open a .pdf file located in the PDF folder, two levels up in the folders gerarchy, and the Acrobat Reader application to show it to the user.

I would be grateful if someone could show me an example of a working applescript, considering also the gerarchy of my folders and considering that I’d like that it worked also on the OS X platforms.

Thank you in advance.

Is Acrobat Reader included on the CD? If so, where is it located? If you plan to open the pdf file with the user’s installed copy of Reader, this might work. You need to modify the script so that it points to the correct pdf file.

try
	tell application "Finder" to open file ("CD Name:PDF:Your.pdf") using (get application file id "CARO" as text)
on error e
	display dialog e
end try

– Rob

Thank you for your help, I have a problem anyway: I’m testing it on my hard disk and the file is located at the same level of my script. I wrote


try
	tell application "Finder" to open file ("001.pdf") using (get application file id "CARO" as text)
on error e
	display dialog e
end try

It returns error -10814 :frowning:

Is the path wrong? Or what else? I’m testing on OS X Panther, could this be a problem?

Thank you.

If I’m not mistaken, the Finder, when lacking a full reference to the file, will look for it in the desktop folder. Move the file to the desktop to test the script.

– Rob

Thank you very much, I will try tomorrow morning and I’ll tell you if it works. :slight_smile:

I’m sorry but it still doesn’t work, it return the same error… It should be a so easy task, why does it create all these problems to open a simple PDF? :frowning:

Does the following script work? It will present a dialog where you can select the PDF and then attempt to open it with Reader. It will also place some information on the clipboard. I would like you to paste it into your reply here. Warning: If your clipboard contains data that you need, don’t run the script.

set file_path to (choose file with prompt "Choose the PDF file.") as Unicode text

tell application "Finder"
	set reader_path to (application file id "CARO") as Unicode text
	open file file_path using reader_path
end tell

set the clipboard to "PDF File: " & file_path & return & ¬
	"Reader Path: " & reader_path

– Rob

It opens the dialog window where I can choose the file, but when I click on the chosen file it returns the same error again

This is the returned Error:

Finder ha trovato un errore: Si è verificato un errore di tipo -10814.

It doesn’t let me paste anything, I don’t know, it seems that no data where copied on the clipboard.

OK, it appears that Unicode text might be a problem on pre-OS X machines. Maybe this will work.

set file_path to (choose file with prompt "Choose the PDF file.") as text 
  
 tell application "Finder" 
    set reader_path to (application file id "CARO") as text 
    open file file_path using reader_path 
 end tell 
  
 set the clipboard to "PDF File: " & file_path & return & ¬ 
    "Reader Path: " & reader_path

If you have further problems, please provide info about your test environment(s).
– Rob

This works for me (OS9.2) :


set file_path to (choose file with prompt "Choose the PDF file.") as text

tell application "Finder"
	set reader_path to (application file id "CARO") --as text was a problem
	open file file_path using reader_path
	
end tell
tell application id "CARO" to activate --need to activate an app, otherwise set the clipboard dont work
set the clipboard to "PDF File: " & file_path & return & ¬
	"Reader Path: " & reader_path

I don’t know, maybe there are some problems on my system, it continues to return the same error. I’m working on a Mac OS X panther (10.3.2). :frowning: