如何在macOS Mojave中更改登录屏幕背景?


21

我刚刚更新到macOS Mojave,立即注意到以下几点:

  • 我的自定义登录屏幕壁纸不见了。
  • 当您在登录屏幕上单击用户名时,它将切换到其个人背景(主显示器第一空间的常用墙纸)。

我以为它刚刚覆盖了我的缓存图像文件。但是当我去更换它时,什么也没发生。事实证明,这com.apple.desktop.admin.png完全消失了!

没有缓存的图像

截取该屏幕截图之后,我决定进入Desktop Pictures,并发现我的个人登录屏幕背景,这看起来很有希望。它包含另一个文件夹,其中 大概  (编辑:已确认)包含我的管理员帐户的登录屏幕背景。

Answers:


16

我已经解决了!但是,您必须编辑沙丘HEIC图片。如果您愿意,请按照下列步骤操作:

1)转到:/ Library / Desktop Pictures /

2)找到名为“ Mojave.heic”的文件

3)将副本另存为备份

4)选择您想要的图片

5)编辑图像值(DPI,大小等)以适合

6)将此编辑的图片重命名为Mojave.heic


好的想法,除了可以“删除”“桌面背景”首选项窗格中的Mojave背景。
juniorRubyist

那绝对可以接受!我认为SIP不会触发,因为它在/Library吗?必须是HEIF,对吗?我的大多数图像都是JPEG,因此我必须找出一种将其转换为JPEG的方法。也许吧sip
SilverWolf-恢复莫妮卡

您可以将整个jpg文件重命名为Mojave.heic,它可以正常工作。
伦纳德

@Leonard有趣。您已经测试过了,并且有效吗?我很惊讶,但这太棒了!
SilverWolf-恢复莫妮卡

@BlackPearl尝试了此操作,但没有成功。不过,我不知道尝试的所有细节。
SilverWolf-恢复莫妮卡

6

扩大伦纳德的答案

您可以通过替换Mojave.heic默认的桌面背景来实现。这不需要禁用SIP,因为它在/Library

  • /Library/Desktop Pictures/Mojave.heic通过将其复制到Mojave.heic.orig或类似文件进行备份。
  • 获取新图像并缩放/裁剪以使其完全适合显示。如果您不知道屏幕分辨率,则可以转到>关于本机。
  • 替换Mojave.heic为新文件。不用担心它是JPG还是类似图片,即使将其重命名为Mojave.heic。* 仍然可以使用。

  • 如果启用了FileVault,请在“系统偏好设置”中更改登录选项。例如,是否显示用户列表或名称和密码字段。如果您实际上不希望更改它,只需将其更改回去。

    这是因为当您使用FileVault引导时,在登录屏幕上您的系统还没有真正完全引导!由于主分区已加密,因此它实际上在EFI分区上运行一个小型系统。更改登录选项将使“系统偏好设置”更改EFI系统的设置,包括获取墙纸更改。看到这个答案

  • 重新启动并享受!

*我仅使用JPEG图像对此进行了测试,但它可能适用于其他类型。


完全不必要的节省时间

我制作了一个小的Swift程序,可以为您完成所有这些工作(它可以检测OS版本,并且可以在Mojave和早期版本上运行)。您将需要Xcode进行编译。

它不应该破坏您的系统,但是我不能保证任何事情- 确保您首先有备份!

现在也可以在GitHub上使用。将来可能会在此处进行更新,也可能不会进行更新。

//
// loginwindowbgconverter
// by SilverWolf
// 2018-09-27
//

import Foundation
import AppKit

func printUsage() {
    print("""
    usage: \(CommandLine.arguments[0]) \u{1B}[4mimage-file\u{1B}[0m
    It needs to be run as root, as it saves to /Library/Desktop Pictures.
    """)
}

guard CommandLine.arguments.indices.contains(1) else {
    printUsage()
    exit(1)
}
let inputFile = CommandLine.arguments[1]

guard let inputImage = NSImage(contentsOfFile: inputFile) else {
    print("\(CommandLine.arguments[0]): can't load image from \(inputFile)")
    exit(2)
}

let iw = inputImage.size.width
let ih = inputImage.size.height
let iaspect = Double(iw) / Double(ih)

// use System Profiler to get screen size

var sw = 0, sh = 0

enum ScreenSizeError: Error {
    case foundNil
}
do {
    let task = Process()
    if #available(macOS 10.13, *) {
        task.executableURL = URL(fileURLWithPath: "/bin/zsh")
    } else {
        task.launchPath = "/bin/zsh"
    }
    task.arguments = ["-f", "-c", "system_profiler SPDisplaysDataType | awk '/Resolution/{print $2, $4}' | head -n 1"]

    let stdoutPipe = Pipe()
    task.standardOutput = stdoutPipe

    if #available(macOS 10.13, *) {
        try task.run()
    } else {
        task.launch()
    }
    task.waitUntilExit()

    let data = stdoutPipe.fileHandleForReading.readDataToEndOfFile()
    guard let text = String(data: data, encoding: .utf8) else {
        throw ScreenSizeError.foundNil
    }
    let sizes = (text as NSString).replacingOccurrences(of: "\n", with: "").components(separatedBy: " ")
    sw = Int(sizes[0]) ?? 0
    sh = Int(sizes[1]) ?? 0
    guard sw != 0 && sh != 0 else {
        throw ScreenSizeError.foundNil
    }
} catch {
    print("\(CommandLine.arguments[0]): can't get screen resolution")
    exit(3)
}

print("Screen size: \(sw)x\(sh)")

var nw = 0, nh = 0
var x = 0, y = 0 // offsets

