Created
April 1, 2011 00:54
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
Author
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
Important note: My app can't properly initialise without
System Events.appactive, so it just needs to wait — I'm open to nicer ways to implement this. I thought about listening toNSWorkspacefor 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 forSystem Events.appto start (knowing the behaviour).