Search code examples
pythoneofnautilus

Running python scripts in nautilus


I have written a python script, made it executable and pasted it in

~/.local/share/nautilus/scripts

The problem is that my script needs some user inputs and while it does that, nautilus generates error saying

Enter your username: Traceback (most recent call last):
  File "/home/sumit/.local/share/nautilus/scripts/sms.py", line 30, in <module>
    username = input("Enter your username: ")
EOFError: EOF when reading a line

However the script works fine when I assign the variables in the program itself (without any user input).

How to make the script run for user inputs as well ?


Solution

  • Use zenity to get interactive user input (read more)

    #!/usr/bin/env python
    
    import subprocess
    
    def get_interactive_input(title, text):
        try:
            result =  subprocess.check_output(['zenity','--entry','--title={}'.format(title),'--text={}'.format(text)])
            return result.strip()
        except subprocess.CalledProcessError as e:
            return None
    
    
    def main():
        print get_interactive_input('asd', 'asdasd asdasd asdasdasd')
    
    
    main()
    

    enter image description here