3

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"
            run
        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?

1

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
    target:self
    selector:@selector(targetMethod:)
    userInfo:nil
    repeats:NO];

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

  • 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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .