Search code examples
linuxgnomexterm

Run a Python script when opening Terminal(xterm)


Is there a way I can run a Python3 script while I open xterm?

What I want to do:
I want to create a ToDo list, which runs on startup of xterm (should be able to use ArgParse)

OS
I use gentoo = a unix/linux distro --> gnome3(X.org)

My research
I didn't find any solution, there were only results, where people wanted to start the Python interactive mode and not a solution to my problem (the way around)


Solution

  • You can try to use an alias, that is modify your .bashrc and add the next line:

    my_alias='xterm -e /path/to/script/ /path/to/todo_script'
    

    Where script file is the following script:

    #!/bin/sh
    "$@"
    exec "$SHELL"
    

    And todo_script is the script that you want to execute. For example, if todo_script contains

    #!/bin/sh
    echo "Hello World"
    

    If you execute my_alias, it will show Hello World in a new xterm terminal.