Setting the Desktop background on OSX using Swift 2

前端 未结 3 1899
耶瑟儿~
耶瑟儿~ 2020-12-28 12:21

After an introduction to Javascript, I\'m trying to tackle OSX/iOS programming by creating some simple tools to scratch my own itches.

However, right from the jump I

3条回答
  •  没有蜡笔的小新
    2020-12-28 12:46

    Updated example for Swift 3:

    do {
       let imgurl = NSURL.fileURL(withPath: singleImage)
       let workspace = NSWorkspace.shared()
       if let screen = NSScreen.main()  {
           try workspace.setDesktopImageURL(imgurl, for: screen, options: [:])
       }
    } catch {
       print(error)
    }
    

提交回复
热议问题