A variety of simple automation scripts and enhancements to Sway and i3.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

43 lines
894B

  1. #!/usr/bin/perl
  2. # TODO: If gammastep is already running, allow location to update
  3. use strict;
  4. use warnings;
  5. use LWP::UserAgent;
  6. use JSON::XS;
  7. my $ua = LWP::UserAgent->new();
  8. my $json = JSON::XS->new();
  9. my $location = "https://papillon.john.me.tz/data/location.json";
  10. my $lat_lon = fetch_lat_lon($ua, $json, $location);
  11. my $pid = fork;
  12. unless ($pid) {
  13. open STDIN, '/dev/null';
  14. open STDOUT, '>>/dev/null';
  15. open STDERR, '>>/dev/null';
  16. `gammastep -l $lat_lon`;
  17. }
  18. sub fetch_lat_lon {
  19. my ($ua, $json, $location) = @_;
  20. my $raw = $ua->get($location)->content();
  21. if (defined $raw) {
  22. my $decoded = $json->decode($raw);
  23. if (defined $decoded->{lat} && defined $decoded->{lon}) {
  24. return "$decoded->{lat}:$decoded->{lon}";
  25. }
  26. print $decoded->{lat};
  27. }
  28. sleep 5;
  29. return fetch_lat_lon($ua, $json, $location);
  30. }
  31. exit;