Optimize Code | Dialog Boxes/Error Messages ? | Script Launches 2 apps

First off this is my first AppleScript code. I have done some scripting in MATLAB before, so yeah . . . that is all.

Now, here is my code. it is designed to check to see if Azuresus and shakespeer are open, if they are not the script launches them and tells the user of this.

tell application "System Events"
	set az to ((name of processes) contains "azureus")
	set sp to ((name of processes) contains "shakespeer")
end tell
if az is false then
	display dialog ("Pedro is launching Azureus.")
	launch application "Azureus"
else
	display dialog ("Azureus is already running.")
end if
if sp is false then
	display dialog ("Pedro is launching Shakespeer.")
	launch application "ShakesPeer"
else
	display dialog ("Shakespeer is already running.")
end if

How may I optimize this code? Make it more efficient, smaller, etc? Should I have any error messages? The code seems simple enough to not require any error messages.

Comments? Etc?

Thanks!

EDIT: FIxed. this is only for two apps, not three.

I’m not really sure why your using variables and all that dialog nonsense… I also have no idea what “dtella” is and I can only imagine “shakespeer” is some P2P client, but this should do the trick.

EDIT: You know, I’m gonna have to say your pretty lazy if you can’t just put the 3 applications in your dock and click them… This is hardly worth scripting. :confused:

tell application "System Events"
	if process "azureus" exists then
		activate application "dtella"
	else
		activate application "Azureus"
		activate application "dtella"
	end if
	if process "shakespeer" exists then
		--do nothing
	else
		activate application "shakespeer"
	end if
end tell

The “variables and all that nonsense” were just my inexperience showing through. The script was only supposed to be for Azureus and Shakespeer.

I like having an uncluttered dock; I’d rather have one icon icon in the dock (the script) than have two all the time. Now yes I understand that I’d end up having three icons in the dock when I am using both programs, but this way when not using those programs my dock is uncluttered.

I really don’t appreciate you calling me lazy. Isn’t the whole purpose of programming/coding/scripting to simplify one thing or the other?

EDIT: yeah, I just tried your way and it was slower than my way with all my “nonsense”. With both applications already running my way took two seconds for the script to run; on the other hand, your way took a total of twelve seconds for your script to run.

Note: these times are approximate.

Obviously somethings wrong if it took system events 12 seconds to run 2 if then statements. :wink:

EDIT: If dtella is not needed, then use this instead.

tell application "System Events"
	if process "azureus" exists then
		--do nothing
	else
		activate application "Azureus"
	end if
	if process "shakespeer" exists then
		--do nothing
	else
		activate application "shakespeer"
	end if
end tell

EDIT2: I’m curious to know why you need two P2P clients running at the same time.

And it’s not just two if then statements . . . =-P Well I have azurues on virtually all the time, as ratio stuffs. And I chat with Shakespeer.

Out of curiosity, why do you use activate instead of launch?

Try running the script on your mac with two programs that you have open, just to see if it’s not a localized issue. eh?

sigh Yes, it is just “two”, count them “two” if then else statements… lol

if something then do something else do something end if
That chunk is called an if then else statement. End of story. There are two of them in the script I provided you with. I use activate because it starts and brings the application(s) in question to the front. Launch leaves them in the backround.

Also, the script works perfectly… I have no idea what you did, but I can swap out “Azurues” and “Shakespeer” for “Adium” and “Camino” both of which are already running, and then run the script and it is active for less than a second and stops because both processes are already active… I honestly have no idea why you would be having issues with it.

There’s no need to patronize me, I know what an if then statement is. And I was alluding to the tell statement.

You two are funny!

here’s smaller…

tell application "System Events"
	if not (exists process "Azureus") then launch application "Azureus"
if not (exists process "ShakesPeer") then launch application "ShakesPeer"
end tell

launch: launches an application
activate: launches an application and brings it to the front