@@ -9,7 +9,6 @@ import ArgumentParser
99import Files
1010import Foundation
1111import Cocoa
12- import Rainbow
1312import SwiftHEXColors
1413
1514class Command {
@@ -18,63 +17,61 @@ class Command {
1817 }
1918
2019 func run( ) {
21- print ( " Starting up " . green)
22- print ( " Found \( NSScreen . screens. count) screens \n " )
20+ Log . info ( " Starting up " )
2321
24- for screen in NSScreen . screens {
25- print ( " Processing screen \( screen. index) of \( NSScreen . screens. count) " )
26-
27- guard let adjustedWallpaper = createWallpaper ( screen: screen) , let data = adjustedWallpaper. jpgData else {
28- print ( " Could not generate new wallpaper for screen \( screen. index) " . red)
29- continue
30- }
22+ guard let screen = NSScreen . main else {
23+ Log . error ( " Could not find the main screen " )
24+ return
25+ }
3126
32- setWallpaper ( screen: screen, wallpaper: data)
27+ guard let adjustedWallpaper = createWallpaper ( screen: screen) , let data = adjustedWallpaper. jpgData else {
28+ Log . error ( " Could not generate new wallpaper fr the main screen " )
29+ return
3330 }
3431
35- print ( " All done! " . green)
32+ setWallpaper ( screen: screen, wallpaper: data)
33+
34+ Log . info ( " All done! " )
3635 }
3736
3837 func loadWallpaperImage( wallpaper: String ? , screen: NSScreen ) -> NSImage ? {
3938 if let path = wallpaper {
4039 guard let wallpaper = NSImage ( contentsOfFile: path) else {
41- print ( " Cannot read the provided wallpaper file as image. Check if the path is correct and if it is a valid image file " . red )
40+ Log . error ( " Cannot read the provided wallpaper file as image. Check if the path is correct and if it is a valid image file " )
4241 return nil
4342 }
4443
45- print ( " Loaded \( path) to be used as wallpaper image " )
44+ Log . debug ( " Loaded \( path) to be used as wallpaper image " )
4645 return wallpaper
4746 }
4847
4948 guard let path = NSWorkspace . shared. desktopImageURL ( for: screen) , let wallpaper = NSImage ( contentsOf: path) else {
50- print ( " Cannot read the currently set macOS wallpaper " . red)
51- print ( " Try providing a specific wallpaper as a parameter instead " . blue)
49+ Log . error ( " Cannot read the currently set macOS wallpaper. Try providing a specific wallpaper as a parameter instead. " )
5250 return nil
5351 }
5452
55- print ( " Using currently set macOS wallpaper \( path) " )
53+ Log . debug ( " Using currently set macOS wallpaper \( path) " )
5654
5755 return wallpaper
5856 }
5957
6058 private func setWallpaper( screen: NSScreen , wallpaper: Data ) {
6159 guard let supportFiles = try ? Folder . library? . subfolder ( at: " Application Support " ) , let workingDirectory = try ? supportFiles. createSubfolderIfNeeded ( at: " ChangeMenuBarColor " ) else {
62- print ( " Cannot access Application Support folder " . red )
60+ Log . error ( " Cannot access Application Support folder " )
6361 return
6462 }
6563
6664 do {
67- let generatedWallpaperFile = workingDirectory. url. appendingPathComponent ( " /wallpaper-screen \( screen . index ) -adjusted- \( UUID ( ) . uuidString) .jpg " )
65+ let generatedWallpaperFile = workingDirectory. url. appendingPathComponent ( " /wallpaper-screen-adjusted- \( UUID ( ) . uuidString) .jpg " )
6866 try ? FileManager . default. removeItem ( at: generatedWallpaperFile)
6967
7068 try wallpaper. write ( to: generatedWallpaperFile)
71- print ( " Created new wallpaper for screen \( screen. index ) in \( generatedWallpaperFile. absoluteString) " )
69+ Log . debug ( " Created new wallpaper for the main screen in \( generatedWallpaperFile. absoluteString) " )
7270
7371 try NSWorkspace . shared. setDesktopImageURL ( generatedWallpaperFile, for: screen, options: [ : ] )
74- print ( " Wallpaper set " . blue )
72+ Log . info ( " Wallpaper set " )
7573 } catch {
76- print ( " Writing new wallpaper file failed with \( error. localizedDescription) for screen \( screen. index ) " . red )
74+ Log . error ( " Writing new wallpaper file failed with \( error. localizedDescription) for the main screen " )
7775 }
78- print ( " \n " )
7976 }
8077}
0 commit comments