Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xcode console, clear screen programmatically

Tags:

xcode

I'm kinda new to Xcode and even programming.

From Xcode, in my code, how do I show the console and clear the screen?

I know I could do it with the Xcode preferences, but I would like to do it programmatically.

like image 255
stone Avatar asked Oct 13 '22 23:10

stone


1 Answers

This works for me - leave out the last activate part if you wish Xcode to stay on top of your app:

bool ClearXCodeDebuggerConsole()
{
    NSString *const scriptText = @"\
tell application \"System Events\"\n\
set currentapp to the name of the current application\n\
end tell\n\
tell application \"Xcode\" to activate\n\
tell application \"System Events\"\n\
keystroke \"r\" using {command down, control down, option down}\n\
end tell\n\
tell application currentapp to activate\n\
return true";

    NSAppleScript *script = [[[NSAppleScript alloc] initWithSource:scriptText] autorelease];
    [scriptText release];
    NSDictionary *dictError = nil;
    NSAppleEventDescriptor *result = [script executeAndReturnError:&dictError];

    if (!result) return false;
    if ([result booleanValue] != YES) return false;
    return true;
}
like image 132
Aidan Avatar answered Oct 19 '22 01:10

Aidan