We have moved to a new Sailfish OS Forum. Please start new discussions there.
13

Use TOH to trigger shell scripts [answered]

asked 2014-02-03 13:39:18 +0300

gehowa gravatar image

updated 2014-02-13 22:17:18 +0300

eric gravatar image

I really like the idea of having different ambiences for different circumstances. I fear, however, that it will take the brave Jolla engineers quite some time to develop a more elaborate ambience system.

One quick workaround would be to allow to trigger shell scripts when a TOH is replaced by another one. This shouldn't be too much work for Jolla, but would allow us to create our own crude ambience system. Frankly, I don't know how much aspects of the phone you can control by CLI, e.g. changing the ambience, but some basic linux stuff like vpn connection should be possible -- and this would be really helpful for me!


Edit: I wrote a python script which takes the ID of a newly attached TOH and executes a shell script named $TOH_ID.sh. This was easier than I thought -- thanks again for your answers!

#!/usr/bin/env python

def start_toh_script(sender, dict, array):
        if 'TOHID' in dict:
                print dict['TOHID']
                cmd = "./"+dict['TOHID']+".sh"
                try:
                        subprocess.Popen([cmd])
                except OSError:
                        print 'Please create file: '+dict['TOHID']+'.sh'


import dbus, gobject, subprocess, os
from dbus.mainloop.glib import DBusGMainLoop
dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
bus = dbus.SystemBus()

bus.add_signal_receiver(start_toh_script,dbus_interface='org.freedesktop.DBus.Properties',path='/com/jolla/tohd')

loop = gobject.MainLoop()
loop.run()
edit retag flag offensive reopen delete

The question has been closed for the following reason "the question is answered, an answer was accepted" by anandrkris
close date 2014-12-18 11:32:33.225627

Comments

1

try running dbus-monitor from cli when attaching a TOH. it triggers events and should be straight forward to trap dbus events with a shell script and do whatever you want then.

droll ( 2014-02-03 13:47:13 +0300 )edit

Seems as if I asked my question just in time ;)

Just ordered the two new TOH so I can play around with the script: http://shop.jolla.com/cat-the-other-half.html

gehowa ( 2014-02-04 17:09:17 +0300 )edit
2

Although technically it's all nice and wow, but how useful is something like this? I mean changing a TOH is not too easy -- at least mine is attached quite well to the phone body, so it takes time and considerable effort to "peal it off". Much easier to swipe and change the ambience or execute some script file from the phone (which might have a "shortcut icon" on the UI, so it is just a simple tap). Or what I miss? ;)

CsTom ( 2014-02-05 10:18:41 +0300 )edit

Okay, a GUI button would be easier, but changing the TOH is way cooler -- and it can be used to show off Jolla's capabilities. For example, the white TOH now enables my work email account and displays a "work" background, and the red one disables work emails, so there is only private mail left. Pretty cool for two days of hacking :D

gehowa ( 2014-02-05 11:31:32 +0300 )edit

Change profile work/personal - nice feature, but this may be switched via gesture as is on BB10. And .. IMHO this feature will not be on SailfishOS in this year .. not with current amount developers in Jolla for work on this Jolla closed things. :(

Kaacz ( 2014-02-05 14:33:23 +0300 )edit

1 Answer

Sort by » oldest newest most voted
9

answered 2014-02-03 14:34:02 +0300

thp gravatar image

The tohd service is running on the System D-Bus as com.jolla.tohd. It has an object with path /com/jolla/tohd which in turn has properties such as Docked, Ready and TOHID.

To get the current values, you can use:

dbus-send --system --dest=com.jolla.tohd --print-reply /com/jolla/tohd org.freedesktop.DBus.Properties.GetAll string:com.jolla.tohd

To watch the property changes on the command line, you can use:

dbus-monitor --system "type='signal',sender='com.jolla.tohd',path='/com/jolla/tohd'"

If you want to script that, you can use e.g. python-dbus (if you just want to SSH in to your device and run a background service) or Qt5's DBus support (if you want to write a GUI application that makes use of the TOH ID).

edit flag offensive delete publish link more

Comments

Thanks, will try that.

gehowa ( 2014-02-03 15:00:37 +0300 )edit

OK. Now we need to know way to "touch" daemon "do NFC read action" .. not only in time "TOH switch is ON". And if NFC tag is read trough TOH, next step is replace tohd daemon by another daemon for real use.

Kaacz ( 2014-02-05 14:44:27 +0300 )edit

Question tools

Follow
8 followers

Stats

Asked: 2014-02-03 13:39:18 +0300

Seen: 1,580 times

Last updated: Feb 04 '14