I want to change display color.
I have a simple script:
#!/bin/bash
sleep 50
xrandr --output VGA1 --gamma 1.28:1:1.28 # for purple
How can I write it in python?
#!/bin/env python
import os
cmd1 = "sleep 50"
cmd2 = "xrandr --output VGA1 --gamma 1.28:1:1.28"
os.system(cmd1)
os.system(cmd2)
system()s will invoke one shell each, so it will run one additional shell command and one python command compared to the bash script.
Using commands module (Preferred):
from commands import getoutput
getoutput('sleep 50; xrandr --output VGA1 --gamma 1.28:1:1.28')
Using os.system module:
import os
os.system('sleep 50; xrandr --output VGA1 --gamma 1.28:1:1.28')
os.system will shell out and run the command without a way to capture the output. Avoid using this, even if you don't care about the output, the commands module is much better.
commands has two methods that can run and return the output: