Search code examples
objective-cfinderscripting-bridge

ScriptingBridge Finder POSIX path


is it possible to get the POSIX path or target to the frontmost window using the Scripting Bridge framework?

I'm using

FinderApplication *theFinder = [SBApplication aplicationWithBundleIdentifier:@"com.apple.Finder";

but I can't find anything in "Finder.h" that could work.


Solution

  • This might be what you are after using ScriptingBridge and NSURL

    FinderApplication *finder = [SBApplication applicationWithBundleIdentifier:@"com.apple.finder"];
    
    SBElementArray *windows =  [finder windows ]; // array of finder windows
    NSArray *targetArray = [windows arrayByApplyingSelector:@selector(target)];// array of targets of the windows
    
    //gets the first object from the targetArray,gets its URL, and converts it to a posix path
    NSString * newURLString =   [[NSURL URLWithString: (id) [[targetArray   objectAtIndex:0]URL]] path];
    
    NSLog(@"newURLString   %@  ", newURLString);