let saspect = Double(sw) / Double(sh)
if saspect > iaspect { // screen is wider
    nw = sw
    nh = Int(Double(sw) / iaspect) // keep input image aspect ratio
    y = -1 * (nh - sh) / 2 // half the difference
} else { // screen is narrower
    nh = sh
    nw = Int(Double(sh) * iaspect)
    x = -1 * (nw - sw) / 2
}

// draw into new image
guard let newImage = NSBitmapImageRep(bitmapDataPlanes: nil,
                                pixelsWide: Int(sw),
                                pixelsHigh: Int(sh),
                                bitsPerSample: 8,
                                samplesPerPixel: 4,
                                hasAlpha: true,
                                isPlanar: false,
                                colorSpaceName: .deviceRGB,
                                bytesPerRow: sw * 4,
                                bitsPerPixel: 32) else {
    print("\(CommandLine.arguments[0]): can't create bitmap image to draw into!")
    exit(2)
}

NSGraphicsContext.saveGraphicsState()
let graphicsContext = NSGraphicsContext(bitmapImageRep: newImage)
NSGraphicsContext.current = graphicsContext
graphicsContext?.imageInterpolation = .high
let r = NSMakeRect(CGFloat(x), CGFloat(y), CGFloat(nw), CGFloat(nh))
print("drawing rect: \(r)")
inputImage.draw(in: r)

graphicsContext?.flushGraphics()
NSGraphicsContext.restoreGraphicsState()

print("image size: \(newImage.size)")

// write to file
if #available(macOS 10.14, *) { // macOS Mojave has a completely different system
    let targetFile = "/Library/Desktop Pictures/Mojave.heic"
    let origFile =  "/Library/Desktop Pictures/Mojave.heic.orig"
    if !FileManager.default.fileExists(atPath: origFile) { // no backup of original Mojave.heic
        print("Backing up original Mojave.heic (this should only happen once)")
        do {
            try FileManager.default.copyItem(atPath: targetFile, toPath: origFile)
        } catch {
            print("\(CommandLine.arguments[0]): \u{1B}[1mbackup failed, aborting!\u{1B}[0m \(error.localizedDescription)")
            exit(1)
        }
    }

    print("Saving to \(targetFile)")
    // actual writing
    let imageData = newImage.representation(using: .jpeg, properties: [:])!
    do {
        try imageData.write(to: URL(fileURLWithPath: targetFile))
    } catch {
        print("\(CommandLine.arguments[0]): can't write image data: \(error)")
        print("(are you root?)")
        exit(1)
    }
} else {
    let targetFile = "/Library/Caches/com.apple.desktop.admin.png"
    print("Saving to \(targetFile)")
    let pngData = newImage.representation(using: .png, properties: [:])!
    do {
        try pngData.write(to: URL(fileURLWithPath: targetFile))
    } catch {
        print("\(CommandLine.arguments[0]): can't write image data: \(error)")
        print("(are you root?)")
        exit(1)
    }
}

//
// This is free and unencumbered software released into the public domain.
//
// Anyone is free to copy, modify, publish, use, compile, sell, or
// distribute this software, either in source code form or as a compiled
// binary, for any purpose, commercial or non-commercial, and by any
// means.
//
// In jurisdictions that recognize copyright laws, the author or authors
// of this software dedicate any and all copyright interest in the
// software to the public domain. We make this dedication for the benefit
// of the public at large and to the detriment of our heirs and
// successors. We intend this dedication to be an overt act of
// relinquishment in perpetuity of all present and future rights to this
// software under copyright law.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
// OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.
//
// For more information, please refer to <https://unlicense.org/>.
//

要获取屏幕尺寸,您可以使用NSScreen框架属性developer.apple.com/documentation/appkit/nsscreen/1388387-frame
Mateusz Szlosek

我试过了 它返回用于布局的“假”屏幕尺寸,而不是实际的物理屏幕尺寸。
SilverWolf-恢复莫妮卡

并且将其乘以支持比例因子也不起作用:即使我使用更高的密度缩放比例,它也为我返回了单位2。因此,它可以大于或小于物理大小,具体取决于您的缩放设置。(:
SilverWolf-恢复莫妮卡

好的,我明白你的意思了:)
Mateusz Szlosek '18

1
不幸的是,这对我没有用。我什至尝试了该程序,但没有成功。我仍在使用默认沙丘而不是我的照片。我已启用FileVault,但是按照您的描述更改了登录选项。有任何想法吗?
Artem M,

1

当我只用JPG替换文件时,我收到一个奇怪的图像,也重命名了HEIC。但是,当我将想要的图像作为背景并在“预览”中以HEIC格式导出时,一切都很好。我正在使用5333×3333图像开始:

  1. 在预览中打开要用作背景的图像
  2. 在预览中,选择文件>导出...
  3. 将格式设置为HEIC,将质量设置为最佳(当尝试的质量小于“最佳”时,我得到了一个完全空白的图像)
  4. 将导出的文件重命名为Mojave(扩展名应该已经是.heic)
  5. 将导出的图像复制到 /Library/Desktop\ Pictures

注销时,您应该会看到新的背景。如果没有立即显示图像,请尝试重新启动。

如果在将文件导出为.heic时遇到问题,请尝试使用“预览:工具>调整大小”来调整图像的大小。首先,将其设置为屏幕的大小,如系统信息>图形/显示中所示。


谢谢,很高兴知道!另外,我编写了一个小程序来自动执行所有操作,如果您不想使用Preview对其进行调整,现在可以将其导出到HEIF。您可以在GitHub上找到它。
SilverWolf-恢复莫妮卡
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.