如果查找程序忙,我有什么方法可以检查(以编程方式),例如复制文件?我不想在文件级别检查它;我只是想知道finder是否忙于复制。
我认为这是不可能的,但总是值得在这里试一试:)
答案 0 :(得分:2)
不幸的是,Apple没有提供任何方法来检索此类信息 但是,有一些“脏”的方法可能会起作用,例如使用AppleScript。
以下脚本检测到Finder的“复制窗口”是否处于活动状态:
(快速编写并未经过全面测试,但似乎效果很好。)
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
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");
}