管理 macOS 上的桌面壁纸
这是一个命令行应用和一个 Swift 包。
即使壁纸设置为目录,它也能正确处理获取当前壁纸。
需要 macOS 10.14.4 或更高版本。
brew install wallpaper
下载 二进制文件并将其放入 /usr/local/bin
。
默认情况下,它设置和获取所有屏幕的壁纸。使用 --screen
标志来更改此行为。
$ wallpaper
USAGE: wallpaper <subcommand>
OPTIONS:
--version Show the version.
-h, --help Show help information.
SUBCOMMANDS:
get Get current wallpaper images.
set Set image as wallpaper.
set-solid-color Set solid color as wallpaper.
screens Get a list of available screens.
$ wallpaper get --help
OVERVIEW: Get current wallpaper images.
USAGE: wallpaper get [--screen <screen>]
OPTIONS:
--screen <screen> Values: all, main, <index> (default: all)
$ wallpaper set --help
OVERVIEW: Set image as wallpaper.
USAGE: wallpaper set <path> [--screen <screen>] [--scale <scale>] [--fill-color <fill-color>]
ARGUMENTS:
<path> The path to the image to use as wallpaper.
OPTIONS:
--screen <screen> Values: all, main, <index> (default: all)
--scale <scale> Values: auto, fill, fit, stretch, center (default: auto)
--fill-color <fill-color>
Format: Hex color <RRGGBB>
$ wallpaper set-solid-color --help
OVERVIEW: Set solid color as wallpaper.
USAGE: wallpaper set-solid-color <color> [--screen <screen>]
ARGUMENTS:
<color> The color to use as wallpaper.
OPTIONS:
--screen <screen> Values: all, main, <index> (default: all)
wallpaper set unicorn.jpg
wallpaper set-solid-color 0000ff
wallpaper get
/Users/sindresorhus/unicorn.jpg
构建此项目需要最新的 Xcode 和 macOS 版本。该软件包支持 macOS 10.14.4 或更高版本。
将以下内容添加到 Package.swift
.package(url: "https://github.com/sindresorhus/macos-wallpaper", from: "2.3.2")
import Wallpaper
let imageURL = URL(fileURLWithPath: "<path>", isDirectory: false)
try! Wallpaper.set(imageURL, screen: .main, scale: .fill)
let solidColor = NSColor.blue
try! Wallpaper.set(solidColor, screen: .main)
print(try! Wallpaper.get(screen: .main))
查看源代码以了解更多信息。
swift run wallpaper
swift build --configuration=release --arch arm64 --arch x86_64 && mv .build/apple/Products/Release/wallpaper .
Do Not Disturb
功能