forked from kuri65536/python-for-android
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtasker_example.py3
More file actions
63 lines (53 loc) · 1.84 KB
/
Copy pathtasker_example.py3
File metadata and controls
63 lines (53 loc) · 1.84 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
__author__ = "Brian Lenihan <brian.lenihan@gmail.com"
__copyright__ = "Copyright (c) 2012 Python for Android Project"
__license__ = "Apache License, Version 2.0"
import os
import logging
import android
"""
Create and set a new Tasker variable, display the variable's value in a Tasker
popup, and then clear the variable.
Misc / Allow External Access must be set in Tasker's prefs.
Tasker action code reference:
http://tasker.dinglisch.net/ActionCodes.java
"""
SET_VARIABLE = 547
CLEAR_VARIABLE = 549
POPUP = 550
logging.basicConfig(level=logging.INFO)
class Tasker(object):
def __init__(self):
self.droid = android.Android()
self.extras = dict(
version_number = '1.0',
task_name = 'tasker_demo.{}'.format(os.getpid()),
task_priority = 9)
self.actions = 0
def bundle(self, action, *args):
# Unused parameters are padded with False
args = list(args)
args.extend([False]*(6-len(args)))
self.actions += 1
self.extras.update(
{'action{}'.format(self.actions) : dict(
{'action' : action,
'arg:1' : args[0],
'arg:2' : args[1],
'arg:3' : args[2],
'arg:4' : args[3],
'arg:5' : args[4],
'arg:6' : args[5]})
})
def broadcast_intent(self):
intent = self.droid.makeIntent(
'net.dinglisch.android.tasker.ACTION_TASK', None, None, self.extras).result
logging.debug("-- {}".format(intent))
self.droid.sendBroadcastIntent(intent)
if __name__ == "__main__":
tasker = Tasker()
tasker.bundle(SET_VARIABLE, "%PY4A_DEMO", "Hello from python")
# Popup: String title, String text, String background image, Scene layout,
# Integer timeout, Boolean show over keyguard, Boolean condition
tasker.bundle(POPUP, "Tasker", "%PY4A_DEMO", "", "Popup", 5, True, False)
tasker.bundle(CLEAR_VARIABLE, "%PY4A_DEMO")
tasker.broadcast_intent()