有谁知道我如何从活动的查找器窗口中检索选定文件的列表?我对 AppleScript 完全没有经验,我们将不胜感激!
我尝试使用 SO 上另一个答案中的以下代码,但我可以让它返回任何东西。没有错误,没有结果,什么都没有。我知道即使它确实有效,也只会给我第一个文件,我需要完整的文件选择..
NSAppleScript *script = [[NSAppleScript alloc] initWithSource:
@"tell application \"Finder\"\n"
"set selectedItems to selection\n"
"if ((count of selectedItems) > 0) then\n"
"set selectedItem to (item 1 of selectedItems) as alias\n"
"container window of selectedItem\n"
"end if\n"
"end tell\n"];
if (script == nil) {
NSLog(@"failed to create script!");
}
NSAppleEventDescriptor *result = [script executeAndReturnError:&errorMessage];
if (result) {
// POSIX path returns trailing /'s, so standardize the path
NSString *path = [[result stringValue] stringByStandardizingPath];
}
for (id key in errorMessage) {
NSLog(@"key: %@, value: %@", key, [errorMessage objectForKey:key]);
}
编辑
我在执行脚本之前打印出错误字典,这就是没有错误的原因。这是我在查找器窗口中选择两个文件时得到的结果:
2013-07-23 13:36:14.817 myAPP[12959:303] key: NSAppleScriptErrorMessage, value: Finder got an error: Can’t get container window of document file "myAPP-logo-white-n-black.png" of folder "untitled folder" of folder "Desktop" of folder "Shumais" of folder "Users" of startup disk.
2013-07-23 13:36:14.817 myAPP[12959:303] key: NSAppleScriptErrorRange, value: NSRange: {151, 16}
2013-07-23 13:36:14.817 myAPP[12959:303] key: NSAppleScriptErrorBriefMessage, value: Can’t get container window of document file "myAPP-logo-white-n-black.png" of folder "untitled folder" of folder "Desktop" of folder "Shumais" of folder "Users" of startup disk.
2013-07-23 13:36:14.818 myAPP[12959:303] key: NSAppleScriptErrorNumber, value: -1728
2013-07-23 13:36:14.818 myAPP[12959:303] key: NSAppleScriptErrorAppName, value: Finder
谢谢你!舒迈斯