automatic launch

How can I tell an applescript to launch automatically when a certain application launches?

I’m not sure I understand what you are trying to do. Could you post some of the code that is not working for you?

I just want an applescript to launch when I launch iTunes

tell application "System Events" to get name of every process whose name contains ("iTunes" as text)
if result contains "iTunes" then
	tell application "MyScript" to launch --MyScript is the name of your application
end if

I want an apple script to run not an application

Hence the code:


if result contains "iTunes" then 
   tell application "MyScript" to launch --MyScript is the name of your application 
end if

This tells your script “MyScript” to launch.

The only tricky part I see is to have this script running in the background to open up your script when iTunes launches.

Thanks.
SA

I think the confusion here is that you don’t realize that you can save your script as an application from the Script Editor (try a “Save As…” and choose “Application” as your File Format). Once you have done this, you can use the code above to launch your script.

Incidentally, the code above must also be saved as a stay-open application with an idle routine to keep checking to see if the application has been launched. It should also have a flag so that if it has launched the second script application once, it won’t do so again until the app (iTunes in this case) has been found to no longer exist in the process list and then run it again once it exists again. Once you have configured this “watch script app”, you might want to add it to your Login Items to have it start up whenever you login.

Perhaps this isn’t very intuitive for a new user, but this should give you a little more to go on.

Jon