#!/usr/bin/perl $arg = shift(@ARGV); if(!$arg){ $data = `gconftool-2 --all-dirs /apps/modest/accounts`; @accounts = split(/\n/, $data); print "\nPlease choose an account from the following list:\n"; print "(alternatively, pass an account name from below as a parameter to toggle it)\n\n"; for($i = 0; $i < ($#accounts + 1); $i++){ $thisAccount = $accounts[$i]; ($name) = $thisAccount =~ /accounts\/(.+?)ID/; $status = `gconftool-2 -g $thisAccount/enabled`; if($status =~ /true/i){ $currentState = "enabled"; } elsif($status =~ /false/i){ $currentState = "disabled"; } else{ $currentState = "state unknown"; } print "\t[".$i."] ".$name.": ".$currentState."\n"; } print "\nSelection [0-".($i - 1)." or [q]uit]: "; $id = <STDIN>; if($id =~ /^q/i){ exit(0); } print "\n"; if($id !~ /^\d+$/ || !$accounts[$id]){ print "Invalid selection.\n"; exit(1); } $path = $accounts[$id]; chomp($path); }else{ $path = "/apps/modest/accounts/".$arg."ID"; } $status = `gconftool-2 -g $path/enabled`; if($status =~ /true/i){ system("gconftool-2 -s ".$path."/enabled --type bool false"); if($? > 0){ print "The account could not be disabled.\n"; exit($?); } print "The account has been disabled.\n"; exit(0); }elsif($status =~ /false/i){ system("gconftool-2 -s ".$path."/enabled --type bool true"); if($? > 0){ print "The account could not be enabled.\n"; exit($?); } print "The account has been enabled.\n"; exit(0); }else{ print "The specified account could not be found.\n"; exit(1); }
~ $ perl modest-account.pl Please choose an account from the following list: (alternatively, pass an account name from below as a parameter to toggle it) [0] Home: enabled [1] Mail@32@for@32@Exchange: enabled [2] Work: enabled Selection [0-2 or [q]uit]: 1 The account has been disabled. ~ $ perl modest-account.pl Home The account has been disabled. ~ $ perl modest-account.pl Home The account has been enabled. ~ $