Ubuntu Pastebin

Paste from ChrisTownsend at Mon, 26 Jan 2015 20:20:17 +0000

Download as text
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/bin/sh
#    Copyright(C) 2010 Ying-Chun Liu(PaulLiu). All rights reserved.
#
#    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
#

# Please run this script by using "source ./attach-dbus-session.sh"

# Search some process to get DBUS_SESSION_BUS_ADDRESS
targetProcess=( unity8 compiz )

# GET PID
for index in ${targetProcess[@]}; do
  PID=$(pidof -s ${index})
  if [ x"${PID}" != x"" ]; then
    break
  fi
done

if [ x"${PID}" == x"" ]; then
  echo "No process found to get DBUS_SESSION_BUS_ADDRESS"
  return 1
fi

QUERY="$(cat /proc/${PID}/environ | tr '\0' '\n' | grep "DBUS_SESSION_BUS_ADDRESS" | cut -d "=" -f 2-)"
if [ x"${QUERY}" != x"" ]; then
  export DBUS_SESSION_BUS_ADDRESS="${QUERY}"
  echo "DBUS_SESSION_BUS_ADDRESS=${DBUS_SESSION_BUS_ADDRESS}"
else
  echo "Cannot find DBUS_SESSION_BUS_ADDRESS in process pid=${PID}."
  return 1
fi

return 0
Download as text