chemin ScriptingBridge Finder Posix
-
28-09-2019 - |
Question
est-il possible d'obtenir le chemin ou de la cible à la fenêtre Posix en utilisant le framework en avant le pont de script?
J'utilise
FinderApplication *theFinder = [SBApplication aplicationWithBundleIdentifier:@"com.apple.Finder";
mais je ne trouve rien dans « Finder.h » qui pourrait fonctionner.
La solution
Cela pourrait être ce que vous êtes après avoir utilisé ScriptingBridge et 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);
Autres conseils
L'exécution du code de drawnonward par outil de ASTranslate de appscript me donne ceci:
#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];
Le résultat sera une instance de ASAlias; utilisation -. [chemin ASAlias] pour obtenir le chemin POSIX
Vous ne pouvez pas le faire en SB à recourir à des codes d'événements d'Apple cru que c'est l'une des caractéristiques les ingénieurs d'Apple a oublié / ne pas la peine de mettre en SB moins API stellaire .
Je n'ai pas utilisé ScriptingBridge. il serait dans le cadre d'un NSAppleScript:
get POSIX path of (target of window 1 as alias)
Si tout va bien qui aide. Je pense que la partie est de la Posix StandardAdditions ScriptingAddition, pas le Finder lui-même.