Applescript - Connection is invalid

Solution 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.