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?

share|improve this question
#!/bin/env python
import os
cmd1 = "sleep 50"
cmd2 = "xrandr --output VGA1 --gamma 1.28:1:1.28"   
os.system(cmd1)
os.system(cmd2)
share|improve this answer
    
Note that those two system()s will invoke one shell each, so it will run one additional shell command and one python command compared to the bash script. – Stéphane Chazelas Jan 1 '16 at 15:08
    
It is just for demo purpose , how to do it in python , there are lots of other options , and optimizations. – Ijaz Khan Jan 1 '16 at 15:18

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:

  • getoutput - will run the command and return the output
  • getstatusoutput - will run the command and return the status code and the output
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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