Sponsored Content
Top Forums Shell Programming and Scripting Shell Script Xml file wallpaper Post 302592042 by edehont on Sunday 22nd of January 2012 12:44:43 PM
Old 01-22-2012
A while ago I wrote a Perl-script to do this. It also puts all pictures in a random order.

Perhaps one could add a routine to update
Code:
~/.gconf/desktop/gnome/background/%gconf

to have it point to the created xml-file as well.

Change the values in the line
Code:
my ($transdur,$statdur) = ('15.0','20.0');

to make it show the background for a longer period and/or make the transition faster.

First cd to your directory containing the wallpapers, then run the script.

Code:
#!/usr/bin/perl
# mySlideShow
# Author: Eric de Hont
# Mail: edehont@xs4all.nl
# Date: wo mrt 23 01:43:16 CET 2011
##################################################

use strict;
use warnings;
use List::Util qw(shuffle);
use Cwd;

my $dir = getcwd . '/';

my $head = '<background>
  <starttime>
    <year>2009</year>
    <month>08</month>
    <day>04</day>
    <hour>00</hour>
    <minute>00</minute>
    <second>00</second>
  </starttime>
<!-- This animation will start at midnight. -->
';

my $foot = '</background>';

#my ($transdur,$statdur) = ('5.0','1795.0');
my ($transdur,$statdur) = ('15.0','20.0');

my @pictures;

opendir(DIR, '.') or die "can't open current directory: $!";
while (defined(my $picture = readdir(DIR))) {
  next if $picture =~ /^\.\.?$/; #skip . and ..
  next unless $picture =~ /^.+\.(jpg|png|gif)$/i;
  push @pictures, $dir.$picture;
}
closedir(DIR);

@pictures = shuffle(@pictures); # Randomize the pictures

# Start
my @XML = $head;

die "No pictures found." unless @pictures > 0;

# First picture

push @XML, "  <static>
    <duration>$statdur</duration>
    <file>$pictures[0]</file>
  </static>\n";

# The bulk
for (my $cur = 1; $cur < @pictures; $cur++) {
  push @XML, "  <transition>
    <duration>$transdur</duration>
    <from>$pictures[$cur - 1]</from>
    <to>$pictures[$cur]</to>
  </transition>
  <static>
    <duration>$statdur</duration>
    <file>$pictures[$cur]</file>
  </static>\n";
}

# The last picture

push @XML, "  <transition>
    <duration>$transdur</duration>
    <from>$pictures[-1]</from>
    <to>$pictures[0]</to>
  </transition>\n";

# Finish the XML

push @XML, $foot;

# write XML

open(XML, '> background-1.xml') or die "Couldn't open background-1.xml for writing: $!\n";
print XML @XML;
close(XML);

 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script to split XML file

Hi, I'm experiencing difficulty in loading an XML file to an Oracle destination table.I keep running into a memory problem due to the large size of the file. I want to split the XML file into several smaller files based on the keyword(s)/tags : '' and '' and would like to use a Unix shell... (2 Replies)
Discussion started by: bayflash27
2 Replies

2. UNIX for Dummies Questions & Answers

need to invoke a shell script from xml file.

hi all, forgive me if this question is not relevant to this section. i have a shell file that will automatically deploy the files that are necessary and will compile them. i need to automate this management process through cruise control, for this i need to know whether it is possible for me to... (2 Replies)
Discussion started by: sais
2 Replies

3. Shell Programming and Scripting

i want to nvoke a xml file from a shell script

hi all , i have a shell script that performs all the steps required for deployment of a tar file .. there is a tool that helps me in finding out what files should go in that tar file... this tool is fully in xml as it invokes ant ( a build tool in java ).... i want to invoke that xml file from a... (1 Reply)
Discussion started by: sais
1 Replies

4. Shell Programming and Scripting

How to remove xml namespace from xml file using shell script?

I have an xml file: <AutoData xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <Table1> <Data1 10 </Data1> <Data2 20 </Data2> <Data3 40 </Data3> <Table1> </AutoData> and I have to remove the portion xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" only. I tried using sed... (10 Replies)
Discussion started by: Gary1978
10 Replies

5. Shell Programming and Scripting

Parse XML file in shell script

Hi Everybody, I have an XML file containing some data and i want to extract it, but the specific issue in my file is that the data is repeated some times like the following example : <section1> <subsection1> X=... Y=... Z=... <\subsection1> <subsection2> X=... Y=... Z=...... (2 Replies)
Discussion started by: yassine
2 Replies

