6

我正在编写一个 bash 脚本,负责在我的 mac 上设置桌面背景。我可以设置桌面背景:

$ osascript -e 'tell app "Finder" to set desktop picture to POSIX file "/Library/Desktop Pictures/Solid Colors/Solid White.png"'

但是,我还需要获取桌面图片的路径。我得到的最接近的是:

$ osascript -e 'tell app "Finder" to get desktop picture'

这将返回桌面图片的路径,但格式非常奇怪,我无法使用:

document file Solid White.png of folder Solid Colors of folder Desktop Pictures of folder Library of startup disk

有什么办法可以得到当前桌面图片的路径,返回:

/Library/Desktop\ Pictures/Solid\ Colors/Solid\ White.png

?

4

3 回答 3

6

我发现答案可以缩短为一行:

osascript -e 'tell app "finder" to get posix path of (get desktop picture as alias)'
于 2015-02-28T17:54:22.450 回答
4

像这样:

osascript -e '
    tell application "Finder"
    set theDesktopPic to desktop picture as alias
    set theName to posix path of theDesktopPic
    end tell'

/Users/mark/Documents/Carbon fibre.png
于 2015-02-28T16:26:48.557 回答
0

以下适用于我在 MacOS Mojave 10.14.6 下使用脚本编辑器和osascript

tell application "System Events" to get pictures folder of every desktop

输出:

{"/Users/jchilders/Library/Mobile Documents/com~apple~CloudDocs/Wallpapers"}

替换everyfirst以获得单个条目:

tell application "System Events" to get pictures folder of first desktop

输出:

"/Users/jchilders/Library/Mobile Documents/com~apple~CloudDocs/Wallpapers"

来自 apple.stackexchange.com 的原始答案

于 2019-09-05T19:21:17.900 回答