在Ubuntu中运行cronjob作为用户更改桌面背景 [英] Run cronjob as user to change desktop background in Ubuntu

查看:267
本文介绍了在Ubuntu中运行cronjob作为用户更改桌面背景的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试执行这个指令码,它将我的桌面背景更改为目录中的随机图片。它从命令行工作,并且cronjob运行(添加的输出,它得到吐出到日志文件),但我不能得到它改变我的背景。这是我的当前行(设置为每分钟运行测试)。

I am trying to run this script which changes my desktops background to a random picture in a directory. It works from the command line, and the cronjob gets run (added output and it gets spit out to a log file), but I can't get it to change my background. Here's my current line (set to run every minute for testing).

01 * * * * username /home/username/.wallpapers/flip.sh

任何想法?

推荐答案

错误: https: //bugs.launchpad.net/ubuntu/+source/gconf/+bug/285937

我的版本:

#!/bin/bash

# Script to randomly set Background from files in a directory

# Directory Containing Pictures
DIR=/home/lucas/studio/art/images/tapety
LOG=/home/lucas/tapeta.log

# Command to Select a random file from directory
PIC="$(
for p in [jJ][pP][gG] [pP][nN][gG] [sS][vV][gG] ; do
 ls $DIR/*.$p
done | shuf -n1
)"
# Command to set Background Image
if [ -z "$DBUS_SESSION_BUS_ADDRESS" ] ; then
 # this is because of gconftool bug in cron
 TMP=~/.dbus/session-bus
 export $(grep -h DBUS_SESSION_BUS_ADDRESS= $TMP/$(ls -1t $TMP | head -n 1))
 echo $DBUS_SESSION_BUS_ADDRESS >> $LOG
fi

gconftool-2 -t string -s /desktop/gnome/background/picture_filename "$PIC"

它适用于Fedora 12

and it's works on Fedora 12

这篇关于在Ubuntu中运行cronjob作为用户更改桌面背景的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