@nkuyu, I just saw your comment that you know how to run an applescript... but for others who don't (and might stumble onto this post) I'll explain.
It's easy to run an applescript from objc using NSApplescript. And if you return a string from your applescript it's even easier to get a result because you can get the "stringValue" from the NSAppleEventDescriptor. As such I return "posix paths" from the applescript. Note that NSApplescript is not thread-safe so in multi-threaded apps you must take care to always run it on the main thread. Try this...
-(IBAction)runApplescript:(id)sender {
[self performSelectorOnMainThread:@selector(getFrontFinderWindowTarget) withObject:nil waitUntilDone:NO];
}
-(void)getFrontFinderWindowTarget {
NSString* theTarget = nil;
NSString* cmd = @"tell application \"Finder\"\ntry\nset dir to the target of the front window\nreturn POSIX path of (dir as text)\non error\nreturn \"/\"\nend try\nend tell";
NSAppleScript* theScript = [[NSAppleScript alloc] initWithSource:cmd];
NSDictionary* errorDict = nil;
NSAppleEventDescriptor* result = [theScript executeAndReturnError:&errorDict];
[theScript release];
if (errorDict) {
theTarget = [NSString stringWithFormat:@"Error:%@ %@", [errorDict valueForKey:@"NSAppleScriptErrorNumber"], [errorDict valueForKey:@"NSAppleScriptErrorMessage"]];
} else {
theTarget = [result stringValue];
}
[self getFrontFinderWindowTargetResult:theTarget];
}
-(void)getFrontFinderWindowTargetResult:(NSString*)result {
NSLog(@"result: %@", result);
}