Skip to content
This repository was archived by the owner on May 25, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
## Set a Random desktop background

This script will download a random image from [unsplash](https://source.unsplash.com/random) and set it as the desktop background.

**The image will be saved as "random.jpg" makesure that there are no files saved as "random.jpg" in the current directory**

### Requirements

#### Linux

Install [Nitrogen](https://wiki.archlinux.org/index.php/Nitrogen)

```
pip install requests
```

### Usage

```python
python background_linux.py
```
OR

```python
python background_windows.py
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
from requests import get # to make GET request
from os import system, getcwd, path


url = "https://source.unsplash.com/random"
filename = "random.jpg"


def download(url, file_name):
'''
downloading the file and saving it
'''
with open(file_name, "wb") as file:
response = get(url)
file.write(response.content)


def setup(pathtofile):
'''
setting the up file
'''
system("nitrogen --set-auto {}".format(path.join(getcwd(), pathtofile)))


if __name__ == "__main__":
download(url, filename)
setup(filename)
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
from requests import get
import os
import ctypes
import argparse
import sys

url = "https://source.unsplash.com/random"
filename = "random.jpg"

def is_64bit():
return sys.maxsize > 2 ** 32


def download(url, file_name):
'''
downloading the file and saving it
'''
with open(file_name, "wb") as file:
response = get(url)
file.write(response.content)


def setup(pathtofile,version):
name_of_file = pathtofile
path_to_file = os.path.join(os.getcwd(), name_of_file)
SPI_SETDESKWALLPAPER = 20
if is_64bit():
ctypes.windll.user32.SystemParametersInfoW(SPI_SETDESKWALLPAPER, 0, path_to_file, 0)
else:
ctypes.windll.user32.SystemParametersInfoA(SPI_SETDESKWALLPAPER, 0, path_to_file, 0)


if __name__ == "__main__":
try:
download(url, filename)
setup(file_name)
except Exception as e:
print(f"Error {e}")
raise NotImplementedError