简体   繁体   English

通过 shell 脚本添加打印机; 适用于终端但不适用于 as.command

[英]Adding printers by shell script; works in terminal but not as .command

I am trying to provide a clickable.command to set up printers in Macs for my workplace.我正在尝试提供一个 clickable.command 来为我的工作场所在 Mac 中设置打印机。 I thought since it is something I do very frequently, I can write a shellscript for each printer and save it on a shared server.我想既然这是我经常做的事情,我可以为每台打印机编写一个 shellscript 并将其保存在共享服务器上。 Then, when I need to add a printer for someone, I can just find the shell script on the server and execute it.然后,当我需要为某人添加打印机时,我可以在服务器上找到 shell 脚本并执行它。 My current command works in terminal, but once executed as a.command, it comes up with the errors.我当前的命令在终端中工作,但是一旦作为 a.command 执行,它就会出现错误。

This is my script:这是我的脚本:

#!/bin/sh
lpadmin -p ‘PRINTERNAME’ -D PRINTER\ NAME -L ‘OFFICE’ -v lpd://xx.xx.xx.xx -P /Library/Printers/PPDs/Contents/Resources/Xerox\ WorkCentre\ 7855.gz -o printer-is-shared=false -E​

I get this error after running the script:运行脚本后出现此错误:

lpadmin: Unknown option “?”.

I find this strange, because there is no "?"我觉得这很奇怪,因为没有“?” in the script.在脚本中。

I have a idea, why not try it like this?我有一个想法,为什么不这样尝试呢? there are huge differences between sh shells, so let me know if it rocks, I have more ideas. sh shell 之间存在巨大差异,所以如果它摇摆不定,请告诉我,我有更多想法。

#!/bin/sh
PPD="PRINTERNAME"
INFO="PRINTER\ NAME"
LOC="OFFICE"
URI="lpd://xx.xx.xx.xx"
OP ="printer-is-shared=false"
# This parameter P is new to me. Is it the paper-name ?
P="/Library/Printers/PPDs/Contents/Resources/Xerox\ WorkCentre\ 7855.gz"

lpadmin -p "$PPD"  -D "$INFO" -L "$LOC"  -v "$URI" -P "$P" -o "$OP" -E;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM