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.
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
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.
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?
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
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
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