Get Error when hitting cancel.

I have 3 scripts I saved at applications. The script below prompts the user to select which one to run.(I saved it as an application bundle, and added the 3 additional app’s to the contents of the bundle) When I select one, it starts running the application. The first thing the user needs to do in any of the 3 additional applications is type in their e-mail in a text field. When I run both below as script’s, it they work fine. When saved as applications, on the first script, If I hit cancel I get the following error:

set appChoice to choose from list {"SD", "HQ", "AE"}

repeat with anApp in appChoice
	
	try
		tell application (anApp as string) to activate
	on error number -1728 --user cancelled
		return
	end try
	
end repeat

Error:

Connection is invalid

Partial Script (where user needs to type in their address):

When saved as an application, the user cannot type in the box even though it appears.


set theText to "yourname@example.com"
tell application "Finder"
	display dialog "What is your e-mail address?" default answer theText
end tell
set myAddress to text returned of result
...

Any ideas?

So I have gotten a little further. The 3 apps will run properly, allowing the user to enter text into the text field if I click on each application individually. However, If I allow the use to choose from a list like the script above, I run into the problem I had before where they can’t type anymore. Is there any more efficient way to launch app’s from a list other then the way it is scripted above?

Instead of saving all the scripts as Applications save them as compiled scripts.
This is the more common way to add additional scripts to your main script
bundle. It will be faster as well.

Call the internal scripts like so

run script file "Path:to:script.scpt"

And to bring dialogs to the front always tell the app displaying them to activate…

Peter B.


I got the run script command to work as follows:

set appChoice to choose from list {"SD", "HQ", "AE"}

repeat with anApp in appChoice
	
	try
		run script file ((path to applications folder as text) & "myapp.app:" & "contents:" & "resources:" & "scripts:" & "HQ.scpt"	on error number -1728 --user cancelled
		return
	end try
	
end repeat

but this doesn’t tell which script to run based on the list. It only runs cause I specified which script to run manually. Does anyone know how I can adjust this so it work off the users selection.

Note: I apologize if this i going over my head. I normally write pretty simple scripts. I have never compiled script within scripts or worked with application bundles until now.

try this


set appChoice to choose from list {"SD", "HQ", "AE"} with multiple selections allowed
if appChoice is false then return
repeat with anApp in appChoice
	run script file ((path to applications folder as text) & "myapp.app:Contents:Resources:Scripts:" & anApp & ".scpt")
end repeat

That did it. Thanks as always Stefan.

Side note: I created an icon. It works fine. Can finder display icon’s without being in a dialog box? Or better yet, can it display it at different sizes? (128 x 128, 512 x 512, etc?)