6. Shell Programming and Scripting

Shell Script to read XML file

Hi unix Gurus, I am really new to Unix Scripting. Please help me to create a shell script which reads the xml file and from that i need to fetch a particular information. For example <SOURCE BUSINESSNAME ="" DATABASETYPE ="Teradata" DBDNAME ="DWPROD3" DESCRIPTION ="" NAME... (5 Replies)
Discussion started by: SmilePlease
5 Replies

7. Red Hat

How to read an xml file through shell script?

Hey , can we read an xml file and make changes in it through shell script. Thanks (4 Replies)
Discussion started by: ramsavi
4 Replies

8. UNIX for Dummies Questions & Answers

Reading XML file and print the values in the text file using Linux shell script

hi guys, i want help... Reding XML file and print the values into the text file using linux shell script file as per below xml file <sequence> <Filename>aldorzum.doc</Filename> <DivisionCode>US</DivisionCode> <ContentType>Template</ContentType> <ProductCode>VIMZIM</ProductCode> </sequence>... (1 Reply)
Discussion started by: sravanreddy
1 Replies

9. Shell Programming and Scripting

Need get data from XML file through shell script..

hi all, here is the sample log file and these errors are repeated in log file.. i need all the repeated time stamp ,severity and message tags needs to print in output file.. through shell script <log-message> <timestamp>2019-03-13T04:52:49.648-05:00</timestamp> <severity>ERROR</severity>... (17 Replies)
Discussion started by: ravi
17 Replies
genxs(1)						      General Commands Manual							  genxs(1)

NAME
genxs - Mono's Xml Serializer Generator SYNOPSIS
genxs configurationFile [destinationFolder] DESCRIPTION
genxs is a tool for generating custom XML serialization writers and readers for classes. configurationFile is configuration file which specifies several information, such as the class for which to generate the reader and writer, the name and namespace of the classes to generate, and a collection of hooks to apply. By using hooks it is possible to customize the behavior of the serializer without needing to modify the generated file, so you can safely regenerate it if the source class is modified. destinationFolder specifies the folder where the files will be generated. NOTE: This tool only runs in the Mono runtime, since it uses some internal classes not available in other runtimes. CONFIGURATION FILE FORMAT
The configuration file is an xml document based on the following grammar ("?" means optional, "*" 0 or more): <configuration> <serializer class="name" assembly="name"> * <reader>name</reader> ? <writer>name</writer> ? <namespace>name</namespace> ? <outFileName>name</outFileName> ? <readerHooks> ? <hook ...> * </readerHooks> <writerHooks> ? <hook ...> * </writerHooks> </serializer> </configuration> A configuration file can have multiple "serializer" elements, each of which specifies the class for which to generate a serializer together with several generation options. The source class is specified in the following attributes: * class : name of the class (including namespace). * assembly : assembly name. It can include the complete path. Generation options are specified in child elements: * reader : name of the reader class. * noReader : if "true", it does not generate reader class. * writer : name of the writer class. * baseSerializer : name of the base xml serializer class. This item is 2.0 only. * implementation : name of the serializer implementation class. This item is 2.0 only. * noWriter : if "true", it does not generate writer class. * namespace : namespace of the reader and writer classes. * generateAsInternal : if "true", it generates classes as internal. * outFileName : name of the generated file. * readerHooks : a list of hooks to apply to the reader. * writerHooks : a list of hooks to apply to the writer. SPECIFYING HOOKS
Using hooks you can customize the behavior of readers and writers. A hook specification follows this grammar: <hook type="name"> <select> ? <typeName>name</typeName> ? <typeAttribute>name</typeAttribute> * <typeMember>name</typeMember> ? </select> <replace>source code</replace> ? <insertBefore>source code</insertBefore> ? <insertAfter>source code</insertAfter> ? </hook> The "type" attribute specifies the context in which the hook is applied. It can be one of the following: * attributes : hook is applied where attributes are serialized/deserialized. * elements : hook is applied where elements are serialized/deserialized. * unknownAttribute : hook is applied where unknown attributes are processed. * unknownElement : hook is applied where unknown elements are processed. * member : hook is applied where a member is serialized/deserialized. * type : hook is applied for the whole type. The "select" element specifies the classes and members to which the hook has to be added. It can contain the following elements: * typeName : the class with that name will be selected (must include namespace) * typeAttribute : all classes which have that attribute applied will be selected (specify the full attribute class name, including namespace). Several attribute names can be specified. * typeMember : name of the class member for which the hook must be added. The hook source code can be specified using any of the following elements: * replace : the provided source code will replace all serialization/deserialization operations in the hook context. * insertBefore : the source code will be added before the hook context. * insertAfter : the source code will be added after the hook context. When writing the code for a hook you can use some special variables that are defined during the code generation process. The variables are the following: * $TYPE: name of the class being generated, without namespace. * $FULLTYPE: full name of the class being generated, including namespace. * $OBJECT: the object being serialized or deserialized. When using a replace reader hook of type "type", the hook code must assign the deserialized object to this variable. * -I $ELEMENT: name of the element of the object being serialized/deserialized. * $NAMESPACE: namespace of the element of the object being serialized/deserialized. * $MEMBER: name of the member being serialized/deserialized. Only valid in the "member" context. HOOK EXAMPLES
The following example adds a call to a Validate method after the deserialization of any object: <hook type="type"> <insertAfter> System.Xml.Schema.XmlSchema.Validate$TYPE ($OBJECT); </insertAfter> </hook> This example specifies the code to be used to deserialize the XmlSchema class: <hook type="type"> <select> <typeName>System.Xml.Schema.XmlSchema</typeName> </select> <replace> $OBJECT = System.Xml.Schema.XmlSchema.Read (Reader, null); </replace> </hook> That one specifies the code to be used to read XmlSchema instances: <hook type="type"> <select> <typeName>System.Xml.Schema.XmlSchema</typeName> </select> <replace>$OBJECT.Write (Writer);</replace> </hook> With this two hooks the serializer will print some information when serializing the class "MyClass": <hook type="type"> <select> <typeName>MyNamespace.MyClass</typeName> </select> <insertBefore>Console.WriteLine ("Serializing MyClass");</replace> <insertAfter>Console.WriteLine ("MyClass serialized");</insertAfter> </hook> <hook type="member"> <select> <typeName>MyNamespace.MyClass</typeName> </select> <insertAfter> Console.WriteLine ("Serialized member $MEMBER"); </insertAfter> </hook> This hook writes an additional element for all types that have the custom attribute "MyAttribute": <hook type="elements"> <select> <typeAttribute>MyNamespace.MyAttribute</typeAttribute> </select> <insertAfter> Writer.WriteStartElement ("privateData"); Writer.WriteString ($OBJECT.PrivateData); Writer.WriteEndElement (); </insertAfter> </hook> CONFIGURATION FILE EXAMPLE
This is the configuration file used to generate the serializer for ServiceDescription: <configuration> <serializer class="System.Web.Services.Description.ServiceDescription" assembly="System.Web.Services"> <reader>ServiceDescriptionReaderBase</reader> <writer>ServiceDescriptionWriterBase</writer> <namespace>System.Web.Services.Description</namespace> <outFileName>ServiceDescriptionSerializerBase.cs</outFileName> <readerHooks> <hook type="unknownElement"> <select> <typeAttribute>System.Web.Services.Configuration.XmlFormatExtensionPointAttribute</typeAttribute> </select> <replace>ServiceDescription.ReadExtension (Reader, $OBJECT);</replace> </hook> <hook type="type"> <select> <typeName>System.Xml.Schema.XmlSchema</typeName> </select> <replace>$OBJECT = System.Xml.Schema.XmlSchema.Read (Reader, null);</replace> </hook> </readerHooks> <writerHooks> <hook type="elements"> <select> <typeAttribute>System.Web.Services.Configuration.XmlFormatExtensionPointAttribute</typeAttribute> </select> <insertBefore>ServiceDescription.WriteExtensions (Writer, $OBJECT);</insertBefore> </hook> <hook type="type"> <select> <typeName>System.Xml.Schema.XmlSchema</typeName> </select> <replace>$OBJECT.Write (Writer);</replace> </hook> </writerHooks> </serializer> </configuration> AUTHORS
Lluis Sanchez Gual (lluis@ximian.com) LICENSE
GenXS is released under the terms of the GNU GPL. SEE ALSO
mono(1), mcs(1), sgen(1) genxs(1)
All times are GMT -4. The time now is 01:13 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy