Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion chrome-cli/App.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,5 @@ typedef enum {
- (void)printSourceFromTab:(Arguments *)args;
- (void)printChromeVersion:(Arguments *)args;
- (void)printVersion:(Arguments *)args;

- (void)listProfiles:(Arguments *)args;
@end
39 changes: 39 additions & 0 deletions chrome-cli/App.m
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,33 @@ - (id)initWithBundleIdentifier:(NSString *)bundleIdentifier outputFormat:(Output
return self;
}

- (NSArray *)getProfiles {
NSString *homeDir = NSHomeDirectory();
NSString *profilesPath = [homeDir stringByAppendingPathComponent:@"Library/Application Support/Google/Chrome"];

NSError *error = nil;
NSFileManager *fileManager = [NSFileManager defaultManager];

NSArray *contents = [fileManager contentsOfDirectoryAtPath:profilesPath error:&error];
if (error) {
return @[];
}

NSMutableArray *profiles = [NSMutableArray array];

for (NSString *item in contents) {
if ([item isEqualToString:@"Default"] || [item hasPrefix:@"Profile"]) {
NSString *prefsPath = [profilesPath stringByAppendingPathComponent:
[item stringByAppendingPathComponent:@"Preferences"]];

if ([fileManager fileExistsAtPath:prefsPath]) {
[profiles addObject:item];
}
}
}

return profiles;
}

- (chromeApplication *)chrome {
chromeApplication *chrome = [SBApplication applicationWithBundleIdentifier:self->bundleIdentifier];
Expand Down Expand Up @@ -762,4 +789,16 @@ - (NSJSONWritingOptions)jsonWritingOptions {
return NSJSONWritingPrettyPrinted;
}

- (void)listProfiles:(Arguments *)args {
NSArray *profiles = [self getProfiles];

if (self->outputFormat == kOutputFormatJSON) {
[self printJSON:@{@"profiles": profiles}];
} else {
for (NSString *profile in profiles) {
printf("Profile Directory: %s\n", profile.UTF8String);
}
}
}

@end
2 changes: 2 additions & 0 deletions chrome-cli/main.m
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ int main(int argc, const char * argv[])

[argonaut add:@"execute <javascript>" target:app action:@selector(executeJavascriptInActiveTab:) description:@"Execute javascript in active tab"];
[argonaut add:@"execute <javascript> -t <id>" target:app action:@selector(executeJavascriptInTab:) description:@"Execute javascript in specific tab"];

[argonaut add:@"list profiles" target:app action:@selector(listProfiles:) description:@"List Chrome profiles"];

[argonaut add:@"chrome version" target:app action:@selector(printChromeVersion:) description:@"Print Chrome version"];
[argonaut add:@"version" target:app action:@selector(printVersion:) description:@"Print application version"];
Expand Down