Swift code to change the Wallpaper for all screens. Currently, it changes only the current spaces' wallpaper. I'm working on a version to change in all spaces.
Usage: WallpaperChanger "/Users/username/SomeFolder/SomePicture.jpg"
// | |
// main.swift | |
// WallpaperChanger | |
// | |
// Created by Tercio Gaudencio Filho on 8/12/15. | |
// Copyright (c) 2015 Tercio Gaudencio Filho. All rights reserved. | |
// | |
import AppKit | |
func setWallpaper(wallpaperPath: String){ | |
var error : NSError? | |
let sharedWorkspace = NSWorkspace.sharedWorkspace() | |
let screens = NSScreen.screens()! | |
let wallpaperUrl : NSURL = NSURL.fileURLWithPath(wallpaperPath)! | |
for screen in screens{ | |
sharedWorkspace.setDesktopImageURL(wallpaperUrl, forScreen: screen as! NSScreen, options: nil, error: &error) | |
} | |
} | |
if Process.arguments.count == 2 { | |
let wallpaperPath = Process.arguments[1] | |
setWallpaper(wallpaperPath) | |
} else { | |
print("Usage: \(Process.arguments[0]) WALLPAPER") | |
} |