This commit is contained in:
Carl P. Corliss 2024-06-06 04:04:40 -05:00 committed by GitHub
commit 789f957d51
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -2,7 +2,7 @@
Title: How to disable CUPS printer job history on macOS Title: How to disable CUPS printer job history on macOS
Description: Learn how to disable CUPS printer job history on macOS. Description: Learn how to disable CUPS printer job history on macOS.
Author: Sun Knudsen <https://github.com/sunknudsen> Author: Sun Knudsen <https://github.com/sunknudsen>
Contributors: Sun Knudsen <https://github.com/sunknudsen> Contributors: Sun Knudsen <https://github.com/sunknudsen>, Carl P. Corliss <https://github.com/rabbitt>
Reviewers: Reviewers:
Publication date: 2022-10-29T13:05:18.112Z Publication date: 2022-10-29T13:05:18.112Z
Listed: true Listed: true
@ -34,7 +34,7 @@ sudo mkdir -p /usr/local/sbin
sudo chown ${USER}:admin /usr/local/sbin sudo chown ${USER}:admin /usr/local/sbin
``` ```
### Step 3: create `cups.sh` script ### Step 3: create `cups.sh` script (see CUPS [docs](https://www.cups.org/doc/man-cupsd.conf.html))
```shell ```shell
cat << "EOF" > /usr/local/sbin/cups.sh cat << "EOF" > /usr/local/sbin/cups.sh
@ -42,15 +42,11 @@ cat << "EOF" > /usr/local/sbin/cups.sh
set -e set -e
if grep -qe '^PreserveJobHistory Off$' /etc/cups/cupsd.conf; then if cupsctl | grep --quiet PreserveJobHistory=no; then
exit 0 exit 0
fi fi
echo "PreserveJobHistory Off" | sudo tee -a /etc/cups/cupsd.conf cupsctl MaxJobTime=5m PreserveJobFiles=no PreserveJobHistory=no
sudo launchctl unload /System/Library/LaunchDaemons/org.cups.cupsd.plist
sudo launchctl load /System/Library/LaunchDaemons/org.cups.cupsd.plist
EOF EOF
``` ```
@ -62,6 +58,8 @@ chmod +x /usr/local/sbin/cups.sh
### Step 5: create `local.cups.plist` launch daemon ### Step 5: create `local.cups.plist` launch daemon
> Heads-up: used to make sure user-defined config persists macOS updates.
```shell ```shell
cat << "EOF" | sudo tee /Library/LaunchDaemons/local.cups.plist cat << "EOF" | sudo tee /Library/LaunchDaemons/local.cups.plist
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
@ -91,32 +89,24 @@ EOF
## Want things back the way they were before following this guide? No problem! ## Want things back the way they were before following this guide? No problem!
### Step 1: delete `PreserveJobHistory Off` line from `cupsd.conf` ### Step 1: delete `cups.sh` script
```shell
sudo sed -i "" "/PreserveJobHistory Off/d" /etc/cups/cupsd.conf
```
### Step 2: delete `cups.sh` script
```shell ```shell
sudo rm /usr/local/sbin/cups.sh sudo rm /usr/local/sbin/cups.sh
``` ```
### Step 3: delete `local.cups.plist` launch daemon ### Step 2: delete `local.cups.plist` launch daemon
```shell ```shell
sudo rm /Library/LaunchDaemons/local.cups.plist sudo rm /Library/LaunchDaemons/local.cups.plist
``` ```
### Step 4: reload CUPS ### Step 3: revert user-defined config to CUPS defaults
```shell ```shell
sudo launchctl unload /System/Library/LaunchDaemons/org.cups.cupsd.plist cupsctl MaxJobTime= PreserveJobFiles= PreserveJobHistory=
sudo launchctl load /System/Library/LaunchDaemons/org.cups.cupsd.plist
``` ```
### Step 5: reboot ### Step 4: reboot
👍 👍