AppleScript Studio Problem

Hi,

I have migrated all my OS 9 scripts to Studio, they look great. Main main app has a window with a “Start” button in it that, if clicked, starts the main code.

What i now want to do is launch and start the app from within FileMaker Pro or from another AppleScript. So I need something like:

tell app “myAppleScriptStudioApp”
launch
<“press the Button “Start” so that the code starts running”>
quit
end tell

Maybe I need a special handler like “on LaunchFromOtherAppleScript” click button “Start” of window “main” … (You know what I mean)

I hope you got the message. Any hints would greatly appreciated!!

Greetings.

If you use the ‘launch’ command within a tell block, you will not get the results you want. The tell block launches AND RUNS the app implicitly, so if you want to launch without running, you have to use…

launch application "myAppleScriptStudioApp"

This will launch the app, but will not perform any of the ‘startup’ actions for the app (like opening windows or processing info). To then force it to continue running, you’d have to use…

activate application "myAppleScriptStudioApp"
-- OR --
tell application "myAppleScriptStudioApp"
	run
end tell

If you want to then perform some action (like execute your code) when one of these events happens to your main app, you can attach a handler to it’s file’s owner. I don’t think you can receive the run statement as an event (i.e. on run >> do this and that >> end run). But you can definitely receive an activated command, so you could do someting like…

on activated theObject
	-- Place your code here --
	quit -- if so desired --
end activated

If you only want to use the app to execute some code when run, you could just set it up to do it’s business on ‘activated’, rather than using a button “start” it. Then you could just launch the app or launch/activate it using the same code. If you wanted more user interaction, just make the button present for both the manual and automated launch, then you won’t have to worry about detecting which one your receiving. I think you could use scripting additions to ‘press’ the button but it might be simpler to do it one way for both events.

on activated theObject
	-- Display your window and your button --
end activated

on clicked theObject
	if name of theObject is "theButton" then
		-- Execute your code here --
		quit -- if so desired --
	end if
end clicked

This way, when your app is run internally or externally, it would prompt the user for ‘interaction’, and then execute the code when the button was pushed. I am sure there is a way to get the button to come up when the app launches itself, and to make the code execute automatically when it’s launched from another app, but I don’t know how so hopefully someone else will chip in.

Hope this helps…
j

You might need to adjust the timing (adding the quit to the end of the routine called by the button, for instance) but this should work for your needs:

tell application "myAppleScriptStudioApp"
    activate
    tell button "Start" of window "main" to perform action
    quit
end tell

Jon

for the excellent help, I’ll check when I will be back at my Mac, hopefully tonight.

Cheers
Jochen