nautilus脚本应用实例之二:右键菜单挂载/卸载ISO


版权声明:可以任意转载,转载时请务必以超链接形式标明文章原始出处和作者信息

右键挂载选中的iso

#!/usr/bin/perl -w
 
# This script mount the selected iso(s).
 
use strict;
 
my @files = split("\n", $ENV{NAUTILUS_SCRIPT_SELECTED_FILE_PATHS});
 
my $foo = system("gksudo -u root -k -m 'enter your password for root terminal access' /bin/echo 'r00t'");
 
if( ! $foo )
{
	foreach my $file (@files)
	{
		if ( ! -f $file && ! -l $file )
		{
			my @dialog = ("gdialog","--title","Error","--msgbox", "\nError: Can not mount $file.    \n\n    Only regular files can be mounted.    ","200", "300");
			system (@dialog);
		}
		else
		{
			$_ = $file;
			my ( $dir, $filename ) = m/(.*)[\\\/](.+)/ ? ( $1, $2 ) : ( undef, $_ );
			if( ! -d "/media/$filename" )
			{
				system("sudo mkdir /media/$filename");
			}
			system("sudo mount -o loop -t iso9660 $file /media/$filename");
		}
	}
 
}

右键卸载选中的iso

#!/usr/bin/perl -w
 
# This script unmount the selected iso(s).
 
use strict;
 
my @files = split("\n", $ENV{NAUTILUS_SCRIPT_SELECTED_FILE_PATHS});
 
my $foo = system("gksudo -u root -k -m 'enter your password for root terminal access' /bin/echo 'r00t'");
 
if( ! $foo )
{
	foreach my $file (@files)
	{
		if ( ! -f $file && ! -l $file )
		{
			my @dialog = ("gdialog","--title","Error","--msgbox", "\nError: Can not unmount $file.    \n\n    Only regular files can be unmounted.    ","200", "300");
			system (@dialog);
		}
		else
		{
			$_ = $file;
			my ( $dir, $filename ) = m/(.*)[\\\/](.+)/ ? ( $1, $2 ) : ( undef, $_ ); 
 
			system("sudo umount /media/$filename");
			if( -d "/media/$filename" )
			{
				system("sudo rmdir /media/$filename");
			}
		}
 
	}
 
}
分享家:Addthis中国
您可能还对以下文章感兴趣

, , , ,