我的笔记本电脑上有两个会话 - Unity 和 Gnome Fallback。我在家里使用便携模式的 Unity 和带有第二台显示器的 Gnome Fallback。我想要为 Unity 和 Fallback 会话设置不同的壁纸。浅色用于 Unity,深色用于 Fallback。
我想我可以使用自动启动选项showonlyin=
,但不知道怎么做。我不想每次都手动切换壁纸。
答案1
使用这个 bash 脚本,您可以实现您想要的。
#!/bin/bash
if [ "$XDG_CURRENT_DESKTOP" = "Unity" ]
then
gsettings set org.gnome.desktop.background picture-uri 'file:///usr/share/backgrounds/warty-final-ubuntu.png'
else
gsettings set org.gnome.desktop.background picture-uri 'file:///usr/share/backgrounds/The_Grass_aint_Greener_by_fix_pena.jpg'
fi
将此脚本添加到启动应用程序(添加 → 命令sh path/to/script
)。
并将文件路径替换为您所需的背景图片。
答案2
下面的脚本为 Unity 会话设置壁纸 A,为壁纸 B Gnome(或为任何其他运行 nautilus 文件管理器的桌面环境)设置壁纸 B。
使用方法很简单。提供两个完整路径到图像。第一幅图像用于 Unity,第二幅图像用于其他图像。
./session_wallpapers.py /home/user/WALLPAPERS/image_A.png /home/user/WALLPAPERS/image_B.jpg
这可以添加到启动应用程序在登录时自动执行该任务。确保脚本具有可执行权限。
也可以在我的github 存储库。
脚本源
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from gi.repository import Gio,Notify
import dbus
import sys
import os
import time
###########################################################
# Author: Serg Kolo , contact: [email protected]
# Date: June 30 , 2016
# Purpose: set wallpaper depending on desktop session
# Written for: https://askubuntu.com/q/146211/295286
# Tested on: Ubuntu 16.04 LTS
###########################################################
# Copyright: Serg Kolo , 2016
#
# Permission to use, copy, modify, and distribute this software is hereby granted
# without fee, provided that the copyright notice above and this permission statement
# appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.
def get_dbus(obj,path,interface,method):
# Reusable function for accessing dbus
# This basically works the same as
# dbus-send or qdbus. Just give it
# all the info, and it will spit out output
bus = dbus.SessionBus()
proxy = bus.get_object(obj,path)
method = proxy.get_dbus_method(method,interface)
return method()
def gsettings_set(schema,key,value):
gsettings = Gio.Settings.new(schema)
gsettings.set_string(key,value)
def send_notif(title,message):
Notify.init("Wallpaper setter")
content = Notify.Notification.new(title,message)
content.show()
def set_wallpaper( image ):
if os.path.isfile( image ):
gsettings_set('org.gnome.desktop.background', \
'picture-options','zoom' )
gsettings_set('org.gnome.desktop.background',\
'picture-uri', 'file://' + image)
send_notif("Session wallpaper set",image)
sys.exit(0)
else:
send_notif( "We have a problem!" ,
"Wallpaper image for this session doesn't exist.")
sys.exit(1)
def print_usage():
print """
session_wallpapers.py [UNITY_WALLPAPER] [GNOME_WALLPAPER]
This script sets wallpaper depending on the desktop
session user chooses. Both images must be given in
their full path form, otherwise the script exists
with status 1. Upon successful setting, it displays
notification and exists with status 0
Copyright Serg Kolo , 2016
"""
def main():
if len(sys.argv) < 2:
print_usage()
sys.exit(0)
# Wait for windows to appear
windows = ""
while not windows:
time.sleep(3)
windows = get_dbus( 'org.ayatana.bamf',\
'/org/ayatana/bamf/matcher' ,\
'org.ayatana.bamf.matcher',\
'WindowPaths' )
# get list of open windows
name_list = []
for window in windows:
name_list.append( get_dbus( 'org.ayatana.bamf', window, \
'org.ayatana.bamf.view','Name' ))
# Do we have unity-dash open ?
# If so that's unity session,
# otherwise - that's Gnome or
# something else.
if "unity-dash" in name_list:
print sys.argv[1]
set_wallpaper(sys.argv[1])
else:
print sys.argv[2]
set_wallpaper(sys.argv[2])
if '__main__' == __name__:
main()