MegaSack DRAW - This year's winner is user - rgwb
We will be in touch
I want to set up a script for activating external monitors (don't ask.. just.. don't...) and bind it to the external monitor hotkey on my laptop (or some other perhaps, whatever).
There's a script to enable and a script to disable, but there's only one key of course so it needs to toggle. So then I need to know if the monitor's enabled or disabled.
I thought the easiest way would be to echo something like 'ON' to a file when I enable and 'OFF' when I disable. I tried echo "ON" >> file but for some reason I get permission denied, even though I use sudo, and sudo vi file works fine, I have permission.
Also - simply echoing to that file will just append - how to replace the file contents?
Actually though - thinking about it - if the system crashes or reboots - the file will still contain 'ON' even when the monitor defaults to disabled.. so perhaps I can use ps and what.. awk or something.. to check the presence of the second X server...
Just create a new file and test for it's existence with your enable/disable script. Just touch an empty file called "monitor" or something, and have your script rename it accordingly when toggled - monitor.on and monitor.off or something
>> to append, > to overwite I think BTW
I think $DISPLAY should hold the info you want.
Or xset q
Thanks folks.
The external monitor config requires me to start a second X server. It shows up differently in the output of ps, so maybe I should just use.. grep?
ps -ef | grep <X_SERVER_PROCESS_NAME> | grep -v grep
echo $? will return 0 if it was found, and 1 if it wasn't.
So in a shell script.. if <backwards apostrophe> grep gubbins <backwards apostrophe> != '' then ..?
Or whatever the hell the syntax is..
[code]if [ <backwards apostrophe>ps -ef | grep <XSERVERNAME> | grep -v grep<backwards apostrophe> ]
then
echo "it's running!"
else
echo "it's not running!"
fi[/code]
echo "cheers" >> verses
Obviously not relevant now, but;
I tried echo "ON" >> file ...
Also - simply echoing to that file will just append - how to replace the file contents?
>> appends
> overwrites
Can you use xrandr? It outputs information about the attached displays.
$ xrandr
Screen 0: minimum 320 x 200, current 1680 x 1050, maximum 8192 x 8192
DVI-I-1 connected 1680x1050+0+0 (normal left inverted right x axis y axis) 474mm x 296mm
etc.
EDIT: no, you can't as it won't tell the on/off state of the monitor, just the display settings.
Nostalgic stuff.
SCO Openserver FTW!
No, the ps grep command definitely works. I'm just farting about with basic commands.
Verses' thing is right but I seem to be having syntactical problems...
#!/bin/bash
if [ ps -ef | grep "Xorg :8" | grep -v grep ]
then echo "Not running"
else
echo "Running"
fi
./test.sh: line 2: [: too many arguments
Running
EDIT.. ooh.. I think I see what's going on. It's evaluating the ps command and substituting it into the script.. that's not what I want
SCO openserver is utterly completely pants.
With badly-fitted knickers on.
need some backticks i think
edit: oh they were probably there but made the forum s/w freak out
I think you can do something like
result=$( ps -ef | grep "Xorg :8" | grep -v grep )
if [ $result ]
then echo "running";
else
echo "not running";
fi
Also, can't you set a global environmental variable instead of grep hackery?
E.g.
if [ $MONITOR_ON = true ]
export MONITOR_ON=false;
else
export MONITOR_ON=true;
fi
I don't know whether that works though I'm a bit rusty (EDIT: I just tried it actually and it only works in the terminal you run it in. As you were...)
Right, it needed both single backwards and double quotes around the ps bit.
However.. whilst it's running my script properly, the program I actually need to run crashes when run via this hotkey, but not when run via a shell.
Dear nVidia.. please develop proper Optimus support for Linux. Thanks, annoyed of Cardiff.
Pff.. can't get it to work via hotkey.. too hard, not enough benefit.
That's the spirit!
Something like Autokey might work? Define 2 different keys for toggling the monitor on/off?
https://code.google.com/p/autokey/
Guessing the script is being run sudo?
Hotkey binding in the Desktop Environment probably can't allow that (how do you put passwd in?)
Probably need to change owner or group to root or whatever X is arunning as, and set the setuid/setgid bits on the file, to make it run as a user with sufficient privilege?
could be talking BS though
You don't need to use setuid anymore, that's soooo 1990s.
sudo FTW!
Add a line like this to /etc/sudoers.conf
youruserid ALL=(ALL) NOPASSWD: /usr/bin/yourcommand
