1

I've been trying to find an novice-level answer to this for an embarrassing long time. New to Mac, so I'm trying to get my head around a process for these types of company wide, one and done, operations.

We moving offices and adding two printers. No print server, just wifi devices. I have written a script to add the two office printers. It works. I need to be able to send that script out to all of my users in a form where they can just double click the file and run the script.

The script works when pasted into a terminal, easy enough. But my user base won't be able to do that without me having to touch nearly every machine.

Script that works:

lpadmin -p 1_Printer -E -v ipp://x.x.x.x -P ~/AirPrint.ppd 
lpadmin -p 2_Printer -E -v ipp://x.x.x.y -P ~/AirPrint.ppd 

echo "Printers added successfully"  

But I cannot figure out how to turn it into a basic executable file that I can push to the user base. In a previous life, I would just save the .bat and make it available on move in day. I've been going through suggestions about .sh manipulation, .command files, and other programming that I don't have a good handle on. But I keep hitting a wall where file permissions and executable status need to be changed locally or run through Terminal. That defeats the purpose of making it easy and self service.

Am I missing something obvious or otherwise basic, or is there a way I can do this I just haven't found?

1
  • 1
    All you have to do is add the .command filename extension and set the owner-executable bit. Depending on how you distribute it, the quarantine attribute may be set locally, in which case the user will be prompted to click through a warning. You can prevent that by code-signing the script file. It sounds like you already know most of this, so if it’s not working for you, please elaborate. But a more natural approach would be to distribute a configuration profile that you create in Apple Configurator.
    – Linc Davis
    Commented Jul 9 at 18:40

1 Answer 1

1

Use the Automator application to create an application.

  1. Open Automator application.

    enter image description here

  2. Select "New Document" button.

  3. Choose "Application".

    enter image description here

  4. Add "Run Shell Script" to your workflow.

    enter image description here

  5. Add your commands.

    enter image description here

  6. Save as a application.

    enter image description here

  7. Quit the Automator application.


Note: You may what to add a trap to display an error message if one of the lpadmin commands returns nonzero value. For example:

trap "osascript -e 'display dialog \"Failed to add printers\" buttons \"OK\"';exit" ERR

lpadmin -p 1_Printer -E -v ipp://x.x.x.x -P ~/AirPrint.ppd 
lpadmin -p 2_Printer -E -v ipp://x.x.x.y -P ~/AirPrint.ppd 

osascript -e 'display dialog "Printers added successfully" buttons "OK"'  
2
  • Thanks, that hits everything I needed. And thanks for the call out on the trap. I still ran into one problem, the app won't execute on any machine by my own. The error is "The application Office Mac Printer Install can't be opened". The file path I'm calling is from /system/library and is generic. Could there be a setting in Automator that is locking the app? Commented Jul 9 at 21:14
  • I tested by creating the app on a Ventura machine and then transferring to a Catalina machine. I did not use the lpadmin command. Instead, I substituted either the true or false command. I did not have the error you describe. Commented Jul 10 at 15:42

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .