Skip to content

Instantly share code, notes, and snippets.

@mikoloism
Created February 12, 2022 15:05
Show Gist options
  • Save mikoloism/5a51fb03a4e3ac792a40a6d9195b1275 to your computer and use it in GitHub Desktop.
Save mikoloism/5a51fb03a4e3ac792a40a6d9195b1275 to your computer and use it in GitHub Desktop.
Python script to change automatically background wallpaper of the OS in time interval (each minute or you can change it)
#!/usr/bin/env python3
import time
import os
# home path to user
user_home = os.environ["HOME"]
# setp - 1
os.system('clear')
# define default value for variable
t = time.time()
# input user path and step
wp_folder = '/media/admin/EXTERNAL/App/Both/wallpapers/'
# # folder_temp = input("Enter folder path: (e.g. /path/folder/) ")
# # if folder_temp != '':
# wp_folder = folder_temp
# time change step
# if not time_change = int(input("Enter time to change (e.g. 1=1minute | default=60minute) : ")):
# time_change = 60
# else:
# time_change = time_change*60
time_change = 3600
# variables
dash = "---------"*5
item_len = 345
index = 0
# process on step at minute to second
# # time_change = time_change * 60
# process on file to find image list in path
os.system("find '{0}' | grep -i --regexp=\"jpg\|png\"$ > ~/.wp_list.txt".format(wp_folder))
# open list file
file_list = open('{0}/.wp_list.txt'.format(user_home), 'r')
# getting file items length
# # for item_list in file_list.readlines():
# # item_len = item_len + 1
for item in file_list.readlines():
# show information
index = index + 1
print("setting ---> {0}".format(item))
print("\t({0}/{1})".format(item_len, index))
print("{0}{1}".format(dash, dash))
# change to setting
img = str(item[0:-1])
if not img.endswith('g'):
img = img + 'g'
os.system('gsettings set org.gnome.desktop.background picture-uri "'+ img +'"')
# doing sleep
try:
time.sleep(time_change - ((time.time() - t) % time_change))
except ValueError:
time.sleep(3600)
# finished items list
print("Done!")
os.system('notify-send "Bash Terminal (wp_change) : " "{0}"'.format("Item has Done!"))
print("\a\n")
# input("Press <ENTER> to close...")
exit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment