Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

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?

share|improve this question
add comment

1 Answer

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

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
add comment

Your Answer

 
discard

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.