-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.scm
executable file
·94 lines (75 loc) · 2.66 KB
/
main.scm
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#! /usr/bin/csi -script
(import (chicken random)
(chicken file)
(chicken file posix)
(posix-utils)
(chicken process)
(chicken process-context)
(optimism))
;; Functions
(define (send-notification wallpaper)
(process-run "notify-send"
(list "-a" (program-name) "-u" "low"
"New wallpaper" wallpaper)))
(define (random-wallpaper wallpapers)
(list-ref wallpapers
(pseudo-random-integer (length wallpapers))))
(define (set-wallpaper wallpaper)
(process-run "swww" (list "img" wallpaper)))
(define (get-option-or-default options get_option default)
(if (eq? (caar options) get_option)
(cdar options)
(if (not (eq? (cdr options) '()))
(get-option-or-default (cdr options) get_option default)
default)))
(define (option-exists? options get_option)
(if (eq? (caar options) get_option)
#t
(if (not (eq? (cdr options) '()))
(option-exists? (cdr options) get_option)
#f)))
(define (directory-recurse dir)
(define (check-list files)
(define file (string-append dir "/" (car files)))
(define new_files (if (directory? file)
(directory-recurse file)
(list (cons (car files) file))))
(if (not (eq? (cdr files) '()))
(append new_files (check-list (cdr files)))
new_files))
(check-list (directory dir)))
;; Defaults
(define wallpaper_path_default
(string-append (get-shell-variable "HOME") "/Pictures/Wallpapers"))
(define delay_default "30")
;; Get options
(define options (parse-command-line
`((-help)
(-h)
(-wallpapers . path)
(-delay . string->number))))
(if (or (option-exists? options '-help) (option-exists? options '-h))
;; Show help
(print "usage: " (program-name) " [options]\n"
"\n"
" -help, -h\t\tShow this help\n"
" -wallpapers path\tWallpaper path, default: "
wallpaper_path_default "\n"
" -delay minutes\tDelay before setting new wallpaper, default"
delay_default)
;; Or begin program
(begin
;; Set variables
(set! wallpaper_path
(get-option-or-default options '-wallpapers wallpaper_path_default))
(set! delay_time (* 60
(string->number
(get-option-or-default options '-delay delay_default))))
(do () (#f)
;; Get list of wallpapers in path
(set! wallpapers (directory-recurse wallpaper_path))
(set! new_wallpaper (random-wallpaper wallpapers))
(set-wallpaper (cdr new_wallpaper))
(print "Set wallpaper: " (cdr new_wallpaper))
(send-notification (car new_wallpaper))
(process-sleep delay_time))))