Memperluas jawaban Leonard :
Anda dapat melakukan ini dengan mengganti Mojave.heic
latar belakang desktop default. Ini tidak memerlukan menonaktifkan SIP , seperti di /Library
.
- Cadangkan
/Library/Desktop Pictures/Mojave.heic
dengan menyalinnya Mojave.heic.orig
atau serupa.
- Dapatkan gambar baru Anda dan skala / tanaman itu untuk persis sesuai layar. Jika Anda tidak tahu resolusi layar Anda, Anda bisa pergi ke > About Mac ini.
Ganti Mojave.heic
dengan file baru Anda. Jangan khawatir apakah itu JPG atau sejenisnya, masih akan berfungsi bahkan setelah Anda menamainya kembali Mojave.heic
. *
Jika FileVault Anda diaktifkan, ubah opsi login di System Preferences. Misalnya, apakah akan menampilkan daftar pengguna atau bidang nama dan kata sandi. Ganti saja jika Anda tidak ingin itu diubah.
Ini karena ketika Anda boot dengan FileVault, pada layar login sistem Anda belum benar-benar melakukan booting sepenuhnya ! Ini sebenarnya menjalankan sistem kecil pada partisi EFI Anda, karena partisi utama Anda dienkripsi. Mengubah opsi masuk akan membuat Preferensi Sistem mengubah pengaturan sistem EFI, termasuk mengambil perubahan wallpaper. Lihat jawaban ini .
Reboot dan nikmatilah!
* Saya hanya menguji ini dengan gambar JPEG, tetapi mungkin bisa digunakan untuk jenis lain.
Penghemat waktu yang sama sekali tidak perlu
Saya telah membuat program Swift kecil yang melakukan semua ini untuk Anda (ia mendeteksi versi OS dan berfungsi baik pada Mojave dan versi sebelumnya). Anda perlu Xcode untuk mengompilasinya.
Seharusnya tidak merusak sistem Anda, tapi saya tidak bisa menjamin apa pun - pastikan Anda memiliki cadangan terlebih dahulu!
Ini sekarang juga tersedia di GitHub . Itu mungkin atau mungkin tidak diperbarui di sini di masa depan.
//
// 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/>.
//