美文网首页
一键备份所有OSX应用

一键备份所有OSX应用

作者: sma11case | 来源:发表于2016-03-24 10:44 被阅读73次

    一键备份所有OSX应用,需要一个外部库sma11case(点此下载)

    + (void)backupMyApps
    {
        NSMutableString *sh = NewMutableString();
        
        // backup to ...
        NSString *save = @"/Users/sma11case/Desktop/sma11case/appsss";
        
        // apps folder
        [CoreTools executeCommand:@"find '/Users/sma11case/Desktop/sma11case/app' -name \"Info.plist\" > /tmp/apps.txt" waitFinished:YES];
        
        NSString *list = [NSString stringWithContentsOfFile:@"/tmp/apps.txt" encoding:NSUTF8StringEncoding error:NULL];
        
        NSArray *apps = [list componentsSeparatedByString:@"\n"];
        
        for (NSString *plist in apps)
        {
            if (NO == [plist regexpCheck:@"/app/[^/]+\\.app/Contents/Info\\.plist$"]) continue;
            
            NSDictionary *info = [NSDictionary dictionaryWithContentsOfFile:plist];
            
            NSString *app = [plist regexpReplace:@"/Contents/Info\\.plist$" replace:@""];
            
            NSString *appName = info[@"CFBundleName"];
            
            NSString *version = info[@"CFBundleShortVersionString"];
            if (nil == version) version = info[@"CFBundleVersion"];
            
            NSString *zip = [NSString stringWithFormat:@"%@/%@_v%@.zip", save, appName, version];
            
            if ([NSFM fileExistsAtPath:zip]) continue;
            
            NSString *cmd = [NSString stringWithFormat:@"cd '%@' && cd ..\nzip -9 -ry '%@' '%@/'",app, zip, [app lastPathComponent]];
            //NSString *cmd = [NSString stringWithFormat:@"tar -zcvf '%@' -C '%@/'", zip, app];
            
            [sh appendFormat:@"%@\n", cmd];
            
            BreakPointHere;
        }
        
        [sh writeToFile:@"/tmp/backupApps.sh" atomically:YES encoding:NSUTF8StringEncoding error:NULL];
        
        {
            [CoreTools executeCommand:@"chmod 777 '/tmp/backupApps.sh'" waitFinished:YES];
        }
        
        // execute /tmp/backupApps.sh .....
    }
    

    相关文章

      网友评论

          本文标题:一键备份所有OSX应用

          本文链接:https://www.haomeiwen.com/subject/kgrrlttx.html