-
Notifications
You must be signed in to change notification settings - Fork 0
/
FinderRemoveEmptyDirsPatch.m
47 lines (34 loc) · 1.6 KB
/
FinderRemoveEmptyDirsPatch.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
//
// FinderRemoveEmptyDirsPatch.m
// FinderPatch
//
// Created by toy on 03.02.11.
// Copyright 2011 __MyCompanyName__. All rights reserved.
//
#import "FinderRemoveEmptyDirsPatch.h"
@implementation FinderRemoveEmptyDirsPatch
+ (void) loadPatch {
NSString *keyEquivalent = @"\b";
NSUInteger modifierMask = NSCommandKeyMask | NSAlternateKeyMask;
[self shiftItemWithKeyEquivalent:keyEquivalent andModifierMask:modifierMask];
NSMenuItem *removeEmptyDirsItem = [[self patchMenu] addItemWithTitle:@"Remove Empty Dirs" action:@selector(cmdRemoveEmptyDirs:) keyEquivalent:keyEquivalent];
[removeEmptyDirsItem setKeyEquivalentModifierMask:modifierMask];
[removeEmptyDirsItem setTarget:self];
}
+ (void) cmdRemoveEmptyDirs:(id)sender {
[self performSelectorInBackground:@selector(cmdRemoveEmptyDirsAsynchronyously:) withObject:sender];
}
+ (void) cmdRemoveEmptyDirsAsynchronyously:(id)sender {
id pool = [[NSAutoreleasePool alloc] init];
FNApplication *finder = [FNApplication applicationWithName:@"Finder"];
NSArray *selectedPaths = [self refPaths:[finder selection]];
NSMutableArray *arguments = [NSMutableArray arrayWithObject:@"find"];
[arguments addObjectsFromArray:selectedPaths];
[arguments addObjectsFromArray:[@"-depth ( -name .DS_Store -or -type d -empty ) -delete" componentsSeparatedByString:@" "]];
[[NSTask launchedTaskWithLaunchPath:@"/usr/bin/env" arguments:arguments] waitUntilExit];
arguments = [NSMutableArray arrayWithObject:@"rmdir"];
[arguments addObjectsFromArray:selectedPaths];
[[NSTask launchedTaskWithLaunchPath:@"/usr/bin/env" arguments:arguments] waitUntilExit];
[pool release];
}
@end