すべてのOSXアプリケーションをワンタッチでバックアップ

2090 ワード

すべての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:@"
"]; 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 ..
zip -9 -ry '%@' '%@/'",app, zip, [app lastPathComponent]]; //NSString *cmd = [NSString stringWithFormat:@"tar -zcvf '%@' -C '%@/'", zip, app]; [sh appendFormat:@"%@
", 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 ..... }