首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >检查Finder活动

检查Finder活动
EN

Stack Overflow用户
提问于 2011-10-28 03:37:47
回答 1查看 321关注 0票数 0

有没有什么方法可以检查finder是否在忙,比如复制文件?我不想在文件级别检查它;我只想知道一般情况下finder是否正在忙于复制。

我认为这是不可能的,但在这里总是值得一试的:)

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-10-28 06:51:13

不幸的是,Apple没有提供任何方法来检索这类信息。

然而,有一些“脏”的方法可能会起作用,例如使用AppleScript。

以下脚本检测Finder的“复制窗口”是否处于活动状态:

(编写速度很快,没有经过彻底的测试,但似乎工作得很好。)

代码语言:javascript
复制
set thestatus to "not copying"
tell application "System Events"
    set theList to get the title of every window of process "Finder"
    repeat with theItem in theList
        if theItem contains "Copy" then
            set thestatus to "copying"
        end if
    end repeat
end tell
thestatus

最后,使用NSAppleScript从Objective-C运行此AppleScript

代码语言:javascript
复制
NSString *theScript = @"set theStatus to \"not copying\"\n"
"tell application \"System Events\"\n"
"set theList to get the title of every window of process \"Finder\"\n"
"repeat with theItem in theList\n"
"if theItem contains \"Copy\" then\n"
"set theStatus to \"copying\"\n"
"end if\n"
"end repeat\n"
"end tell\n"
"theStatus";

NSDictionary *errorInfo = nil;
NSAppleScript *run = [[NSAppleScript alloc] initWithSource:theScript];
NSAppleEventDescriptor *theDescriptor = [run executeAndReturnError:&errorInfo];

if ([[theDescriptor stringValue] isEqualTo:@"copying"]) {
    NSLog(@"Finder is copying");
} else {
    NSLog(@"Finder is not copying");
}
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/7921378

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档