the starting of an application should start a second application

hello

while the user starts an application a pfd helpfile should open up automatically. how can this be done with apple script?

thanks a lot for your answer

simon

Hi Simon,

this opens the PDF with the application, which is specified in the Finder Information window

tell application "Finder" to open "path:to:document.pdf"

this forces Preview.app to open the PDF

tell application "Finder" to open "path:to:document.pdf" using (path to application "Preview")

first of all thanks for your answer. although i’m not totally sure whether you got my answer. it’s not only that i would like to open a pdf file, i want to open two applications at the same time: the main program and a pdf program to open a help file, so when the user launches the main program the help file is open right from the start.
i’m totally new to apple script, but i could imagine that it must be solved with a if-then-relation?

simon

Hi simon,

the quality of the answer depends often on the quality of the question. :wink:

Do you want to

¢ write an AppleScript application which opens the PDF file while launching?
¢ have a stay open script, which poll the processes and opens the PDF file, when a certain application launches?
¢ write a script, which launches the application and opens the PDF file?

(at least) three options, how should we know, what your’re going to accomplish

hello stefan

you’re right! i was not very clear with my first question. thanks for your patience! i guess it’s our second proposal that i would like to realise.
concrete situation: the user clicks on the icon of application a (a database program) - the click opens application a and at the same time starts application b (acrobat reader oder preview) which shows a pfd help file. my intention is, that the user doesn’t have to search for the help file - it’s present and visible with the launching of the database program.

i hope this description is now clear enough - so that you can help me with my problem!

thanks

simon

Hi Simon,

a stay open script which polls the processes consumes always a certain amount of CPU,
so I would prefer a litte application which launches the app and opens the PDF file like


activate application "iCal"
tell application "Finder" to open "path:to:document.pdf"

Save it as application and assign the icon of your database to this AppleScript application

Anyway, I stay open (saved as application with option stay open) can look like this


property status : false
property _application : "iCal"

on run
    set status to false
end run

on idle
    if checkProcess() then
        if status is false then
            tell application "Finder" to open "path:to:document.pdf"
            set status to true
        end if
    else
        set status to false
    end if
    return 1
end idle

on checkProcess()
    tell application "System Events" to exists process _application
end checkProcess

Note: in Leopard “System Events” (or a shell script with ps) is no longer required to check whether an application is running
replace

if checkProcess() then

with

if application _application is running then

and remove the checkProcess() handler

Hi Stefan

Sorry for my late answer, my system was down the last two days. Your script is exactly what I was looking for, thanks! Next time I’ll try to do it myself. Do you have any recommondations for newbie books on AppleScript?

Regards

Simon

Which kind of newbie?

For a newbie newbie look at this
You can also read the tutorials at http://macscripter.net/

A very recommendable book is Hanaan Rosenthal’s AppleScript: A Comprehensive Guide
or (I call it the AppleScript bible) Matt Neuburgs AppleScript: The Definitive Guide