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-04-28 07:46:39 +00:00
|
|
|
|
2017-06-06 20:53:55 +00:00
|
|
|
cwd = os.path.dirname(os.path.realpath(__file__))
|
|
|
|
|
2017-04-28 07:46:39 +00:00
|
|
|
|
2017-06-11 19:30:23 +00:00
|
|
|
def __terminal_script(path):
|
2017-04-28 07:46:39 +00:00
|
|
|
# Create the content for script that will change the terminal background image.
|
|
|
|
content = "tell application \"iTerm\"\n"
|
|
|
|
content += "\ttell current session of current window\n"
|
2017-06-11 19:30:23 +00:00
|
|
|
content += "\t\tset background image to \"" + path + "\"\n"
|
2017-04-28 07:46:39 +00:00
|
|
|
content += "\tend tell\n"
|
|
|
|
content += "end tell"
|
|
|
|
return content
|
|
|
|
|
|
|
|
|
|
|
|
def __wallpaper_script(pokemon):
|
|
|
|
# Create the content for the script that will change the wallpaper.
|
|
|
|
content = "tell application \"System Events\"\n"
|
|
|
|
content += "\ttell current desktop\n"
|
|
|
|
content += "\t\tset picture to \"" + pokemon.get_path() + "\"\n"
|
|
|
|
content += "\tend tell\n"
|
|
|
|
content += "end tell"
|
|
|
|
return content
|
|
|
|
|
|
|
|
|
2017-06-07 23:15:08 +00:00
|
|
|
def __iterm2_create_terminal_script(pokemon):
|
2017-04-28 07:46:39 +00:00
|
|
|
# Create and save the script for changing the terminal background image.
|
2017-06-11 19:30:23 +00:00
|
|
|
content = __terminal_script(pokemon.get_path())
|
|
|
|
file = open(cwd + "/./Scripts/background.scpt", "wb")
|
|
|
|
file.write(bytes(content, 'UTF-8'))
|
|
|
|
file.close()
|
|
|
|
|
|
|
|
|
|
|
|
def __iterm2_clear_script():
|
|
|
|
# Create and save the script for clearing the terminal background image.
|
|
|
|
content = __terminal_script("")
|
2017-06-06 20:53:55 +00:00
|
|
|
file = open(cwd + "/./Scripts/background.scpt", "wb")
|
2017-04-28 07:46:39 +00:00
|
|
|
file.write(bytes(content, 'UTF-8'))
|
|
|
|
file.close()
|
|
|
|
|
|
|
|
|
2017-06-08 02:30:27 +00:00
|
|
|
def __darwin_create_wallpaper_script(pokemon):
|
2017-04-28 07:46:39 +00:00
|
|
|
# Create and save the script for changing the wallpaper.
|
|
|
|
content = __wallpaper_script(pokemon)
|
2017-06-06 20:53:55 +00:00
|
|
|
file = open(cwd + "/./Scripts/wallpaper.scpt", "wb")
|
2017-04-28 07:46:39 +00:00
|
|
|
file.write(bytes(content, 'UTF-8'))
|
|
|
|
file.close()
|
|
|
|
|
|
|
|
|
2017-06-07 23:15:08 +00:00
|
|
|
def __darwin_create_terminal_bash():
|
2017-04-28 07:46:39 +00:00
|
|
|
# Create and save the run.sh that will execute the AppleScript if the correct run.sh doesn't already exist.
|
2017-06-06 20:53:55 +00:00
|
|
|
content = "#!/bin/bash\n" + "osascript " + cwd + "/./Scripts/background.scpt"
|
|
|
|
if open(cwd + "/./Scripts/run.sh", 'r').read() == content:
|
2017-04-28 07:46:39 +00:00
|
|
|
return
|
2017-06-06 20:53:55 +00:00
|
|
|
file = open(cwd + "/./Scripts/run.sh", 'wb')
|
2017-04-28 07:46:39 +00:00
|
|
|
file.write(bytes(content, 'UTF-8'))
|
|
|
|
file.close()
|
|
|
|
|
|
|
|
|
2017-06-08 02:52:10 +00:00
|
|
|
# Create and save the run.sh that will execute the AppleScript if the correct run.sh
|
|
|
|
# doesn't already exist.
|
2017-06-08 02:30:27 +00:00
|
|
|
def __darwin_create_wallpaper_bash():
|
2017-06-06 20:53:55 +00:00
|
|
|
content = "#!/bin/bash\n" + "osascript " + cwd + "/./Scripts/wallpaper.scpt"
|
|
|
|
if open(cwd + "/./Scripts/run.sh", 'r').read() == content:
|
2017-04-28 07:46:39 +00:00
|
|
|
return
|
2017-06-06 20:53:55 +00:00
|
|
|
file = open(cwd + "/./Scripts/run.sh", 'wb')
|
2017-04-28 07:46:39 +00:00
|
|
|
file.write(bytes(content, 'UTF-8'))
|
|
|
|
file.close()
|
|
|
|
|
|
|
|
|
|
|
|
def change_terminal(pokemon):
|
2017-06-07 23:15:08 +00:00
|
|
|
if sys.platform == "darwin":
|
2017-06-08 02:52:10 +00:00
|
|
|
# Create, save and run the bash script to change the terminal background.
|
2017-06-07 23:15:08 +00:00
|
|
|
__iterm2_create_terminal_script(pokemon)
|
|
|
|
__darwin_create_terminal_bash()
|
|
|
|
os.system(cwd + "/./Scripts/run.sh")
|
|
|
|
if sys.platform == "linux":
|
|
|
|
os.system(__linux_create_terminal(pokemon))
|
|
|
|
|
2017-06-11 19:30:23 +00:00
|
|
|
|
2017-06-07 23:15:08 +00:00
|
|
|
def __linux_create_terminal(pokemon):
|
|
|
|
if os.environ.get("TERMINOLOGY") == '1':
|
2017-06-08 02:52:10 +00:00
|
|
|
return "tybg \"" + pokemon.get_path() + "\""
|
2017-06-12 10:48:16 +00:00
|
|
|
elif "TILIX_ID" in os.environ:
|
|
|
|
return "gsettings set com.gexperts.Tilix.Settings background-image " + \
|
|
|
|
"\""+ pokemon.get_path()+"\""
|
2017-06-07 23:15:08 +00:00
|
|
|
else:
|
2017-06-08 02:52:10 +00:00
|
|
|
print("Terminal emulator not supported")
|
2017-06-07 23:15:08 +00:00
|
|
|
exit(1)
|
2017-04-28 07:46:39 +00:00
|
|
|
|
2017-06-11 19:30:23 +00:00
|
|
|
|
|
|
|
def __linux_clear_terminal():
|
|
|
|
if os.environ.get("TERMINOLOGY") == '1':
|
|
|
|
return "tybg"
|
2017-06-14 06:57:26 +00:00
|
|
|
elif "TILIX_ID" in os.environ:
|
|
|
|
return "gsettings reset com.gexperts.Tilix.Settings background-image"
|
2017-06-11 19:30:23 +00:00
|
|
|
else:
|
|
|
|
print("Terminal emulator not supported")
|
|
|
|
exit(1)
|
|
|
|
|
|
|
|
|
2017-04-28 07:46:39 +00:00
|
|
|
def change_wallpaper(pokemon):
|
2017-06-08 02:30:27 +00:00
|
|
|
if sys.platform == "darwin":
|
|
|
|
# Create, save and run the bash script to change the wallpaper.
|
|
|
|
__darwin_create_wallpaper_script(pokemon)
|
|
|
|
__darwin_create_wallpaper_bash()
|
|
|
|
os.system(cwd + "/./Scripts/run.sh")
|
|
|
|
if sys.platform == "linux":
|
2017-06-11 19:30:23 +00:00
|
|
|
os.system(__linux_create_wallpaper_script(pokemon))
|
|
|
|
|
|
|
|
|
|
|
|
def clear_terminal():
|
|
|
|
if sys.platform == "darwin":
|
|
|
|
__iterm2_clear_script()
|
|
|
|
__darwin_create_terminal_bash()
|
|
|
|
os.system(cwd + "/./Scripts/run.sh")
|
|
|
|
if sys.platform == "linux":
|
|
|
|
os.system(__linux_clear_terminal())
|
2017-04-28 23:17:44 +00:00
|
|
|
|
2017-06-11 19:30:23 +00:00
|
|
|
|
|
|
|
def __linux_create_wallpaper_script(pokemon):
|
2017-06-08 02:52:10 +00:00
|
|
|
# If its gnome... aka GDMSESSION=gnome-xorg, etc.
|
|
|
|
if os.environ.get("GDMSESSION").find("gnome") >= 0:
|
|
|
|
return "gsettings set org.gnome.desktop.background picture-uri " + \
|
|
|
|
"\"file://"+ pokemon.get_path()+"\""
|
2017-06-08 02:30:27 +00:00
|
|
|
#elif condition of KDE...
|
|
|
|
else:
|
2017-06-08 02:52:10 +00:00
|
|
|
print("Window manager not supported ")
|
2017-06-08 02:30:27 +00:00
|
|
|
exit(1)
|