Created
June 16, 2017 09:19
-
-
Save fbentele/65edcee2a80d96e7a3baaaf75614c95f to your computer and use it in GitHub Desktop.
Randomly select a installed printer on macOS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Randomly select a printer every 2 minutes | |
# This is a simple "load-balancing" printer queue | |
# Florian Bentele - 2017 | |
# Step 1: Open the Terminal.app (/Applications/Utilities/Terminal.app) | |
# Check what printer is the Default Printer, enter the following command and hit enter | |
lpstat -d | |
# The output should be something like "system default destination: my_printer1" | |
# Step 2: Check all printers that may be listed | |
lpstat -p | awk '{ print $2 }' | |
# This lists all the printers available, remove any printer you don't want to include in your loadbalancing from the systems preferences | |
# Step 3: Create a cronjob, that changes the default printer | |
crontab -l > tempcronjob | |
echo "*/2 * * * * lpoptions -d \`lpstat -p | awk '{ print $2 }' | ruby -e 'puts STDIN.readlines.shuffle' | head -n 1\` >/dev/null 2>&1" >> tempcronjob | |
crontab tempcronjob | |
rm tempcronjob | |
# Step 4: Test which is the default printer (the result will change ever 2 minutes) | |
lpstat -d | |
# To remove / stop the scrippt | |
crontab -e | |
# then go to the line where the cronjob is defined and press two times the letter "d" | |
# press ctrl+c and enter ":wq" and hit enter | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment