Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to show a progress bar on file's icon

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

I am wondering how to let it shown in Finder window when I'm copying or download files with my own code.

Could somebody help me?

Thanks a lot.

like image 469
YuDenzel Avatar asked Feb 22 '13 06:02

YuDenzel


People also ask

How can I tell if a file is downloading on a Mac?

Regardless of the browser, to verify, open finder, click the house icon on the left and double click downloads and see if the downloaded item is present. During the download there should appear an icon on top of the Downloads folder in the Dock; it, too, should display a progress bar.

How do I check airdrop progress?

Yes, you need to apply first in the upper left tab, under "Airdrop links". After you've been accepted, the "Check Status" page will have what you're looking for, though it only updates once per week during the "no move" period every Thursday. Glad to have you join us!


1 Answers

I got the way by query file/directory attributes myself. It's quit simple.

Get attributes of the file you want to show a progress bar on it's icon

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

Get extend 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 mutable 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];

Now you'll find it the progress bar showed up.

like image 82
YuDenzel Avatar answered Nov 15 '22 08:11

YuDenzel