-1

How do I close programs on mac using python?

I want something like this:

import os

process_name = "GoogleChrome"
os.system(f"end_process {process_name}")
1
  • try killall Chrome Commented Jan 18, 2024 at 4:01

1 Answer 1

1

you can use the osascript command with AppleScript to close or quit applications try this

import os

def end_process(process_name):
    applescript = f'tell application "{process_name}" to quit'
    os.system(f"osascript -e '{applescript}'")


if __name__ == "__main__":
    process_name = "Google Chrome"
    end_process(process_name)
Sign up to request clarification or add additional context in comments.

3 Comments

how do I get the process name? Is there a command that shows all process name? Because I'm not sure if that is google's process name.
if you want to know process name using this in powershell "ps -ax -o comm" This command displays a list of all running processes along with their names
Or in python ``` import os def get_application_process_names(): # Use the 'ps' command to get process names associated with terminal sessions ps_command = 'ps -cx -o comm' process_names = os.popen(ps_command).read().strip().split('\n')[1:] return process_names if name == "main": application_process_names = get_application_process_names() print("Running application process names:") for process_name in application_process_names: print(process_name) ```

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.