How to show progress bar on file icon

You know that there is a mini progress bar on the file icon when we copy a file or load a file with safari and chrome.

I am wondering how to show this in the Finder window when I copy or upload files using my own code.

Can someone help me?

Thank you very much.

+4
source share
2 answers

I myself got the path to the attributes of the request file / directory. It's simple.

Get the attributes of the file you want to show the progress bar on the icon

NSDictionary *fileAttr = [[NSFileManager defaultManager] attributesOfItemAtPath:filePath error:nil]; 

Get extension attributes

 NSDictionary *extendAttr = [fileAttr objectForKey:@"NSFileExtendedAttributes"]; 

Create a Mutable copy of extendAttr and change some value in it

 NSMutableDictionary *mutableExtendAttr = [NSMutableDictionary dictionaryWithDictionary:extendAttr]; // create data of progress value NSData *progressData = [@"0.1" dataUsingEncoding:NSASCIIStringEncoding]; // change it [mutableExtendAttr setObject:progressData forKey:@"com.apple.progress.fractionCompleted"]; 

Create a modified copy of FileAttr

  NSMutableDictionary *mutableFileAttr = [NSMutableDictionary dictionaryWithDictionary:fileAttr]; // change extend attr [mutableFileAttr setObject:[NSDictionary dictionaryWithDictionary:mutableExtendAttr] forKey:extendAttrKey]; // change file/dir create date to the special one // if not , progress bar will not show [mutableFileAttr setObject:[NSDate dateWithString:@"1984-01-24 08:00:00 +0000"] forKey:NSFileCreationDate]; // set attribute to file [[NSFileManager defaultManager] setAttributes:mutableFileAttr ofItemAtPath:filePath error:&error]; 

You will now see a progress bar appear.

+11
source

One starting point will be the use of NSProgressIndicator , then [progressIndicator setIndeterminate:NO]; . Your update / background operation should not block the main thread. NSProgressIndicator slightly different for the AppKit widget - it allows you to receive some updates from secondary streams. Of course, โ€œcurrent progressโ€ updates can also be installed in the main thread loop.

0
source

All Articles