I know this is a shot in the dark, but figured I'd post this script to see if there are any ideas for getting line breaks in the output of an EA that reads the file output by the script.
High level...green initiative to set default for all installed printers to Duplex. To start, we need a report that shows what printers every user has installed that offer Duplex, and show what the default is set to.
I created a script that basically pulls a list of installed printers using lpstat, then use lpoptions to identify any that show "Duplex/", then look for the default option that is set (None, DuplexNoTumble, or DuplexTumble, an asterisk is used to show chosen default), then output to a file for each printer, containing these three possible states:
<printerName> <None> or <printerName> <DuplexNoTumble> or <printerName> <DuplexTumble>
The script...
#!/bin/sh
# Report default Duplex setting for installed printers that offer the feature.
# 20180205 Don Montalvo
# Create report folder
/bin/mkdir -p /Library/Company/SearchResults/
# Remove old reports
/bin/rm /Library/Company/SearchResults/PrinterDuplexReport-*.txt
# Get printerName for each installed printer
/usr/bin/lpstat -p | awk '{ print $2 }' > /tmp/.printersList.txt
# Go through printerName list, and report any that have duplex function,
# and include the default duplexSetting, output to a printersList.
while IFS= read -r printerName; do
duplexSetting=$( /usr/bin/lpoptions -p "$printerName" -l | grep "Duplex/"| sed 's/.**//' | cut -f1 -d " " )
/bin/echo "$printerName $duplexSetting" > /Library/Company/SearchResults/PrinterDuplexReport-"$printerName".txt
done < "/tmp/.printersList.txt"
# Remove printersList
if [ -e /tmp/.printersList.txt ]; then
/bin/rm /tmp/.printersList.txt
fi
exit 0
An EA, which basically cats each of the files. Terminal shows cat output as a list. Jamf Pro shows the output as a single line. #sigh
#!/bin/sh
# Check installed printers duplex default setting.
# 20180205 Don Montalvo
defaultSetting=$( echo | cat /Library/Company/SearchResults/PrinterDuplexReport-*.txt 2>/dev/null )
if [[ $defaultSetting ]]; then
echo "<result>"$defaultSetting"</result>"
else
echo "<result>"NoDuplexPrintersInstalled"</result>"
fi
Sanity check, is there nothing I can do to get line returns in the output of the EA?
Gracias in advance.
Don
