-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 6a72f41
Showing
3 changed files
with
121 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# wallsh for mac os | ||
|
||
> Get and set the desktop wallpaper of the current workspace. | ||
## How to install | ||
· [Download](https://github.com/jaumesegarra/wallsh-macos/releases) the binary file | ||
· Put it in `/usr/local/bin` folder. | ||
|
||
|
||
## How to use this command | ||
|
||
##### Get | ||
... | ||
$ wallsh -g | ||
... | ||
|
||
##### Set | ||
... | ||
$ wallsh -s /Users/jaumesegarra/Pictures/world.png | ||
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// | ||
// main.swift | ||
// wallsh | ||
// | ||
// Created by Jaume Segarra on 31/8/18. | ||
// Copyright © 2018 Jaume Segarra. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
import AppKit | ||
|
||
var arguments = CommandLine.arguments | ||
arguments.removeFirst(1) | ||
|
||
func help() { | ||
let message: String = | ||
"\n wallsh (v0.1): get and set the desktop wallpaper of the current workspace." + | ||
"\n\n Usage:\twallsh [options]" + | ||
"\n\n Options:" + | ||
"\n -h, --help\t\t\tprint help" + | ||
"\n -g \t\t\tget the current wallpaper" + | ||
"\n -s [path]\t\t\tset a wallpaper" + | ||
"\n\n Created by Jaume Segarra" | ||
|
||
print(message) | ||
} | ||
|
||
if(arguments.count > 0){ | ||
switch arguments[0]{ | ||
case "--help", "-h": | ||
help() | ||
case "-s": | ||
if(arguments.count == 2){ | ||
exit(setWallpaper(path: arguments[1])) | ||
}else{ | ||
print("No wallpaper path introduced...") | ||
exit(1) | ||
} | ||
case "-g": | ||
exit(getWallpaper()) | ||
default: | ||
help() | ||
} | ||
}else { help() } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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 | ||
} |