Reply
Thread Tools
Posts: 277 | Thanked: 319 times | Joined on Jan 2010
#1611
Originally Posted by mr666acdc View Post
Can you make that config file to this script?
Sorry, haven't checked back here in a while. Here's a quick and dirty modification to it that will save your options to a 'scriptconfigfile.ini' and will automatically start with those options the next time you start it. If you want to choose again just remove or rename the config file from /home/user. If you need multiple instances running for multiple devices to follow, just rename the config file in the script for each instance (both places!).

Code:
#!/usr/bin/python
# Trigger Profilematic rule by BT connected/disconnected
# author: slarti

import dbus, gobject
from ConfigParser import SafeConfigParser

# Check for a configfile and create one if it doesn't exist
cfgfile = open('scriptconfigfile.ini', 'a+')


# Set up profilematic interface and get a list of rule names:
sesbus = dbus.SessionBus()
pm_obj = sesbus.get_object('org.ajalkane.profilematic', '/org/ajalkane/profilematic')
pm_intf = dbus.Interface(pm_obj, 'org.ajalkane.profilematic')
rulenames = pm_intf.getRuleNames()

# Set up some functions to use when handling the dbus event:
def menu(list_1, question):
        print (30 * '-')
        print ("Pick one from these:")
        for entry in list_1:
                print "  ",1 + list_1.index(entry),
                print ") " + entry
        print (30 * '-')

        return list_1[(int(raw_input(question)) - 1)]

def get_disconnected_rule():
        rule_list = ["No action"] + rulenames
        disconnected_rule = menu(rule_list, "Pick the rule whose actions you want to execute when device is disconnected: ")
        print "The actions of (%s) will be executed on device disconnect" %disconnected_rule

        return disconnected_rule

def get_connected_rule():
        rule_list = ["No action"] + rulenames
        connected_rule = menu(rule_list, "Pick the rule whose actions you want to execute when device is connected: ")
        print "The actions of (%s) will be executed on device connect" %connected_rule

        return connected_rule

def trigger_action(rulename):
        if rulename == 0:
                print "No action wanted."
        else:
                pm_intf.executeActionsByRuleName(rulename)
                print rulename, "executed."

# Set up loop to listen for dbus signal:
from dbus.mainloop.glib import DBusGMainLoop
dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)


# Get the BT adapter path and link device names to device paths in a dict:
bus = dbus.SystemBus()
bluez = bus.get_object('org.bluez', '/')
adapter_path = bluez.ListAdapters(dbus_interface='org.bluez.Manager')[0]
adapter = bus.get_object('org.bluez', adapter_path)
devices = adapter.ListDevices(dbus_interface='org.bluez.Adapter')
device_dict = {}

for device_path in devices:
        deviceprops = bus.get_object('org.bluez', device_path).GetProperties(dbus_interface='org.bluez.Device')
        device_dict.update({deviceprops ['Alias']:device_path})

# Get device, connect rule and disconnect rule from user:

settings = SafeConfigParser()
settings.read('scriptconfigfile.ini')
if settings.has_section('settings'):
        pass
else:
        settings.add_section('settings')

if settings.has_option('settings', 'device'):
        device = settings.get('settings', 'device')
else:
        device = menu(device_dict.keys(),"The name of the device to follow: ")
        settings.set('settings', 'device', device)

device_path = device_dict [device]
print "Now following the device: ",device, "in path: ",device_path

if settings.has_option('settings', 'connected_rule'):
        connected_rule = settings.get('settings', 'connected_rule')
else:
        connected_rule = get_connected_rule()

if connected_rule == "No action":
        device_connected = 0
else:
        device_connected = connected_rule
settings.set('settings', 'connected_rule', connected_rule)

if settings.has_option('settings', 'disconnected_rule'):
        disconnected_rule = settings.get('settings', 'disconnected_rule')
else:
        disconnected_rule = get_disconnected_rule()

if disconnected_rule == "No action":
        device_disconnected = 0
else:
        device_disconnected = disconnected_rule
settings.set('settings', 'disconnected_rule', disconnected_rule)
settings.write(cfgfile)
cfgfile.close()

print "Try connecting/disconnecting device %s now" %device

# Handle dbus signal:
def process_signal(property, message):
        if message == 0:
                print device, "disconnected. Triggering action."
                trigger_action(device_disconnected)
        else:
                print device, "connected. Triggering action."
                trigger_action(device_connected)

# Add signal receiver:
bus.add_signal_receiver(process_signal,path=device_path,dbus_interface='org.bluez.Device',signal_name='PropertyChanged')

loop = gobject.MainLoop()
loop.run()
 

The Following 3 Users Say Thank You to slarti For This Useful Post:
edgar2's Avatar
Moderator | Posts: 199 | Thanked: 264 times | Joined on May 2009 @ turku, finland
#1612
Originally Posted by ajalkane View Post
As others have said, this is already a feature of N9. You just need to Edit networks and set the WLAN to be automatically connected.
if both the 3g connection and a particular wlan is set to automatically connect, it doesn't seem possible to "switch to wlan x when available". Is this correct?
 
Posts: 1,313 | Thanked: 2,977 times | Joined on Jun 2011 @ Finland
#1613
Originally Posted by edgar2 View Post
if both the 3g connection and a particular wlan is set to automatically connect, it doesn't seem possible to "switch to wlan x when available". Is this correct?
That is correct.
__________________
My N9/N950 projects:
 

