Pokemon-Terminal/scripter.py

50 lines
1.3 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):
adapter = identify()
adapter.set_pokemon(image_file_path)
def change_wallpaper(image_file_path):
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))