This is how I got it to work as intended: 1. Install Fastscripts 2. Set up an Applescript, which looks like this: > on run > -- Copy the currently selected text to the clipboard > tell application "System Events" > keystroke "c" using {command down} > delay 0.5 -- Wait for the data to be available > end tell > > -- Get the selected text from the clipboard > set selectedText to (the clipboard as text) > > -- Call the Python script and pass the selected text > set translatedText to do shell script "echo " & quoted form of > selectedText & " | > /Library/Frameworks/Python.framework/Versions/3.11/bin/python3 > /PATH/TO/MY/SCRIPT/DK_openAi.py" > > -- Put the translated text back into the clipboard > set the clipboard to translatedText > > -- Paste the translated text > tell application "System Events" > keystroke "v" using {command down} > end tell > end run - REPLACE THE PATH TO THE PYTHON ("/Library/Frameworks/Python.framework/Versions/3.11/bin/python3") WITH YOUR PATH - REPLACE THE PATH ("/PATH/TO/MY/SCRIPT/DK_openAi.py")TO WHERE YOU STORE THE PYTHON SCRIPT 3.Set up a python script that looks like this: import openai import sys # Read the API key openai.api_key = 'YOUR-API-KEY' # Get the selected text selected_text = sys.stdin.read().strip() # Call the OpenAI API to translate the text model = "gpt-3.5-turbo" language = "Danish" response = openai.ChatCompletion.create( model=model, messages=[ { "role": "user", "content": f"Translate the following text to {language} without changing the formatting: {selected_text}", } ] ) # Grabs the response from the API and strips it of leading/trailing newlines translated_text = response["choices"][0]["message"]["content"].strip() # Replace the selected text with the translated text print(translated_text, end="") - Replace "YOUR-API_KEY" with your API key and save according to the path defined 4.Set-up shortcuts to run the apple scripts via Fastscripts