ScriptingBridge Finder POSIX path

Can I get the POSIX path or target in the very front window using the Bridge scripting platform?

I use

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

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

+4
source share
3 answers

It may be that 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); 
+4
source

Running reverse code through appscript The ASTranslate tool gives me the following:

 #import "FNGlue/FNGlue.h" FNApplication *finder = [FNApplication applicationWithName: @"Finder"]; FNReference *ref = [[[finder windows] at: 1] target]; FNGetCommand *cmd = [[ref get] requestedType: [ASConstant alias]]; id result = [cmd send]; 

The result will be an instance of ASAlias; use the [ASAlias] path to get the POSIX path.

You cannot do this in SB without resorting to raw Apple event codes, as this is one of the features that Apple engineers forgot / did not bother to put in SB less than the star API .

+2
source

I have not used ScriptingBridge. As part of NSAppleScript, this will be:

 get POSIX path of (target of window 1 as alias) 

Hope this helps. I think the POSIX part is the StandardAdditions ScriptingAddition application, not the Finder itself.

0
source

Source: https://habr.com/ru/post/1313246/


All Articles