[Python] Close terminal window opened by .command python script?

Discussão em 'Python' iniciado por Stack, Agosto 2, 2025.

  1. Stack

    Stack Membro Participativo

    What I am trying to achieve: I have a really simple python script. I'd like to double click a file on my desktop (macos) to run a python script (works great). I'd like the terminal window opened by running the script to close (not working).

    To start, I changed the file extension of my script from .py => .command and gave it the following permissions: 'chmod a+x file.py'

    Here is the sample python script:

    #!/usr/bin/env python

    # this worked!
    # https://stackoverflow.com/questions/5125907/how-to-run-a-shell-script-in-os-x-by-double-clicking
    # chmod a+x filename
    # .command
    # https://nordvpn.com/blog/macos-cannot-verify-this-app-is-free-from-malware/
    # xattr -d com.apple.quarantine filepath

    from time import sleep
    from selenium import webdriver
    from selenium.webdriver.common.by import By
    import os

    service = webdriver.ChromeService(executable_path = '/usr/local/bin/chromedriver')
    driver = webdriver.Chrome(service=service)

    driver.get("https://google.com/")

    sleep(3)


    This is working nicely, however, when the terminal window opens to run, it does not close itself.

    I'd like the terminal window to close after completion. Right now it just says '[Process Completed]' but doesn't close the actual terminal window.

    I've tried 'quit()' and 'exit()'

    [​IMG]

    Continue reading...

Compartilhe esta Página