I am trying to open a video file with Quicktime and then close it. The video file is opening fine with [NSWorkspase openfile:path withapplication:@"Quick Time Player"]
. But when I am trying to close the Quicktime window nothing happens. Here is the code.
NSMutableArray *titles = [[NSApplication sharedApplication] orderedWindows];
int i;
id obj;
NSMutableString *mystring;
for(i=0; i< [titles count]; i++)
{
obj = (NSWindow*)[titles objectAtIndex:i];
mystring = [obj title];
if([mystring isEqualToString:@"PREVIEW"] == 1 )
{
[obj close];
}
//NSLog("Title : %@\n",(NSString*)[obj title]);
}
I would be obliged if any one could help me out.
This won’t work because orderedWindows
returns only the windows from your application. There is no way to access a NSWindow
object from another application like QuickTime Player.
To do this you’ll have to use AppleEvents. There are many different ways to send them, but the easiest probably would be ScriptingBridge. Here is a pretty good tutorial.