-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathpbcopy.m
28 lines (24 loc) · 1.06 KB
/
pbcopy.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
#import <UIKit/UIKit.h>
#import <MobileCoreServices/MobileCoreServices.h>
int pbcopy(NSString *pasteboardType) {
NSFileHandle *input = [NSFileHandle fileHandleWithStandardInput];
NSData *inputData = [NSData dataWithData:[input readDataToEndOfFile]];
if (!pasteboardType)
pasteboardType = (NSString *)kUTTypeText;
[[UIPasteboard generalPasteboard] setData:inputData forPasteboardType:pasteboardType];
return !inputData;
}
int main(int argc, char **argv, char **envp) {
@autoreleasepool {
if (argc > 1) {
if (strcmp(argv[1], "-help") == 0 || strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-h") == 0) {
printf("Usage: %s [-help | public.pasteboard-type ]\n%s takes the standard input and places it in the clipboard. Optionally, the pasteboard type of the input may be specified.\n", argv[0], argv[0]);
return 0;
} else {
return pbcopy([NSString stringWithUTF8String:argv[1]]);
}
} else {
return pbcopy(nil);
}
}
}