The Following 2 Users Say Thank You to ajalkane For This Useful Post:
Posts: 3 | Thanked: 1 time | Joined on Aug 2013
#1614
Have you ever thought about creating similar app for BlackBerry 10? There are some profile changers in their store, but they are not even close to Profilematic. After few years with N9, this is probably the only app that I can't find replacement for to use with my new BB phone...
 
Posts: 1,313 | Thanked: 2,977 times | Joined on Jun 2011 @ Finland
#1615
Originally Posted by bakulik View Post
Have you ever thought about creating similar app for BlackBerry 10? There are some profile changers in their store, but they are not even close to Profilematic. After few years with N9, this is probably the only app that I can't find replacement for to use with my new BB phone...
I thought about it, and I started to port ProfileMatic for BB10 when it first arrived. But it was impossible. The platform was too locked down and they did not provide the APIs that would have been necessary. Back then you couldn't even change the profile. Basically I couldn't figure out no actions at all that would have made sense for ProfileMatic-like tool.

Nice to hear apparently changing profile automatically is now possible. But I have unfortunately lost interest in BB10. Thank you for your nice words about ProfileMatic.
__________________
My N9/N950 projects:
 

The Following 4 Users Say Thank You to ajalkane For This Useful Post:
Posts: 3 | Thanked: 1 time | Joined on Aug 2013
#1616
Originally Posted by ajalkane View Post
Nice to hear apparently changing profile automatically is now possible. But I have unfortunately lost interest in BB10. Thank you for your nice words about ProfileMatic.
I'm sorry to hear this, but I understand your decision.
ProfileMatic is really useful application, logical and convenient.
Maybe after next OS update, which will allow to cerate own profiles, current BB apps will become more useful.
 

The Following User Says Thank You to bakulik For This Useful Post:
Posts: 290 | Thanked: 385 times | Joined on Jan 2012 @ Madrid, Spain
#1617
Originally Posted by slarti View Post
Turns out setting an alarm from the command line is now extremely simple thanks to PMs executeAction method. Was that always there?

Here is a simple script that takes seconds as an argument. If you don't give it anything it defaults to 60 seconds. If you give it something that isn't a number it will fail with ValueError exception. Title, snooze and sound can, of course, be modified from within the script.

python and python-dbus need to be installed (apt-get install python python-dbus as root)

Argument is given simply with: python /path/to/script.py 120
This will set an alarm 120 seconds from now.

Code:
#!/usr/bin/python

import dbus
import sys

bus = dbus.SessionBus()
pm_obj = bus.get_object('org.ajalkane.profilematic', '/org/ajalkane/profilematic')
pm_intf = dbus.Interface(pm_obj, 'org.ajalkane.profilematic')

actions_struct = ['', 0, -1, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, '', '', dbus.Array([], signature=dbus.Signature('(usis)')), '', 0, 1, [dbus.Array([], signature=dbus.Signature('s'))], -1, 0, ['', -1, -1, ''], -1, 0]

if len(sys.argv) == 2:
        seconds = int(sys.argv[1])
else:
        seconds = 60

title = 'Timer'
snooze = 10
sound = ''
actions_struct[24] = [title, seconds, snooze, sound]

pm_intf.executeAction(actions_struct)
print 'Alarm set to go off in %s seconds from now.' %seconds
Other ProfileMatic actions can be executed by modifying certain parts of the actions_struct. I can post the relevant indices if anyone is interested.
Hi.

I'm interested in using this functionality, but I'd like to tailor it a bit for my necessities:
Where can I find the description of the parameters used in the python's script methods?

Regards.
 
Posts: 290 | Thanked: 385 times | Joined on Jan 2012 @ Madrid, Spain
#1618
Hi.

Sorry for bumping the thread, but I really would like to be able to set/modify clock alarms in my N9.

Somebody knows what's the meaning of the parameters in:
Code:
org.ajalkane.profilematic.executeAction(QDBusRawType::(sbiibibibibibibssa(usis action)
The example in my previous post just sets the values.... but does not explain them.

Thanks in advance.
Regards.
 
Posts: 1,313 | Thanked: 2,977 times | Joined on Jun 2011 @ Finland
#1619
Originally Posted by pasko View Post
Hi.

Sorry for bumping the thread, but I really would like to be able to set/modify clock alarms in my N9.

Somebody knows what's the meaning of the parameters in:
Code:
org.ajalkane.profilematic.executeAction(QDBusRawType::(sbiibibibibibibssa(usis action)
The example in my previous post just sets the values.... but does not explain them.

Thanks in advance.
Regards.
I'm not sure if this helps you, but here's the relevant sources of how ProfileMatic interprets the DBus parameters:

https://github.com/ajalkane/profilem...ticinterface.h

(see executeAction() function, it receives RuleAction structure).

RuleAction structure is parsed like this:

https://github.com/ajalkane/profilem...model/rule.cpp

(see QDBusArgument &operator<< function)

I'm sorry I can't give more concrete help, but hopefully that gets you somewhere.
__________________
My N9/N950 projects:
 

The Following 3 Users Say Thank You to ajalkane For This Useful Post:
Posts: 290 | Thanked: 385 times | Joined on Jan 2012 @ Madrid, Spain
#1620
Hi.
Thank you for your answer, but I still don't get it. Slarti said in his post that he could provide information about the other indices of the variable 'actions_struct' . I'm trying to set a new trigger for an already set alarm, something like method 'replace_event' from 'com.nokia.time'. I started with dbus-send, and now I'm trying with python.... but no luck so far.

Regards.
 
Reply

Thread Tools

 
Forum Jump


All times are GMT. The time now is 21:24.