//message= TextEdit:f
NSString *string = message;
// split the text by the : to get an array containing { “AAA”, “BBB” }
NSArray *splitText = [string componentsSeparatedByString:@”:”];

// form a new string of the form “BBB AAA” by using the individual entries in the array
NSString *cellText = [NSString stringWithFormat:@”%@ %@”, [splitText objectAtIndex:1], [splitText objectAtIndex:0]];

NSString *cmdKey = [NSString stringWithFormat:@”%@”, [splitText objectAtIndex:1]];
NSString *app = [NSString stringWithFormat:@”%@”, [splitText objectAtIndex:0]];

textView.string = message ;

//run and activate application
NSString *script = [ NSString stringWithFormat:@”tell application \”%@\” to run”,app];
NSAppleScript *run = [[NSAppleScript alloc] initWithSource:script ];
[run executeAndReturnError:nil];

NSString *script1 = [ NSString stringWithFormat:@”tell application \”%@\” to activate”,app];

NSAppleScript *run1 = [[NSAppleScript alloc] initWithSource:script1 ];
[run1 executeAndReturnError:nil];
NSString *cmd = [NSString stringWithFormat:@”tell application \”System Events\” to keystroke \”%@\” using command down”, cmdKey];
NSAppleScript *playScript;
playScript = [[NSAppleScript alloc] initWithSource:cmd];

if([playScript isCompiled] == NO){
[playScript compileAndReturnError:nil];

id exerror = [playScript executeAndReturnError:nil];

if(exerror == nil){
NSLog(@”Script Failed”);

NSLog(@”keystorke should be execute”);