Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
148 changes: 148 additions & 0 deletions plugins/resources/AllSpacesAndDisplays.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>AllSpacesAndDisplays</key>
<dict>
<key>Desktop</key>
<dict>
<key>Content</key>
<dict>
<key>Choices</key>
<array>
<dict>
<key>Configuration</key>
<data>
YnBsaXN0MDDSAQIDDF8QD2JhY2tn
cm91bmRDb2xvcllwbGFjZW1lbnTS
BAUGC1pjb21wb25lbnRzWmNvbG9y
U3BhY2WkBwgJCiM/0FBQUFBQUCM/
2lpaWlpaWiM/5VVVVVVVVSM/8AAA
AAAAAE8QQ2JwbGlzdDAwXxAXa0NH
Q29sb3JTcGFjZUdlbmVyaWNSR0II
AAAAAAAAAQEAAAAAAAAAAQAAAAAA
AAAAAAAAAAAAACIQAQgNHykuOURJ
UltkbbMAAAAAAAABAQAAAAAAAAAN
AAAAAAAAAAAAAAAAAAAAtQ==
</data>
<key>Files</key>
<array>
<dict>
<key>relative</key>
<string>file:///paper </string>
</dict>
</array>
<key>Provider</key>
<string>com.apple.wallpaper.choice.image</string>
</dict>
</array>
<key>Shuffle</key>
<string>$null</string>
</dict>
<key>LastSet</key>
<date>2025-08-20T16:11:15Z</date>
<key>LastUse</key>
<date>2025-08-20T18:01:17Z</date>
</dict>
<key>Idle</key>
<dict>
<key>Content</key>
<dict>
<key>Choices</key>
<array>
<dict>
<key>Configuration</key>
<data>
</data>
<key>Files</key>
<array/>
<key>Provider</key>
<string>default</string>
</dict>
</array>
<key>Shuffle</key>
<string>$null</string>
</dict>
<key>LastSet</key>
<date>2024-11-12T15:44:40Z</date>
<key>LastUse</key>
<date>2025-08-20T18:01:17Z</date>
</dict>
<key>Type</key>
<string>individual</string>
</dict>
<key>Displays</key>
<dict/>
<key>Spaces</key>
<dict/>
<key>SystemDefault</key>
<dict>
<key>Desktop</key>
<dict>
<key>Content</key>
<dict>
<key>Choices</key>
<array>
<dict>
<key>Configuration</key>
<data>
YnBsaXN0MDDSAQIDDF8QD2JhY2tn
cm91bmRDb2xvcllwbGFjZW1lbnTS
BAUGC1pjb21wb25lbnRzWmNvbG9y
U3BhY2WkBwgJCiM/0FBQUFBQUCM/
2lpaWlpaWiM/5VVVVVVVVSM/8AAA
AAAAAE8QQ2JwbGlzdDAwXxAXa0NH
Q29sb3JTcGFjZUdlbmVyaWNSR0II
AAAAAAAAAQEAAAAAAAAAAQAAAAAA
AAAAAAAAAAAAACIQAQgNHykuOURJ
UltkbbMAAAAAAAABAQAAAAAAAAAN
AAAAAAAAAAAAAAAAAAAAtQ==
</data>
<key>Files</key>
<array>
<dict>
<key>relative</key>
<string>file:///paper </string>
</dict>
</array>
<key>Provider</key>
<string>com.apple.wallpaper.choice.image</string>
</dict>
</array>
<key>Shuffle</key>
<string>$null</string>
</dict>
<key>LastSet</key>
<date>2025-08-20T16:11:15Z</date>
<key>LastUse</key>
<date>2025-08-20T16:11:15Z</date>
</dict>
<key>Idle</key>
<dict>
<key>Content</key>
<dict>
<key>Choices</key>
<array>
<dict>
<key>Configuration</key>
<data>
</data>
<key>Files</key>
<array/>
<key>Provider</key>
<string>default</string>
</dict>
</array>
<key>Shuffle</key>
<string>$null</string>
</dict>
<key>LastSet</key>
<date>2024-11-12T15:44:40Z</date>
<key>LastUse</key>
<date>2025-08-20T16:06:48Z</date>
</dict>
<key>Type</key>
<string>individual</string>
</dict>
</dict>
</plist>
94 changes: 75 additions & 19 deletions plugins/wallpaper
Original file line number Diff line number Diff line change
@@ -1,36 +1,92 @@
#!/usr/bin/env bash
#!/usr/bin/env zsh


help(){
cat<<__EOF__
help() {
cat <<__EOF__
Usage: m wallpaper [OPTIONS]

Description: Set the desktop wallpaper to the specified image file

Options:
--help Show this help message
--help Show this help message
--set IMAGE_PATH Set the wallpaper to the specified image file


Examples:
m wallpaper --set ~/wallpapers/tree.jpg # set wallpaper
__EOF__
}

set_wallpaper(){
WALLPAPER_PLIST_PATH="${HOME}/Library/Application Support/com.apple.wallpaper/Store/Index.plist"
WALLPAPER_PLIST_BACKUP_PATH="${WALLPAPER_PLIST_PATH}_bkp"
WALLPAPER_REPLACEMENT_PLIST="${0:A:h}/resources/AllSpacesAndDisplays.plist"

buddy() {
/usr/libexec/PlistBuddy -c "${1}" "${WALLPAPER_PLIST_PATH}"
}

plist_backup_exists() {
[ -f "${WALLPAPER_PLIST_BACKUP_PATH}" ]
}

backup_plist() {
cp "${WALLPAPER_PLIST_PATH}" "${WALLPAPER_PLIST_BACKUP_PATH}"
}

reset_wallpaper_plist() {
buddy "Clear dict" 1>/dev/null
buddy "Merge '${WALLPAPER_REPLACEMENT_PLIST}'"
}

restart_wallpaper_agent() {
killall WallpaperAgent
}

set_path() {
local path="${1}"
buddy "Set AllSpacesAndDisplays:Desktop:Content:Choices:0:Files:0:relative file://${path}"
buddy "Set SystemDefault:Desktop:Content:Choices:0:Files:0:relative file://${path}"
}

set_wallpaper_sonoma() {
if ! plist_backup_exists; then
backup_plist
fi

reset_wallpaper_plist
set_path "${1:A}"
restart_wallpaper_agent
}

set_wallpaper_fallback() {
osascript -e "tell application \"System Events\" to tell every desktop to set picture to \"${1}\" as POSIX file"
}

case $1 in
--help)
help
;;
--set)
shift
[ -z "$1" ] && help && exit 1
set_wallpaper "$1"
;;
*)
help && exit 1
;;
migrated_to_sonoma() {
local major_version="$(sw_vers -productVersion | cut -d'.' -f1)"
local sonoma_major_version="14"

(( "${major_version}" >= "${sonoma_major_version}" )) &&
[ "$(defaults read 'com.apple.wallpaper' 'SonomaFirstRunMigrationPerformed' 2>/dev/null)" = "1" ]
}

set_wallpaper() {
if ! migrated_to_sonoma; then
echo "You're using macOS older than Sonoma (version 14), or you've just updated and the wallpaper agent hasn't perfomed migration yet. Falling back to an osascript wallpaper setter."
set_wallpaper_fallback "${1}"
else
set_wallpaper_sonoma "${1}"
fi
}

case "${1}" in
--help)
help
;;
--set)
shift
[ -z "${1}" ] && help && exit 1
set_wallpaper "${1}"
;;
*)
help && exit 1
;;
esac