From 4558a6284d3c0283855d9333f060d39d94e9d68b Mon Sep 17 00:00:00 2001 From: "andrew.vanderbye" Date: Thu, 21 Dec 2023 01:46:10 -0600 Subject: [PATCH] Initial Commit --- README | 19 +++++++++++++++++++ client.py | 7 +++++++ server.py | 23 +++++++++++++++++++++++ test.bat | 2 ++ 4 files changed, 51 insertions(+) create mode 100644 README create mode 100644 client.py create mode 100644 server.py create mode 100644 test.bat diff --git a/README b/README new file mode 100644 index 0000000..3158c01 --- /dev/null +++ b/README @@ -0,0 +1,19 @@ +# OSC-TO_SCRIPT +## GETTING STARTED +- Create directory for project to live in +- Drop Batch Files to execute into the project directory +- Navigate to this folder in terminal/command prompt +- Run the following commands +> \/python.exe -m venv venv +> +> \/venv/Scripts/activate.bat +> +> pip install python-osc + +To run the server: + +> "\/venv/Scripts/python.exe" "\/server.py" + +OR + +> "\/venv/Scripts/pythonw.exe" "\/server.py" diff --git a/client.py b/client.py new file mode 100644 index 0000000..2c8fe04 --- /dev/null +++ b/client.py @@ -0,0 +1,7 @@ +from pythonosc.udp_client import SimpleUDPClient + +ip = "127.0.0.1" +port = 1337 + +client = SimpleUDPClient(ip, port) # Create client +client.send_message("/script/test.bat", 123) # Send float message \ No newline at end of file diff --git a/server.py b/server.py new file mode 100644 index 0000000..9120376 --- /dev/null +++ b/server.py @@ -0,0 +1,23 @@ +from pythonosc.dispatcher import Dispatcher +from pythonosc.osc_server import BlockingOSCUDPServer + +import subprocess +from subprocess import Popen + +def default_handler(address, *args): + print(f"DEFAULT {address}: {args}") + +def run_script(address, *args): + script_to_run = address.split("/")[-1] + print(f"Script to run: {script_to_run}") + Popen(script_to_run,creationflags=subprocess.CREATE_NEW_CONSOLE) + +dispatcher = Dispatcher() +dispatcher.map("/script/*", run_script) +dispatcher.set_default_handler(default_handler) + +ip = "127.0.0.1" +port = 1337 + +server = BlockingOSCUDPServer((ip, port), dispatcher) +server.serve_forever() # Blocks forever \ No newline at end of file diff --git a/test.bat b/test.bat new file mode 100644 index 0000000..272316d --- /dev/null +++ b/test.bat @@ -0,0 +1,2 @@ +ECHO 'hooray' +PAUSE \ No newline at end of file