![]() |
2010-08-06
, 18:07
|
Posts: 5 |
Thanked: 15 times |
Joined on Aug 2010
|
#2
|
#!/usr/bin/python import sys import dbus status_dict = { 1: "Offline", 2: "Online", 3: "Away", 4: "Extended_Away", 5: "Invisible", 6: "Busy" } status_dict_rev = { "off": 1, "offline": 1, "on": 2, "online": 2, "away": 3, "extended away": 4, "na": 4, "n/a": 4, "invisible": 5, "invis": 5, "busy": 6, "dnd": 6, } try: presence = sys.argv[1] except IndexError: sys.exit('Usage: %s off|on|away|na|invis|dnd') try: presence_const = int(presence) except ValueError: try: presence_const = status_dict_rev[presence] except KeyError: sys.exit('Usage: %s off|on|away|na|invis|dnd') presence = status_dict[presence_const] try: presence_text = sys.argv[2] except IndexError: presence_text = '' bus = dbus.SessionBus() account_manager = bus.get_object('org.freedesktop.Telepathy.AccountManager', '/org/freedesktop/Telepathy/AccountManager') accounts = account_manager.Get( 'org.freedesktop.Telepathy.AccountManager', 'ValidAccounts') for account_path in accounts: if str(account_path) == '/org/freedesktop/Telepathy/Account/ring/tel/ring': continue account = bus.get_object('org.freedesktop.Telepathy.AccountManager', account_path) enabled = account.Get('org.freedesktop.Telepathy.Account', 'Enabled') if not enabled: continue account.Set('org.freedesktop.Telepathy.Account', 'RequestedPresence', \ dbus.Struct((dbus.UInt32(presence_const), presence, presence_text), signature='uss'), dbus_interface='org.freedesktop.DBus.Properties')
SetPesence.py online "I'm available"
![]() |
2010-08-06
, 18:36
|
|
Posts: 139 |
Thanked: 28 times |
Joined on Jun 2010
@ Connecticut, United States
|
#3
|
![]() |
2010-10-09
, 10:58
|
Posts: 47 |
Thanked: 3 times |
Joined on May 2010
@ Johannesburg, South Africa
|
#4
|
A slightly better version - now you can use text statuses instead of numbers:Usage:Code:#!/usr/bin/python import sys import dbus status_dict = { 1: "Offline", 2: "Online", 3: "Away", 4: "Extended_Away", 5: "Invisible", 6: "Busy" } status_dict_rev = { "off": 1, "offline": 1, "on": 2, "online": 2, "away": 3, "extended away": 4, "na": 4, "n/a": 4, "invisible": 5, "invis": 5, "busy": 6, "dnd": 6, } try: presence = sys.argv[1] except IndexError: sys.exit('Usage: %s off|on|away|na|invis|dnd') try: presence_const = int(presence) except ValueError: try: presence_const = status_dict_rev[presence] except KeyError: sys.exit('Usage: %s off|on|away|na|invis|dnd') presence = status_dict[presence_const] try: presence_text = sys.argv[2] except IndexError: presence_text = '' bus = dbus.SessionBus() account_manager = bus.get_object('org.freedesktop.Telepathy.AccountManager', '/org/freedesktop/Telepathy/AccountManager') accounts = account_manager.Get( 'org.freedesktop.Telepathy.AccountManager', 'ValidAccounts') for account_path in accounts: if str(account_path) == '/org/freedesktop/Telepathy/Account/ring/tel/ring': continue account = bus.get_object('org.freedesktop.Telepathy.AccountManager', account_path) enabled = account.Get('org.freedesktop.Telepathy.Account', 'Enabled') if not enabled: continue account.Set('org.freedesktop.Telepathy.Account', 'RequestedPresence', \ dbus.Struct((dbus.UInt32(presence_const), presence, presence_text), signature='uss'), dbus_interface='org.freedesktop.DBus.Properties')Code:SetPesence.py online "I'm available"
![]() |
2010-10-09
, 11:47
|
Posts: 5 |
Thanked: 15 times |
Joined on Aug 2010
|
#5
|
![]() |
2010-10-09
, 19:43
|
Posts: 47 |
Thanked: 3 times |
Joined on May 2010
@ Johannesburg, South Africa
|
#6
|
Either put SetPresence.py to a directory in PATH or call it with a relative or full path; .e.g. ./SetPresence.py if it's in the current directory or /home/user/bin/SetPresence.py if it's in /home/user/bin/.
~ $ cd /home/user/MyDocs ~/MyDocs $ ls Set ls: Set: No such file or directory ~/MyDocs $ ls -a . .qf Signature.jpg .. .sounds WMPInfo.xml .VolumeIcon.icns .videos autorun.inf ._ DCIM backups .apt-archive-cache Downloads cities .documents GPO Update.txt fuelpad.db .images Mac OS mstardict .map_tile_cache Music qtirreco .mediabox Podcasts tmp .n900.ico SetPesence.py ~/MyDocs $ SetPresence.py -sh: SetPresence.py: not found ~/MyDocs $ /home/user/MyDocs/SetPresence.py -sh: /home/user/MyDocs/SetPresence.py: not found ~/MyDocs $
![]() |
2010-10-09
, 20:03
|
Posts: 5 |
Thanked: 15 times |
Joined on Aug 2010
|
#7
|
$ chmod a+x SetPresence.py $ ls -lF SetPresence.py
![]() |
2010-10-09
, 20:40
|
|
Posts: 1,637 |
Thanked: 4,424 times |
Joined on Apr 2009
@ Germany
|
#8
|
The Following User Says Thank You to nicolai For This Useful Post: | ||
![]() |
2010-10-10
, 09:54
|
Posts: 992 |
Thanked: 738 times |
Joined on Jun 2010
@ Low Earth Orbit
|
#9
|
The Following User Says Thank You to kureyon For This Useful Post: | ||
![]() |
2010-10-10
, 10:20
|
Posts: 47 |
Thanked: 3 times |
Joined on May 2010
@ Johannesburg, South Africa
|
#10
|
Usage:
Last edited by phd; 2010-08-06 at 16:09.