-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.swift
57 lines (46 loc) · 1.3 KB
/
utils.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
//
// utils.swift
// wallsh
//
// Created by Jaume Segarra on 31/8/18.
// Copyright © 2018 Jaume Segarra. All rights reserved.
//
import Foundation
import AppKit
func getWallpaper() -> Int32{
var result: Int32 = 1;
let workspace = NSWorkspace.shared
if let screen = NSScreen.main {
let desktopWallpaper = workspace.desktopImageURL(for: screen);
var path: String? = desktopWallpaper?.absoluteString;
path?.removeFirst(7);
if(path != nil){
print(path!)
result = 0
}else{
print("ERROR: Path no found")
}
}else{
print("ERROR: No wallpaper found")
}
return result
}
func setWallpaper(path: String) -> Int32{
var result: Int32 = 1;
do {
let imgurl = NSURL.fileURL(withPath: path)
let fileManager = FileManager.default
if fileManager.fileExists(atPath: imgurl.path) {
let workspace = NSWorkspace.shared
if let screen = NSScreen.main {
try workspace.setDesktopImageURL(imgurl, for: screen, options: [:])
result = 0;
}
}else{
print("ERROR: Wallpaper doesn't exist")
}
} catch {
print("ERROR: ", error)
}
return result
}