Created
September 13, 2022 22:47
-
-
Save 0187773933/151b6ca1ff2e9ba9361dcc58f3e87e92 to your computer and use it in GitHub Desktop.
Python Script to Trigger Mac OSX Toast Notification
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import sys | |
import os | |
import json | |
import subprocess | |
import requests | |
import pyperclip | |
def read_json( file_path ): | |
with open( file_path ) as f: | |
return json.load( f ) | |
def write_json( file_path , python_object ): | |
with open( file_path , 'w', encoding='utf-8' ) as f: | |
json.dump( python_object , f , ensure_ascii=False , indent=4 ) | |
def run_bash_command( options ): | |
try: | |
result = subprocess.run( options , cwd=os.getcwd() , shell=False , capture_output=True , universal_newlines=True ) | |
if result.returncode != 0: | |
return result.stderr | |
else: | |
print( result.stdout ) | |
return result.stdout | |
except Exception as e: | |
print( e ) | |
return False | |
if __name__ == "__main__": | |
print( run_bash_command( [ "bash" , "-c" , f"osascript -e 'display notification \"{sys.argv[1]}\" with title \"sys.argv[1] =\" '" ] ) ) | |
write_json( "/Users/morpheous/TMP2/testasdf34134.json" , { "one": sys.argv[ 1 ] , "two": sys.argv[ 2 ] } ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment