Search code examples
macoscocoafinder

Check Finder Activity


Is there any way I can check (programatically) if finder is busy e.g. copying files? I don't want to check it at file level; I just want to know in general if finder is busy copying.

I think it's not possible, but it is always worth giving it a shot here :)


Solution

  • Unfortunately Apple does not provide any method to retrieve this kind of information.
    However, there are some 'dirty' ways that might work, for example using AppleScript.

    The following script detects wether the 'copy window' by Finder is active or not:
    (Quickly written and not thoroughly tested, but seems to be working great.)

    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
    

    Finally use NSAppleScript to run this AppleScript from 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");
    }