在用gconftool-2 修改壁纸时很奇怪的一件事..

sh/bash/dash/ksh/zsh等Shell脚本
回复
头像
hellojinjie
帖子: 1150
注册时间: 2007-09-14 21:03
来自: 浙江

在用gconftool-2 修改壁纸时很奇怪的一件事..

#1

帖子 hellojinjie » 2009-08-26 23:26

下面是我写的用来下载bing背景,并设为壁纸的python,,我在桌面上执行的时候是能够正常设置壁纸的..

可是当我,rc.local加入

代码: 全选

su jj -c 'echo /home/jj/bin/autorun/BingPicture.py | at now + 10 minutes' 
让电脑开机自己下载并设置壁纸时,,只能下载bing的背景,,却没有设置壁纸..只是why?

代码: 全选

#!/usr/bin/env python
# -*- coding:utf-8 -*-

import re, urllib, os
from Logger import Logger

class BingPicture:
	'''
	download bing.com background picture
	and set the picture as gnome wallpaper
	'''
	version = 1.0
	
	def __init__(self):
		self.bingUrl = "http://www.bing.com"	
		self.downloadFolder = "/home/jj/Pictures/bing/"
		self.commad = "gconftool-2 -t str --set /desktop/gnome/background/picture_filename "
		self.log = Logger("bing")
		
	def go(self):
		filename = self.downloadPicture()
		
		# if the file is not None, let's set it as wallpaper
		if filename != None:
			os.system(self.commad + self.downloadFolder + filename)
			
	def getHtml(self):
		# return www.bing.com's page html code
		f = urllib.urlopen(self.bingUrl)
		bingString = ''
		for i in f:
			bingString += i
		return bingString
	
	def downloadPicture(self):
		# download the picture we want
		# @return the filename of the picture
		# first we retrive the url of the picture
		bingString = self.getHtml()
		tmp = re.search("g_img={url:.*jpg", bingString).group()
		tmp = tmp.replace("\\", '')
		picUrl = tmp.rsplit("'")[1]
		picUrl = "http://www.bing.com" + picUrl
		
		# filename of the picture
		picFilename = tmp.rsplit("/", 1)[1]
		
		# before we download the picture, let's check it 
		# whether we have already downloaded it. we should avoid repeated work
		if os.path.isfile(self.downloadFolder + picFilename):
			self.log.log("we have already downloaded it. we will not do it again")
		else:	
			# OK, let's download it
			urllib.urlretrieve(picUrl, self.downloadFolder + picFilename)
			self.log.log("OK, a picture is downloaded.")
		
		return picFilename
		
if __name__ == "__main__":
	bp = BingPicture()
	bp.go()
Say hello to everyday!
头像
eexpress
帖子: 58428
注册时间: 2005-08-14 21:55
来自: 长沙

Re: 在用gconftool-2 修改壁纸时很奇怪的一件事..

#2

帖子 eexpress » 2009-08-26 23:29

at cron 都另外一套环境变量
● 鸣学
头像
hellojinjie
帖子: 1150
注册时间: 2007-09-14 21:03
来自: 浙江

Re: 在用gconftool-2 修改壁纸时很奇怪的一件事..

#3

帖子 hellojinjie » 2009-08-26 23:31

eexpress 写了:at cron 都另外一套环境变量
可是我已经在rc.local里用su jj,以我自己的用户名执行脚本
Say hello to everyday!
头像
eexpress
帖子: 58428
注册时间: 2005-08-14 21:55
来自: 长沙

Re: 在用gconftool-2 修改壁纸时很奇怪的一件事..

#4

帖子 eexpress » 2009-08-26 23:35

gconftool-2你都全路径先。你那su,和你脚本里面的执行路径|权限何关哦。
● 鸣学
头像
hellojinjie
帖子: 1150
注册时间: 2007-09-14 21:03
来自: 浙江

Re: 在用gconftool-2 修改壁纸时很奇怪的一件事..

#5

帖子 hellojinjie » 2009-08-26 23:39

你的意思是说将python里的
self.commad = "gconftool-2 -t str --set /desktop/gnome/background/picture_filename "
修改成
self.commad = "/usr/bin/gconftool-2 -t str --set /desktop/gnome/background/picture_filename "
吗...我试试...
======================

我发现这样直接在终端下执行也是不行阿
echo gconftool-2 -t str --set /desktop/gnome/background/picture_filename /home/jj/Pictures/bing/KissingFish_ZH-CN697907340.jpg | at now
Say hello to everyday!
头像
hellojinjie
帖子: 1150
注册时间: 2007-09-14 21:03
来自: 浙江

Re: 在用gconftool-2 修改壁纸时很奇怪的一件事..

#6

帖子 hellojinjie » 2009-08-28 23:35

我今天看了下,gconftool-2 其实已经修改了wallpaper的配置文件,,可是gnome没有发现配置文件被修改,所以也就没有修改壁纸,,,,

那怎么通知gnome我已经修改了wallpaper呢..或者说有没有另外的一种方式修改wallpaper
Say hello to everyday!
回复