| Index | Submit class | Submit snippet | Submission feed | List |

NSWorkspace (BSInvisibility)

Language: Objective-C, Author: Michele Balistreri
License: Public domain

This category to NSWorkspace adds the method “isInvisibleFileAtPath:” which checks wether the file at a given path is invisible or not. On Mac OS X there are many ways of making a file invisible, this method will check all, and has some hardcoded paths, it reflects visibility in Finder.app.

NSWorkspace (BSInvisibility) source preview

#import "NSWorkspace+BSInvisibility.h"


@implementation NSWorkspace (BSInvisibility)

- (BOOL)isInvisibleFileAtPath:(NSString *)path
{
  BOOL isHidden = NO; 
  
  LSItemInfoRecord itemInfo;
  LSCopyItemInfoForURL((CFURLRef)[NSURL URLWithString:path], kLSRequestAllFlags, &itemInfo);
  isHidden |= (itemInfo.flags & kLSItemInfoIsInvisible);
  
  FSRef possibleInvisibleFile; 
  FSCatalogInfo catalogInfo;
  FSPathMakeRef((unsigned const char *)[path fileSystemRepresentation], &possibleInvisibleFile, nil); 
  FSGetCatalogInfo(&possibleInvisibleFile, kFSCatInfoFinderInfo, &catalogInfo,  nil, nil, nil); 
  isHidden |= (((FileInfo*)catalogInfo.finderInfo)->finderFlags & kIsInvisible) ? 1 : 0;
  
  isHidden |= [path isEqualToString:@"/Network"];
  isHidden |= [path isEqualToString:@"/mach"];
  isHidden |= [path isEqualToString:@"/mach.sym"];
  isHidden |= [path isEqualToString:@"/dev"];
  
  return isHidden;
}

@end

NSWorkspace (BSInvisibility) header preview

#import <Cocoa/Cocoa.h>
#include <sys/param.h>
#include <sys/mount.h>

@interface NSWorkspace (BSInvisibility)

- (BOOL)isInvisibleFileAtPath:(NSString *)path;

@end
Download Archive

Compatible with:


Comments

Jordy/Jediknil says:

Nice! But, shouldn't you #import <ApplicationServices/ApplicationServices.h> for LaunchServices? It's only incidental that NSWindow.h imports this.

It's probably OK to assume that ApplicationServices imports CoreServices since it's in the main header file.

Michele Balistreri says:

Here i do not get any compilation warning, so i don't think it is necessary.

Fairly says:

The last five lines of your code beginning with "isHidden" are wasteful.

Michele Balistreri says:

Unfortunately they aren't (at least not on all versions of Mac OS X) because when I tested it those path didn't report to be invisible so I had to hardcode them.

Name

Website

Do you hate spammers? (Answer "Yes")