如何制作一个非技术Mac用户可以双击下载并运行的脚本?

时间:2018-09-09 12:19:50

标签: macos shell command-line

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

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

有没有办法做到这一点?

2 个答案:

答案 0 :(得分:0)

我已经解决了这个问题,但是由于没有找到提供明确帮助的文章,我想我会在这里写下来。为了提供可以由非技术用户轻松运行的脚本,您可以对可执行脚本进行代码签名,并将其打包到DMG中,并对其进行代码签名。为此,需要一些步骤,所以让我为您解压缩这些步骤。

  1. 创建Apple开发人员ID
    1. 这是最简单的步骤(⚠️它要花钱)。只需按照此处的说明进行操作:https://developer.apple.com/programs/enroll/
  2. 创建开发人员ID证书
    1. 注意:只有团队代理可以执行此操作。
    2. 登录您的Apple开发者帐户
    3. 从左上方的下拉菜单中选择macOS
    4. 选择证书,标识符和配置文件
    5. 在证书下,选择生产
    6. 点击右侧的“ +”按钮
    7. 在生产中,选择“开发人员ID”,然后按继续按钮。
    8. 选择“开发人员ID应用程序”,然后按“继续”按钮
    9. 按照说明创建新的CSR,然后按继续
    10. 上传CSR,然后下载证书。
    11. 双击证书以将其导入您的钥匙串。钥匙串访问应用程序将启动。
    12. 选择导入的证书以查看开发人员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

```

  1. 创建上述脚本并从Terminal bash路径/to/build-script.sh中运行它

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

答案 1 :(得分:0)

有一个名为Platypus的免费应用程序,它将您的脚本转换为简单的Mac应用程序。我在python脚本上使用了它,但它可用于许多其他脚本类型,包括shell脚本。在脚本上运行Platypus后,客户所需要做的就是双击应用程序。