Launch app/wait 10/Quit app/wait 10/Launch app

Hi All,
Sorry for such a basic question but I’ve been trying to do this myself and have had no luck…

I have an app named “mongo”. I need to cycle a launch and quit of “mongo”…

in other words I need to:

Launch “mongo”
Wait 10 seconds
Quit “mongo”
Wait 10 seconds
Launch “mongo”

Can anyone help me? This seems so simple but I can’t make it work it’s driving me nuts.

Thanks,
Rob

Hello.

I think you would use Activity Monitor to stop the script. Please come back if there are any other issues.


repeat
	tell application "Mongo" to activate
	delay 10
	tell application "Mongo" to quit
	delay 10
end repeat

If you really want to get professional, you can use launchd.

Make your self this script and save it in your documents:

-- /Users/yourusername/Documents/relaunchDaemon.scpt
on run {appName}
    tell application "System Events" to set alreadyActive to (exists process appName)
    
    if alreadyActive is true then
        quit application appName
    else
        activate application appName
    end if
    
    return 0
end run

Than make yourself a property list file with the following contents:

And save it in “/Users/yourusername/Library/LaunchAgents/com.ief2.relaunchdaemon.plist” after you’ve made sure the path to the script is correct.

Now open terminal and run the following command:

launchctl load "~/Library/LaunchAgents/com.ief2.relaunchdaemon.plst"

Now the script should run every 10 seconds

Hope it works,
ief2

Wow, thanks for all your helpful advice! I truly appreciate it.
I have another question though… I really only need it to cycle 1 time. I intend to save the script as an application and run it on the hour using iCal.

Launch app
Wait 10
Quit app
Wait 10
Launch app
(then quit the script all together, leaving “mongo” running until iCal launches the applesciript app again)

I really don’t know how to modify your scripting language to accomplish this (im sorry, I thought it would be much more basic).

any additional help you might offer would be most warmly appreciated.

sincere thanks,
Rob

This is the script you need:

property APP_NAME : "Mango"
property DELAY_TIME : 10

activate application APP_NAME
delay DELAY_TIME
quit application APP_NAME
delay DELAY_TIME
activate application APP_NAME

Hope it helps,
ief2

Hello.

I’m not sure wether this will work, that is, if iCal is active the moment that the script is run, I can’t get you back any further. If however iCal is not active, then this should activate the previous frontmost application.

And It would be better to run it as a script, hopefully you can do that from iCal.


set frontApp to  getFrontApp() 

tell application "Mongo" to activate
delay 10
tell application frontApp to activate
  
on getFrontApp() -- Regulus6633/Hank and Nigel Garvey
	set colon to ":" as Unicode text
	set dot to "." as Unicode text
	set appPath to (path to frontmost application as Unicode text)
	considering case
		if (appPath ends with colon) then
			set n to -2
		else
			set n to -1
		end if
		set astid to AppleScript's text item delimiters
		set AppleScript's text item delimiters to colon
		set appname to text item n of appPath
		if (appname contains dot) then
			set AppleScript's text item delimiters to dot
			set appname to text 1 thru text item -2 of appname
		end if
		set AppleScript's text item delimiters to astid
	end considering
	
	return appname
end getFrontApp