Skip to content

Instantly share code, notes, and snippets.

@tonyarnold
Created April 1, 2011 00:54
Show Gist options
  • Select an option

  • Save tonyarnold/897561 to your computer and use it in GitHub Desktop.

Select an option

Save tonyarnold/897561 to your computer and use it in GitHub Desktop.
So System Events is always available via the Scripting Bridge first thing on startup. This is nasty, but it works.
SomeClass *someObj = nil;
// This is a rude and nasty hack. Basically if someObj is nil, just keep checking until you get it.
while (someObj == nil) {
someObj = [AppDelegate sharedAppDelegate].somethingIWantFromSystemEvents;
if (someObj == nil) {
CBLog(@"Could not get a hold of the thing I wanted from System Events.app. Sleeping for 2 seconds before trying again.");
sleep(2);
}
}
// Shudder
@tonyarnold
Copy link
Author

Important note: My app can't properly initialise without System Events.app active, so it just needs to wait — I'm open to nicer ways to implement this. I thought about listening to NSWorkspace for app launches, but this would leave my app in an inconsistent state and the user confused as to why things don't work yet. I think it's better to wait the 2-3 seconds for System Events.app to start (knowing the behaviour).

@tonyarnold
Copy link
Author

Alternately I could write this part of my app properly in the first place, and present some form of indeterminate progress indicator to the user while it waits... Fridays are supposed to be easy, dammit!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment