一键备份所有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 .....
}