代码之家  ›  专栏  ›  技术社区  ›  Lyndsey Ferguson

如何制作一个脚本,让非技术Mac用户通过双击下载并运行?

  •  0
  • Lyndsey Ferguson  · 技术社区  · 6 年前

    我想做一个脚本,可以下载和运行的非技术Mac用户。我不想让他们打开终端窗口并键入命令。

    我希望整个过程尽可能简单。

    有办法解决这个问题吗?

    2 回复  |  直到 6 年前
        1
  •  1
  •   Lyndsey Ferguson    6 年前

    1. 创建Apple开发者ID
      1. https://developer.apple.com/programs/enroll/
    2. 创建开发人员ID证书
      1. 注意:只有团队代理才能这样做。
      2. 登录您的Apple开发者帐户
      3. 选择证书、标识符和配置文件
      4. 在“证书”下,选择“生产”
      5. 单击右侧的“+”按钮
      6. 按照说明创建新的CSR,然后按Continue
      7. 上载CSR,然后下载证书。
      8. 双击证书以将其导入密钥链。钥匙链访问应用程序将启动。
      9. 选择导入的证书以查看开发人员ID。它将采用“开发人员ID应用程序:我的实体(blahblah)”的形式。
    3. 运行一个脚本,使脚本可执行,对其进行签名,将其捆绑到DMG中,然后对DMG进行签名

    ```

    #!/usr/bin/env bash
    
    # exit the script right away if there are any errors
    set -e 
    
    # make the distributed script executable
    chmod a+x path/to/code/myshell.command # you MUST name this *.command for the signature to persist
    
    # sign the script; replace 'My Entity (blahblah)' with the actual value you saw in your Keychain Access app.
    codesign -s "Developer ID Application: My Entity (blahblah)" path/to/code/myshell.command
    
    # verify that the script has been signed
    spctl -a -t open --context context:primary-signature -v path/to/code/myshell.command
    
    # create the Disk Image with the contents of the path/to/code directory
    hdiutil create -ov -srcfolder path/to/code path/to/disk-image-file.dmg
    
    # sign the disk image
    codesign -s "Developer ID Application: My Entity (blahblah)" path/to/disk-image-file.dmg
    
    # verify that the disk image has been signed
    spctl -a -t open --context context:primary-signature -v path/to/disk-image-file.dmg
    

    ```

    现在,当客户打开磁盘映像时,只需双击*.command文件,它就会在他们的计算机上启动。它会问他们是否确定,但这比默认的不允许要好。

        2
  •  0
  •   Natsfan    6 年前

    有一个叫做 Platypus 这将把你的脚本变成一个简单的Mac应用程序。我在python脚本中使用它,但它适用于许多其他脚本类型,包括shell脚本。运行后 鸭嘴兽 在您的脚本上,客户只需双击应用程序。