2017-04-29 05:57:47 +00:00
|
|
|
# Used for creating, running and analyzing applescript and bash scripts.
|
2017-04-28 22:26:00 +00:00
|
|
|
|
2017-04-28 07:46:39 +00:00
|
|
|
import os
|
2017-06-07 23:15:08 +00:00
|
|
|
import sys
|
2017-06-21 13:22:11 +00:00
|
|
|
import subprocess
|
2017-04-28 07:46:39 +00:00
|
|
|
|
2017-06-21 11:49:16 +00:00
|
|
|
from adapter import identify
|
|
|
|
|
2017-06-22 05:31:23 +00:00
|
|
|
osa_script_fmt = """tell application "System Events"
|
|
|
|
\ttell current desktop
|
|
|
|
\t\tset picture to "{}"
|
|
|
|
\tend tell
|
|
|
|
end tell"""
|
|
|
|
|
2017-04-28 07:46:39 +00:00
|
|
|
|
2017-06-21 13:22:11 +00:00
|
|
|
def __run_osascript(stream):
|
|
|
|
p = subprocess.Popen(['osascript'], stdout=subprocess.PIPE, stdin=subprocess.PIPE)
|
|
|
|
p.stdin.write(stream)
|
|
|
|
p.communicate()
|
|
|
|
p.stdin.close()
|
2017-04-28 07:46:39 +00:00
|
|
|
|
|
|
|
|
2017-07-03 14:32:28 +00:00
|
|
|
def __linux_create_wallpaper_script(image_file_path):
|
2017-06-08 02:52:10 +00:00
|
|
|
# If its gnome... aka GDMSESSION=gnome-xorg, etc.
|
2017-06-22 05:31:23 +00:00
|
|
|
if "gnome" in os.environ.get("GDMSESSION"):
|
|
|
|
fmt = 'gsettings set org.gnome.desktop.background picture-uri "file://{}"'
|
2017-07-03 14:32:28 +00:00
|
|
|
return fmt.format(image_file_path)
|
|
|
|
# elif condition of KDE...
|
2017-06-08 02:30:27 +00:00
|
|
|
else:
|
2017-06-08 02:52:10 +00:00
|
|
|
print("Window manager not supported ")
|
2017-06-08 02:30:27 +00:00
|
|
|
exit(1)
|
2017-07-03 14:32:28 +00:00
|
|
|
|
|
|
|
|
|
|
|
def clear_terminal():
|
|
|
|
adapter = identify()
|
|
|
|
adapter.clear()
|
|
|
|
|
|
|
|
|
|
|
|
def change_terminal(image_file_path):
|
2017-07-04 13:20:11 +00:00
|
|
|
if not isinstance(image_file_path, str):
|
|
|
|
print("A image path must be passed to the change terminal function.")
|
|
|
|
return
|
2017-07-03 14:32:28 +00:00
|
|
|
adapter = identify()
|
2017-07-04 01:35:46 +00:00
|
|
|
if adapter is None:
|
|
|
|
print("Terminal not supported")
|
|
|
|
adapter.set_image_file_path(image_file_path)
|
2017-07-03 14:32:28 +00:00
|
|
|
|
|
|
|
|
|
|
|
def change_wallpaper(image_file_path):
|
2017-07-04 13:20:11 +00:00
|
|
|
if not isinstance(image_file_path, str):
|
|
|
|
print("A image path must be passed to the change wallpapper function.")
|
|
|
|
return
|
2017-07-03 14:32:28 +00:00
|
|
|
if sys.platform == "darwin":
|
|
|
|
script = osa_script_fmt.format(image_file_path)
|
|
|
|
__run_osascript(str.encode(script))
|
|
|
|
elif sys.platform == "linux":
|
|
|
|
os.system(__linux_create_wallpaper_script(image_file_path))
|