«Connection is invalid» error message ...

Hi,

I have an application script named “Update Power Manager”. When double clicked from the finder it runs without any problem. I want to activate/run/launch/open it by script:


activate application "Update Power Manager" 

When trying to ACTIVATE the application script that way, it executes but ends with this error message: «Connection is invalid». I get the same result with RUN. With LAUNCH the script hangs.

What is the problem ?

Robert

What happens, if you use code like follows?


set apppath to ((path to applications folder) as Unicode text) & "iTunes.app"
set command to "open " & quoted form of POSIX path of apppath
do shell script command

hi,

I would definitively prefer a way by which Apple Script finds or asks to select the application file itself. The complete and actual path to my application script is:

“Macintosh HD:Applications:Scripts:En construction:Mise à jour Power Manager:Update Power Manager”.

I tried it with that path and it didn’t work.

Thanks for helping.

Robert

Are you sure that the path does not end with ‘Update Power Manager.app’?

Hi, Robert.

The «Connection is invalid» error usually means that an application’s disappeared while being sent a command. If your script’s a non-stay-open application, the problem’s something to do with it opening, doing its stuff, and then quitting without interacting properly with the calling script. (Sorry. I don’t know the exact details.)

You can ‘launch’ the application first, which loads it into memory without running it (and thus without it quitting afterwards). It’s then a sitting target for a ‘run’ command.

tell application "Update Power Manager"
	launch
	run
end tell

Better still, of course, if the application’s a script, would be to use ‘run script’. That’'ll be faster because the application itself won’t have to be launched:

run script file ((path to applications folder as text) & "Scripts:En construction:Mise à jour Power Manager:Update Power Manager.app")

Hi Nigel,

tell application "System Events" to exists process "Update Power Manager"
if result is false then
	tell application "Update Power Manager"
		launch
		run
	end tell
end if

Your advice fixed my problem, but obviously your comment reveals that there is still «a problem» with my script. Before, when the «activate» application script executed, the script quits and leaves a «Connection is invalid» error window open. With your script that does not happen anymore.

As for the «run script file» it is fast … very fast. So fast I thought that nothing had happen, until I looked carefully. Is there a way to use the «run script file» without having to specify the path ?

If you have time, I can send you my application script that has an error. Thanks for helping.

Regards.

Robert

The problem was that you were trying to treat an application script as an application rather than as a script. The application part is really only a mechanism for executing the script part. It’s not as sophisticated as software that’s written as an application in its own right. Running it or activating causes it to launch, execute the script it contains, and then quit (unless it’s been saved as a stay-open application). For some reason, this causes communication problems with the script issuing the ‘run’ or ‘activate’ command.

‘launch’ opens an application in memory, but doesn’t run it. This appears to give the two scripts a chance to communicate before the application one rushes for the exit.

You could instead tell the Finder to ‘open’ the application script file, or use the shell script “open” command, and it should execute with no problem.

But, unless there’s something about the application script you haven’t said, it’s possible that it doesn’t need to be an application at all. A simple compiled script should be enough if it’s to be run from another script.

‘run script’ is a StandardAdditions command. It’s fast here because OSAX commands are available for immediate use. This one reads the script component directly from the application script file and runs it, which saves having to start up the application itself for that purpose and quit it afterwards.

If you want to run a script that’s in a file, you have to specify how to find that file.

Hi Nigel,

Thank you for all those precisions and your time to help me. I think I should use basic scripts more often and less use application scripts.

Regards.

Robert