Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl
- use warnings;
- use strict;
- # can likely change from ubuntu- to custom- as Precise seems to use all in dir
- # (would need to create an XML shell using ubuntu- or precise- as example)
- my $XML_FILE = q(/usr/share/gnome-background-properties/ubuntu-wallpapers.xml);
- usage() unless @ARGV && -f $ARGV[0];
- add_file(@ARGV);
- exit;
- # replace @ARGV to automagically edit file(s) inline
- sub add_file {
- my ($image_fn, $optional_name) = @_;
- @ARGV = ($XML_FILE);
- # set to .bak or ~ if you want a backup, but both files will then be read,
- # nearly doubling the choices when changing the background setting
- local $^I = '';
- while(<>) {
- print;
- next unless is_edit_boundary($_);
- print filename_to_xml($image_fn, $optional_name);
- # print STDERR filename_to_xml($image_fn, $optional_name);
- }
- }
- # add new entry up front
- sub is_edit_boundary {
- local $_ = shift;
- # print STDERR $_;
- return unless /^\s*<wallpapers>\s*$/;
- return 1;
- }
- # "scale" worked beautifully before Precise, but now seemingly stuck
- # with "zoom" which is a shame, especially when moving files across
- # different screen sizes
- sub filename_to_xml {
- my ($filename, $name) = @_;
- $name = $filename unless $name;
- my $str = <<EOT;
- <wallpaper>
- <name>__NAME__</name>
- <filename>__FILENAME__</filename>
- <options>zoom</options>
- </wallpaper>
- EOT
- $str =~ s/__FILENAME__/$filename/;
- $str =~ s/__NAME__/$name/;
- return $str;
- }
- sub usage {
- die join("\n", (
- 'USAGE',
- '[sudo] '.$0.' filename [name]',
- '',
- 'Adds filename to list of choices when changing desktop picture.',
- 'Because filename is a file that should be available to all, it makes',
- 'sense to have it in the default location: /usr/share/backgrounds/',
- '',
- 'Optionally add a name that is shown in the desktop choice, default',
- 'is to use the filename itself as the label.',
- '',
- 'EXAMPLE',
- 'sudo mv duk.jpg /usr/share/backgrounds/',
- "sudo wallpaper-add-to-choices /usr/share/backgrounds/duk.jpg 'Duck with Fly'",
- '',
- 'NOTE',
- 'By default the ubuntu config file being edited is owned by root.',
- '', @_,
- ))."\n";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement