To be able to execute system commands like notify-send
from within python scripts, you'll need to first import the os
module then use it to execute that system command like so:
import os
os.system('notify-send "Let\'s Take a Break!"')
That being said, you might need to pay attention to other syntax issues like the sleep 60
call that might work in bash
but python needs time.sleep(60)
and you might want to first import the time
module for that to work. Another thing is the indentation of if
... else
, you need to pay attention to that too.
Therefore, the example code in your question should be:
import os
import time
x = 1
count = x
while count <= 8:
os.system('notify-send "Let\'s Take a Break!"')
time.sleep(60)
count += 1
if count <= 8:
os.system('notify-send "Ok folks," "Let\'s get back to work!"')
time.sleep(3600)
else:
os.system('notify-send "Ok folks," "Let\'s call it a day!"')
It is very important as well to correctly run your python script with python
and not other interpreters like e.g. bash
as I understand from this(which is most likely run by your shell e.g. bash
and not the python
interpreter):
When I run a simple .py file with code
notify-send " ha ha "
I get notifications in 22.04 without any issues.