Here is the corresponding AppleScript that you want to run:
property timeScale : 600 set currentPosition to missing value tell application "QuickTime Player" set currentPosition to (current time of document 1) / timeScale end tell return currentPosition
If you are not familiar with it, property is a way to specify a global variable in AppleScript. In addition, the missing value is the equivalent of AppleScript nil in Objective-C. So this script first defines a variable called currentPosition and sets the value to missing value . He then enters the tell block, which, if successful, will change the currentPosition variable. Then, outside the tell block, it returns the currentPosition variable.
In Objective-C code, when creating an NSAppleScript with the above code, its -executeAndReturnError: method returns the currentPosition variable in NSAppleScriptEventDescriptor .
-(IBAction)currentPlayTime:(id)sender { NSDictionary *error = nil; NSMutableString *scriptText = [NSMutableString stringWithString:@"property timeScale : 600\n"]; [scriptText appendString:@"set currentPosition to missing value\n"]; [scriptText appendString:@"tell application \"QuickTime Player\"\n "]; [scriptText appendString:@"set currentPosition to (current time of document 1) / timeScale\n"]; [scriptText appendString:@"end tell\n"]; [scriptText appendString:@"return currentPosition\n"]; NSAppleScript *script = [[[NSAppleScript alloc] initWithSource:scriptText] autorelease]; NSAppleEventDescriptor *result = [script executeAndReturnError:&error]; NSLog(@"result == %@", result); DescType descriptorType = [result descriptorType]; NSLog(@"descriptorType == %@", NSFileTypeForHFSTypeCode(descriptorType));
You can extract the contents of NSAppleEventDescriptor as shown above.
Using the Bridge scripting infrastructure has a slight learning curve, but will allow you to work with native types such as NSNumber , instead of taking the somewhat dirty path of extracting raw bytes from the AppleEvent descriptor.
NSGod
source share