ScriptingBridge Finder Posixパス
-
28-09-2019 - |
質問
Scripting Bridge Frameworkを使用して、POSIXパスまたはターゲットを最前のウィンドウに取得することは可能ですか?
私は使用しています
FinderApplication *theFinder = [SBApplication aplicationWithBundleIdentifier:@"com.apple.Finder";
しかし、「Finder.H」には何も機能しません。
解決
これは、ScriptingBridgeと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);
他のヒント
drawnonwardのコードを実行します appscript's Astranslateツールは私にこれを与えてくれます:
#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];
結果はアサリアスのインスタンスになります。 [Asalias Path]を使用して、POSIXパスを取得します。
Appleエンジニアが忘れていた/SBに入れることを気にしなかった機能の1つであるため、Raw Appleイベントコードに頼ることができず、SBでそれを行うことはできません 恒星API未満.
Scriptingbridgeを使用していません。 nsapplescriptの一部として、それは次のとおりです。
get POSIX path of (target of window 1 as alias)
うまくいけばそれは助けになります。 POSIXの部分は、Finder自体ではなく、StandardAdditions ScriptingAdditionからのものだと思います。
所属していません StackOverflow