View Single Post
Posts: 17 | Thanked: 17 times | Joined on Aug 2008 @ Portsmouth UK
#22
I've written another version of TiagoTiago's script in Perl, with both a simple menu for selection and the ability to pass an account with a parameter.

Code:
#!/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);
}
Example:
Code:
~ $ 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. 
~ $
If I can ever be bothered to learn Python/Qt, I might make this into a pretty little app, but Python is not my strong point. :P

Last edited by cmantito; 2010-12-29 at 01:27.
 

The Following User Says Thank You to cmantito For This Useful Post: