Pokemon-Terminal/scripter.py

58 lines
1.6 KiB
Python
Raw Normal View History

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
import os
2017-06-07 23:15:08 +00:00
import sys
import subprocess
2017-06-21 11:49:16 +00:00
from adapter import identify
osa_script_fmt = """tell application "System Events"
\ttell current desktop
\t\tset picture to "{}"
\tend tell
end tell"""
def __run_osascript(stream):
p = subprocess.Popen(['osascript'], stdout=subprocess.PIPE, stdin=subprocess.PIPE)
p.stdin.write(stream)
p.communicate()
p.stdin.close()
def __linux_create_wallpaper_script(image_file_path):
2017-06-08 02:52:10 +00:00
# If its gnome... aka GDMSESSION=gnome-xorg, etc.
if "gnome" in os.environ.get("GDMSESSION"):
fmt = 'gsettings set org.gnome.desktop.background picture-uri "file://{}"'
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)
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
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)
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
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))