Ask Different is a question and answer site for power users of Apple hardware and software. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have an application for mac and I use the following applescript code (exported as an AS app) to start that app periodically:

on idle
    tell application "System Events"
        tell application "MyApp"
        end tell
        return 7
    end tell
end idle

I use [NSApp terminate:self] in MyApp to terminate itself after it finished its work.

The problems is that the AS script displays a "Connection is invalid" error message when it tries to run MyApp the second time and onward. The error does not show up in the first launch.

I'm guessing [NSApp terminate:self] is causing the conflict with the AS somehow, but why?

share|improve this question
up vote 1 down vote accepted

In the end I used NSTimer to automate my code.

Rather then using the applescript to launch the app periodically, I have the app run constantly and use NSTimer within my app to fire a specific method from time to time.

[NSTimer scheduledTimerWithTimeInterval:2.0

This way the app is never killed and does not have to be restarted.

share|improve this answer
Could you give some more info on how you solved your problem for future reference? – Gerry Oct 9 '12 at 11:38
Sure, I edited my answer. – Zoltán Matók Oct 9 '12 at 13:04

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.