The following Python script is extracted from /usr/lib/python2.7/dist-packages/Mailnag/plugins/libnotifyplugin.py
In the script, the command ('zenity --info --text="You got new mail"') is not run. How do I make it run? I want it to run when mail_count > 0
The lines under if mail_count > 1: are run properly.

if mail_count > 0:
    import os
    os.system('zenity --info --text="You got new mail"')   

if mail_count > 1:
    summary = _("{0} new mails").format(str(mail_count))
    if (mail_count - i) > 1:
        body = _("from {0} and others.").format(senders)
        body = _("from {0}.").format(senders)
    summary = _("New mail")
    body = _("from {0}.").format(senders)

I put the following "Testing.py" script into /usr/lib/python2.7/dist-packages/Mailnag/plugins/Testing.py and ran it, which did bring up the "You got new mail" message.

#!/usr/bin/env python2
import os
os.system('zenity --info --text="You got new mail"')
  • I just edited my question. Please read it again. Apr 5 '19 at 8:54
  • 1
    OK, that changes your question substantially, which isn’t really how this site works, but whatever. Are you sure your formatting accurately represents the indentation of your Python script? When you say the Zenity command isn’t run, what happens instead? What’s the return value of os.system? Apr 5 '19 at 9:08

As you don't need to capture the output of the sys command, os.system is just fine.
As your posted code seems to be fine, try to guess if the zenity command you run is available at the path, where you run the python script.

Just to check that your output works, you could:

if mail_count > 0:
    import os
    result = os.system('echo "more than 0" > testfile')
    if result == 0:
        print("a testfile was created")

If that command generates the testfile, you know your issue is on zenity side.

It is a good practice, import sentences are better placed at the beginning of the file, when possible.

  • @ Evhz, I added your lines into the script and tried again. No "testfile" was generated although my account does have new mail. FYI, the script is extracted from /usr/lib/python2.7/dist-packages/Mailnag/plugins/libnotifyplugin.py. Should I post the complete script here? It is a long script. Apr 5 '19 at 12:15
  • it looks, the user running the python script, does not have write permissions on the folder you use as output. It could be, the user has no rights or visibility to the zenity command. Check which user runs your script and everything regarding files and folders visibility for it.
    – Evhz
    Apr 5 '19 at 12:22
  • I am the only user on my Linux MInt. I have every right to run any commands. I just added something at the bottom of my question. Apr 5 '19 at 12:37

Not the answer you're looking for? Browse other questions tagged or ask your own question.