Skip to content

Instantly share code, notes, and snippets.

@justrhysism
Created February 28, 2023 11:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save justrhysism/8fc3c131a3656a868014c61376a40c3d to your computer and use it in GitHub Desktop.
Save justrhysism/8fc3c131a3656a868014c61376a40c3d to your computer and use it in GitHub Desktop.
// Name: Fix Wallpaper
import "@johnlindquist/kit";
/**
* Ensure you have a ~/Library/Desktop/Wallpaper.jpg file ready to go.
*
* The script requires sudo access, and assumes you have TouchID connected
* to `sudo` by prepending:
* ```
* auth sufficient pam_tid.so
* ```
* to the `/etc/pam.d/sudo` file.
*
* So your file should look like:
* ```
* # sudo: auth account password session
* auth sufficient pam_tid.so # <-- Add this line to top
* auth sufficient pam_smartcard.so
* auth required pam_opendirectory.so
* account required pam_permit.so
* password required pam_deny.so
* session required pam_permit.so
* ```
*
* Notes:
* - This will be reset each time macOS is updated.
* - If you have using DisplayLink, TouchID will not work, but macOS
* will prompt you for your password.
*/
const SETTING_VOLUME_NAME = "Wallpaper";
const SETTING_TARGET_PATH = "/Library/Desktop";
try {
await $`diskutil info ${SETTING_VOLUME_NAME} | grep "Volume Name"`;
// Use `exec` for processes that require sudo access.
await exec(
`sudo diskutil umount ${SETTING_VOLUME_NAME}; sudo diskutil mount readOnly -mountPoint ${SETTING_TARGET_PATH} ${SETTING_VOLUME_NAME}`
);
await $`killall Dock`;
} catch (e) {
await div(
`<div class="p-4 text-red-700"><strong>Error:</strong> ${e._stderr}</div>`
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment