-
Notifications
You must be signed in to change notification settings - Fork 12
/
NSPasteboard+Files.m
executable file
·52 lines (45 loc) · 1.88 KB
/
NSPasteboard+Files.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
48
49
50
51
52
//
// NSPasteboard+Files.m
// Kickoff
//
// Created by Michael Villar on 7/6/11.
//
#import "NSPasteboard+Files.h"
///////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////
@implementation NSPasteboard (Files)
///////////////////////////////////////////////////////////////////////////////////////////////////
- (NSArray*)filesRepresentation {
NSString *type = [self availableTypeFromArray:
[NSArray arrayWithObjects:
NSFilenamesPboardType,NSTIFFPboardType,
NSPasteboardTypeTIFF,NSPasteboardTypePNG,nil]];
NSMutableArray *files = [NSMutableArray array];
if(!type)
return files;
NSData *data = [self dataForType:type];
if(type == NSTIFFPboardType || type == NSPasteboardTypeTIFF || type == NSPasteboardTypePNG) {
NSDateFormatter* formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"yyyy-MM-dd-HH-mm-ss"];
NSString *path = [NSString stringWithFormat:@"/tmp/image-%@.png",
[formatter stringFromDate:[NSDate date]]];
[formatter release];
NSData *imageRepresentation = [[NSBitmapImageRep imageRepWithData:data]
representationUsingType:NSPNGFileType
properties:nil];
[imageRepresentation writeToFile:path atomically:YES];
[files addObject:path];
}
else if(type == NSFilenamesPboardType) {
NSString* errorDescription;
files = [NSPropertyListSerialization propertyListFromData:data
mutabilityOption:kCFPropertyListImmutable
format:nil
errorDescription:&errorDescription];
}
if(!files)
return [NSArray array];
return files;
}
@end