Lyndsey Ferguson
Lyndsey Ferguson

Reputation: 5384

How can I make a script that can be downloaded and run by a non-technical Mac user by double-clicking?

I want to make a script that can be downloaded and run by a non-technical Mac user. I do not want to make them open up the Terminal window and type commands.

I want the entire process to be as easy as possible.

Is there a way to acheive this?

Upvotes: 0

Views: 875

Answers (2)

Natsfan
Natsfan

Reputation: 4802

There is a free app called Platypus that will turn your script into a simple Mac app. I use it on my python scripts but it works for many other script types including shell scripts. After running Platypus on your script all a customer has to do is double click the app.

Upvotes: 0

Lyndsey Ferguson
Lyndsey Ferguson

Reputation: 5384

I solved this already, but as I haven't found an article providing explicit help, I thought I would write it up here. In order to deliver a script that is easily run by a non-technical user, you can codesign the executable script and package it up in a DMG which you also codesign. There are a some steps to doing this, so let me unpack it for you into those steps.

  1. Create a Apple Developer ID
    1. This is the easiest step (⚠️ it costs money). Just follow the instructions here: https://developer.apple.com/programs/enroll/
  2. Create a Developer ID Certificate
    1. Note: only the Team Agent can do this.
    2. Log into your Apple Developer Account
    3. Select macOS from the top-left dropdown menu
    4. Select Certificates, Identifiers, & Profiles
    5. Under Certificates, select Production
    6. Click the '+' button on the right
    7. Under Production, select "Developer ID" and press the button Continue
    8. Select "Developer ID Application" and press the button Continue
    9. Follow the instructions to create a new CSR and press Continue
    10. Upload the CSR and then download the certificate.
    11. Double-click the certificate to import it into your keychain. The Keychain Access app will start.
    12. Select the imported certificate to view the Developer ID. It will be of the form "Developer ID Application: My Entity (blahblah)".
  3. Run a script to make the script executable, sign it, bundle it into a DMG, and sign the 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. Create the above script and run it from the Terminal bash path/to/build-script.sh

Now, when the customer opens up the disk image, they can simply double-click the *.command file and it will launch on their computer. It will ask them if they're sure, but that is better than the default of not allowing it.

Upvotes: 2

Related Questions