Run Python script using AppleScript

Much better & faster than programatically open an Terminal window and copying/pasting commands.

#!/bin/bash
osascript -e 'tell application "Terminal" to do script "source /path/to/project/folder/venv/bin/activate && python3 /path/to/project/folder/test.py"'

or as part of a Python script:

import os

os.system('osascript -e \'tell application "Terminal" to do script "source /path/to/project/folder/venv/bin/activate && python3 /path/to/project/folder/test.py"\'')

links

social