我整理了一个小脚本,从通过udev和systemd服务运行的sd卡中复制图片。 完成后,我希望它打开文件管理器到photo目录,但是由于脚本是以root身份运行的,因此会出现问题。 如何解决这个问题?
我已经使用发现的此脚本来显示通知,我是否应该对文件管理器进行相同的设置?似乎有点肮脏和肮脏。
#!/bin/sh
user=`whoami`
pids=`pgrep -u $user polybar`
title=$1
text=$2
timeout=$3
icon=$4
if [ -z "$title" ]; then
echo You need to give me a title >&2
exit 1
fi
if [ -z "$text" ]; then
text=$title
fi
if [ -z "$timeout" ]; then
timeout=60000
fi
for pid in $pids; do
# find DBUS session bus for this session
DBUS_SESSION_BUS_ADDRESS=`grep -z DBUS_SESSION_BUS_ADDRESS \
/proc/$pid/environ | sed -e 's/DBUS_SESSION_BUS_ADDRESS=//'`
# use it
#icon hack:
if [ -z $icon ]; then
DBUS_SESSION_BUS_ADDRESS=$DBUS_SESSION_BUS_ADDRESS \
notify-send -u low -t $timeout "$title" "$text"
else
DBUS_SESSION_BUS_ADDRESS=$DBUS_SESSION_BUS_ADDRESS \
notify-send -u low -t $timeout -i "$icon" "$title" "$text"
fi
done