MacOS – Hide all files of the same extension in Finder

file extensionsfindermacos

I need to hide all files with .pek extension on Finder (macOS Sierra) automatically.

Best Answer

OK I've changed the Peter Hosey's fs-notifier, so that it will set the newly created .pak files hidden. You will need Xcode for the compilation.

Please change those lines in his code:

In Notifier.m change 25th line to:

 stream = FSEventStreamCreate(kCFAllocatorDefault, newCallback, &context, (CFArrayRef)paths, kFSEventStreamEventIdSinceNow, /*latency*/ 1.0, kFSEventStreamCreateFlagUseCFTypes | kFSEventStreamCreateFlagFileEvents);`

In fs-notifier.m file change the whole body of the gotEvent fuction (lines 34+) to:

NSArray *eventPaths = eventPathsVoidPointer;
if (*eventFlags | kFSEventStreamCreateFlagFileEvents) {
    NSURL *fileUrl = [[NSURL alloc] initWithString:[@"file://" stringByAppendingString:[eventPaths objectAtIndex:0UL]]];
    if ([fileUrl.pathExtension isEqualToString:@"pak"]) {
        [fileUrl setResourceValue:@YES forKey:NSURLIsHiddenKey error:nil];
    }
}

Note: In order to compile the sources you might need to set the 64bit architecture.

After the compilaton you'll launch the program with the path to the directory you want to monitor.

I've tested it and it works, however I don't know what's the impact on the system.

Edit: To hide .pak files already created, run this command:

find -x /path/to/folder -name \*.pak -exec chflags hidden {} +

Answer from superuser.