4

Flux is nice application for those working on night time, it gives you warm color temperature on night time. I've been happily enjoying using it, link for anyone interested.

Color temperature changes on Flux started on 6PM, but rather than letting Flux modify my computer display I'd prefer turn the lights on.

This behavior makes me have to close the Flux manually, which is inconvenience.

Is there any way to make Flux only:

  • Launch between 8PM to 3AM
  • Stop between 3AM to 8PM
  • This looks like ma feature request. – userDepth Jan 16 '17 at 12:47
  • Can be done, but are you running the fluxgui indicator? – Jacob Vlijm Jan 16 '17 at 13:14
  • @JacobVlijm Yes, I'm using fluxgui. – Liso Jan 24 '17 at 0:03
5

First step : create the script

First let us create a script the will be run and would enable/disable flux depending on the time (I don't knot flux syntax, so adapt it for your need). You can note that here I suppose that you need to be root to run flux, but of course if you don't just run these steps as a classical user.

sudo mkdir -p /opt/flux/
sudo gedit /opt/flux/toogleFlux.sh

and put in it something like this

#!/usr/bin/env bash

h=$(date +%H)
start=20
stop=3
export DISPLAY=:0
if [ $h -ge $start ] || [ $h -lt $stop ] ; then
    # Start flux, give it any information you want, latitude...
    xflux -l 45
else
    # Stop flux
    killall xflux
fi

Then, make it executable :

sudo chmod +x /opt/flux/toogleFlux.sh

Second step : run it when needed

Now, you need to run it when needed. To to so, you can use a cron that would run it at 8:05 PM and 3:05 AM. But if you do so, if you open your computer at 8:10PM, it would not run it. The first solution is to use fcron, but I don't think it's packaged on distributions, so I'll use a combinaison of cron and a file that runs when you open a session.

To run this script with cron, run the following command. If you need to run it as root, add sudo before :

crontab -e

and then type :

05 20 * * * /opt/flux/toogleFlux.sh
05 3 * * * /opt/flux/toogleFlux.sh

now, you need to be sure that the script will run when you open your session. Depending on your GUI, you can configure it in your system settings, or sometimes putting this line in .profile will be enough (the xhost command is usefull to let the root user connect to the graphical interface) :

xhost +local:
/opt/flux/toogleFlux.sh

Now, run it toogleFlux.sh to enable it for the current session :

xhost +local:
/opt/flux/toogleFlux.sh

and enjoy flux !

| improve this answer | |
  • Most likely, just killing flux will leave the screen in colored mode. Also not quite sure if running from cron like this on the GUI won' t have issues. So the main question is: did you test? – Jacob Vlijm Jan 16 '17 at 13:25
  • The kill send a SIGTERM, not a SIGKILL so it is supposed to kill it smoothly, so that flux could revert it's configuration back. Moreover, since Liso says that when he stops flux manually it works, I don't see why here it would not work. Please try my solution, and if it does not work, explain what is see/expected, and we will look for another solution. – tobiasBora Jan 16 '17 at 13:37
  • ...That's why I asked him if he is using the indicator (gui) which does take care of it. killall flux does nothing on my system, let alone from cron, but it' s not my job to find out that this happens, nor why. No offense, but testing your stuff is essential. – Jacob Vlijm Jan 16 '17 at 13:41
  • The original question was about lanching program on specific time, and I answered that. Moreover, I do not want to install useless stuff on my system, especially when flux won't work on it. However, I tried and when I run it I have a message saying "Going to background: 'kill 18938' to turn off.". So running killall xflux should work. (note the x of xflux) – tobiasBora Jan 16 '17 at 14:32
  • While Killing xflux from crontab works (of course), but running xflux does not work like this (meaning: has no effect). The script will therefore fail. – Jacob Vlijm Jan 16 '17 at 14:43
2

I would like to share an alternative software that you can/should check, redshift (with its indicator redshift-gtk), I prefer it over flux for some reasons, foss, its on main repos, auto adjust color temp based on location/sunset time, easy manual settins (color temp, times...) , etc.

From author's page:

redshift example

You can simply run sudo apt install redshift-gtk on your terminal, and then launch it from Unity's dash. Also the indicator (a light bulb) has itself an option to make it autostart.

redshift indicator

Hope it helps.

UPDATE: As @JacobVlijm explained in comments (thanks for that), launching from cronjob seems to be not so simple as for non-GUI apps, so I changed my answer to simply show an alternative software solution.

| improve this answer | |
  • I don't want to seem cranky, but the combination of suggesting stuff you didn't try ("putting the command into a simple script and launch it from a cronjob", not working like this), and just thinking aloud, makes a bad answer. – Jacob Vlijm Jan 16 '17 at 14:55
  • @JacobVlijm Sorry for that, i thought it was better to point to tobiasBora's answer first as example (better direct answer to OP question) and all I wanted was to show an alternative which I think also solves OP question but not in the manner he's asking for. Should I remove my answer? – dgonzalez Jan 16 '17 at 15:09
  • @JacobVlijm answer updated, I would like to have your thought about this. Is now ok? I have no problems deleting a bad answer and I'd like to contribute, but doing things well. – dgonzalez Jan 16 '17 at 15:16
  • 2
    Thanks for editing @dgonzalez, but neither of the current answers will work. When running GUI stuff rom cron, you need to set the DISPLAY variable in any case, possibly also additional environment variables (when editing gsettings for example), since cron runs with a limited set of environment variables. That's why I think answers should always be tested before posting. Be sure btw I haven't the slightest doubts in your intentions, and appreciate your effort(s). – Jacob Vlijm Jan 16 '17 at 16:09
  • Answer updated. @JacobVlijm thanks for what I learned about cronjobs while walking the way ;) – dgonzalez Jan 16 '17 at 21:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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