I am currently using code in this format to open a pdf from a cd via a Flash projector
tell application “Finder”
select file “example.pdf” in folder “pdfs” of disk “CD”
This works fine, but I need to be able to open the pdf even if the user has copied the contents of the CD onto their computer. i.e from any given location.
Is there anyway of returning the path that an applescript has been called from so I know where the files have been copied to. Or any other way of opening a PDF with applescript from a path relative to where the applescript resides.
This is the wrong approach to take to opening a file.
The issues are that a) the Finder has to be activated, b) it manipulates the selection, potentially opening folder windows that the user doesn’t expect and c) is prone to runtime errors if the user performs some action (e.g. changes the selection or changes window focus while your script runs.
tell application "Finder"
set my_reference to container of (path to me) as text
open file my_reference & "example.pdf"
This doesn’t activate the Finder. It doesn’t change active windows, open any windows, change the selected item(s). It just does what you want it to.
Thanks alot Camelot I have been unhappy with the whole approach of opening different finder windows. This is much cleaner. Wish I hadn’t just rewritten the 63 seperate scripts I am using before reading your post.