Created
February 7, 2014 03:25
-
-
Save jonnyyu/8856992 to your computer and use it in GitHub Desktop.
check app is responding on Mac
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
| // | |
| // main.c | |
| // AppStatusChecker | |
| // | |
| // Created by Jonny Yu on 1/23/14. | |
| // Copyright (c) 2014 Jonny Yu. All rights reserved. | |
| // | |
| #include <CoreServices/CoreServices.h> | |
| #include <ApplicationServices/ApplicationServices.h> | |
| int main(int argc, const char * argv[]) | |
| { | |
| pid_t pid = 56377; | |
| OSStatus status = WaitForApplicationUIReady(56377, 5); | |
| if (status == noErr) { | |
| printf("UI Ready for Input\n"); | |
| } | |
| else { | |
| printf("UI not ready within time limit.\n"); | |
| } | |
| return 0; | |
| } | |
| OSStatus WaitForApplicationUIReady(pid_t pid, long timeoutInSeconds) | |
| { | |
| ProcessSerialNumber psn; | |
| OSStatus status = GetProcessForPID(pid, &psn); | |
| if (status != noErr) | |
| return status; | |
| status = SendAppleEventToPSN(&psn, kAENullEvent, timeoutInSeconds * 60); | |
| return status; | |
| } | |
| OSStatus SendAppleEventToPSN(ProcessSerialNumber * psn, AEEventID eventToSendID, long timeoutInTicks) { | |
| AEAddressDesc targetDesc; | |
| AppleEvent eventReply = {typeNull, NULL}; | |
| AppleEvent eventToSend = {typeNull, NULL}; | |
| OSStatus status = AECreateDesc(typeProcessSerialNumber, | |
| psn, sizeof(ProcessSerialNumber), &targetDesc); | |
| if (status != noErr) | |
| return status; | |
| status = AECreateAppleEvent(kCoreEventClass, eventToSendID, | |
| &targetDesc, kAutoGenerateReturnID, kAnyTransactionID, &eventToSend); | |
| AEDisposeDesc(&targetDesc); | |
| if (status != noErr) | |
| return status; | |
| status = AESendMessage(&eventToSend, &eventReply, kAEWaitReply, timeoutInTicks); | |
| AEDisposeDesc(&eventToSend); | |
| AEDisposeDesc(&eventReply); | |
| return status; | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment