Mac 命令行安装Chrome插件

1. 在终端调用命令行实现Chrome插件安装

/Applications/Google\Chrome.app/Contents/MacOS/Google\ Chrome --enable-easy-off-store-extension-install extensionPath
其中extensionPath是指的插件文件位置(Chrome插件文件的后缀名是crx),例如~/Desktop/chromeExtension.crx

注意:安装插件之前要确保Chrome浏览器不在运行

2. 通过代码实现Chrome插件安装


  1. - (void)startInstallChromeExtension {  
  2.     NSURL *url = [[NSWorkspace sharedWorkspace] URLForApplicationWithBundleIdentifier:@"com.google.Chrome"];  
  3.     if (url) {  
  4.         NSString *chromeExtensionPath = [[NSBundle mainBundle] pathForResource:EXTENSIONSOURCENAME ofType:@"crx" inDirectory:EXTENSIONDIRNAME];  
  5.         NSDictionary *configuration = [NSDictionary dictionaryWithObjectsAndKeys:  
  6.                                        [NSArray arrayWithObjects:@"--enable-easy-off-store-extension-install",chromeExtensionPath,nil],NSWorkspaceLaunchConfigurationArguments, nil];  
  7.           
  8.         [[NSWorkspace sharedWorkspace] launchApplicationAtURL:url  
  9.                                                       options:NSWorkspaceLaunchDefault  
  10.                                                 configuration:configuration error:nil];  
  11.           
  12.     }  
  13. }  
  14.   
  15. - (IBAction)installChromeExtension:(id)sender {  
  16.     NSArray *runningChromes = [NSRunningApplication runningApplicationsWithBundleIdentifier:@"com.google.Chrome"];  
  17.     if ([runningChromes count] > 0) {  
  18.         NSAlert * alert = [NSAlert alertWithMessageText:NSLocalizedString(@"安装Chrome插件,需要关闭正在运行的Chrome浏览器,是否允许?", @"")  
  19.                                           defaultButton:NSLocalizedString(@"OK", @"")  
  20.                                         alternateButton:NSLocalizedString(@"Cancel", @"")  
  21.                                             otherButton:nil  
  22.                               informativeTextWithFormat:@""];  
  23.           
  24.         NSInteger result = [alert runModal];  
  25.           
  26.         if (result == NSAlertDefaultReturn ) {  
  27.             for (int i = 0; i < [runningChromes count]; i++) {  
  28.                 [(NSRunningApplication *)[runningChromes objectAtIndex:i] forceTerminate];  
  29.             }  
  30.             [self performSelector:@selector(startInstallChromeExtension) withObject:nil afterDelay:0.5];  
  31.         }  
  32.     }  
  33.     else {  
  34.         [self performSelector:@selector(startInstallChromeExtension) withObject:nil afterDelay:0.5];  
  35.     }  
  36. }  


源引:http://blog.csdn.net/lexiaoyao20/article/details/10406143
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值