0

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?

2 Answers 2

1
#!/bin/env python
import os
cmd1 = "sleep 50"
cmd2 = "xrandr --output VGA1 --gamma 1.28:1:1.28"   
os.system(cmd1)
os.system(cmd2)
2
  • 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. Commented Jan 1, 2016 at 15:08
  • It is just for demo purpose , how to do it in python , there are lots of other options , and optimizations. Commented Jan 1, 2016 at 15:18
0

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

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.