macos - Mac : Getting path of current desktop picture from terminal

标签 macos osascript desktop-background

我正在编写一个 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

?

最佳答案

像这样:

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

关于macos - Mac : Getting path of current desktop picture from terminal,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28783834/

相关文章:

Applescript:所有脚本都可以访问的系统范围全局变量

python - 写入文件时出现 IOError

macos - Docker Pull - 未能注册层 : Error processing tar file(exit status 1): unexpected EOF

applescript - 来自终端 osascript 调用的多个 Applescript 行

objective-c - 高效地绘制数千个矩形并为其设置动画

macos - 在登录期间为所有用户启动 cocoa 应用程序

python - 更改桌面背景和播放 .mp3 文件不起作用

macos - 在 Mac 上获取桌面背景

xcode - 以编程方式启动 OS X 应用程序

swift - fatal error : could not build module 'Darwin'