Skip to content

Instantly share code, notes, and snippets.

@goerz
Created September 3, 2009 19:07
Show Gist options
  • Save goerz/180474 to your computer and use it in GitHub Desktop.
Save goerz/180474 to your computer and use it in GitHub Desktop.
insomnia: CLI interface to InsomniaX
#!/usr/bin/perl
use strict;
# Author: Michael Goerz <[email protected]>
# Make sure that $kextfile is owned by root!
my $app = '/Applications/InsomniaX.app';
my $kextfile = "$app/Contents/Resources/Insomnia_r6.kext/";
sub close_insomnia_x{
my $ps_line = `ps -A | grep $app | grep -v grep`;
if ($ps_line =~ /^([0-9]+)\s/){
my $pid = $1;
system("kill $pid");
}
}
sub start_insomnia_x{
system("open $app");
}
if (length(@ARGV) > 0){
if (($ARGV[0] eq 'start') or ($ARGV[0] eq 'load') or ($ARGV[0] eq 'on')){
print "starting...\n";
close_insomnia_x();
system("sudo kextload $kextfile");
start_insomnia_x();
}
if (($ARGV[0] eq 'stop') or ($ARGV[0] eq 'unload') or ($ARGV[0] eq 'off')){
print "stopping...\n";
system("sudo kextunload $kextfile");
close_insomnia_x();
}
if ($ARGV[0] eq 'show'){
start_insomnia_x();
}
if ($ARGV[0] eq 'hide'){
close_insomnia_x();
}
}
my $kextstat = `kextstat | grep insomnia`;
if ($kextstat =~ /org.binaervarianz.*insomnia/){
print("Insomnia is loaded\n");
} else {
print("Insomnia is NOT loaded\n");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment