somebody might find this script useful.
you will need to have at least php4-cli installed to run it.
PHP Code:
#!/usr/bin/env php
<?php
/**
* xfce4-background-changer
*
* a bit of automating for the xfce4 desktop
*
* it recreates the background list automaticly as I found the gui
* not comfortable enough and "reloads" afterwards the desktop causing a
* new background picture being randomly displayed
* you can put it in your crontab to change the background every
* now and then (man crontab)
* f.e. "* * * * * ~/scripts/xfce4-background-changer.php"
* or you might place a desktop starter to change the background
* everytime you activate the starter
*
* PHP version 4 and 5
*
* LICENSE:
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* @author David Uhlig <david.uhlig@googlemail.com>
* @copyright 2007 David Uhlig <david.uhlig@googlemail.com>
* @license http://www.gnu.org/licenses/gpl.txt GNU GPL
* @version 1.0
*/
// {{{ settings
/**
* home
*/
define('HOME', $_ENV['HOME']);
/**
* directories with wallpapers, or wallpaper files
* use absolute path, seperate by comma
* !!! no closing slash for directorys
* !!! directories will _not_ be walked through recursive
*/
define('BACKGROUND_DIR', HOME . '/.wallpaper');
/**
* absolute path to your background list as choosen via
* Applications / Settings / Background -> Picture -> File
*/
define('BACKGROUND_LIST', HOME . '/.config/xfce4/desktop/hintergrundbilder.list');
// }}}
// {{{ functions
/**
* rewriteBackgroundList
*/
function rewriteBackgroundList()
{
$res = fopen(BACKGROUND_LIST, "w");
fwrite($res, "# xfce backdrop list\n");
if ($res === false)
{
return;
}
$aryBackgroundDir = split(",", BACKGROUND_DIR);
foreach ($aryBackgroundDir as $strBackgroundDir)
{
if (is_dir($strBackgroundDir))
{
$aryDir = scandir($strBackgroundDir);
foreach ($aryDir as $strFile)
{
if (is_dir($strFile))
{
continue;
}
if ($strFile == "." || $strFile == "..")
{
continue;
}
if (!file_exists($strBackgroundDir . "/" . $strFile))
{
continue;
}
fwrite($res, $strBackgroundDir . "/" . $strFile . "\n");
}
}
elseif (file_exists($strBackgroundDir))
{
fwrite($res, $strBackgroundDir);
}
}
fclose($res);
}
/**
* php4 compat for scandir
* taken from php.net/scandir user comments
*/
if(!function_exists('scandir')) {
function scandir($strDir, $intSortorder = 0) {
if (is_dir($strDir)) {
$strDirlist = opendir($strDir);
while (($strFile = readdir($strDirlist)) !== false) {
if(!is_dir($strFile)) {
$aryFiles[] = $strFile;
}
}
($intSortorder == 0) ? asort($aryFiles) : rsort($aryFiles);
return $aryFiles;
} else {
return false;
}
}
}
// }}}
// {{{ main
rewriteBackgroundList();
exec("killall -USR1 xfdesktop");
// }}}
?>
Bookmarks