Qball's Weblog

Putting IfThenElse to work

Tags IfThenElse 

I blogged previous about IfThenElse..  It is a very simple tool, but combined with random other programs can become a fun and powerful tool:

The following script locks my screen, puts jabber status on away when I turn off the lights in the room.  Unlocks the screen when turning the lights back on.. Also when I start vlc/totem/mplayer it will set my jabber status to away “watching a movie”.

 

This is all described in the following xml file:

?View Code XML
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<interface>
	<object class="IfThenElseTimerTrigger" id="lights_timer">
		<property name="timeout">5</property>
		<child>
			<object class="IfThenElseMultiAction" id="main_multiplier">
				<child>
					<object class="IfThenElseChain" id="lights_chain">
						<child type="if">
							<object class="IfThenElseExternalToolCheck" id="check_light">
								<property name="cmd">./Scripts/domotica_check_light.sh</property>
								<property name="true_status">1</property>
								<property name="false_status"></property>
								<property name="compare_old_state">true</property>
							 </object>
						</child>
						<child type="then">
							<object class="IfThenElseMultiAction" id="multiplier">
								<child>
									<object class="IfThenElseExternalToolAction" id="lights_off_action">
										<property name="cmd">gnome-screensaver-command -a -l</property>
										<property name="kill_child">false</property>
									</object>
								</child>
								<child>
									<object class="IfThenElseExternalToolAction" id="lights_off_action2">
										<property name="cmd">mpc -h 192.150.0.106 stop</property>
										<property name="kill_child">false</property>
									</object>
								</child>
								<child>
									<object class="IfThenElseExternalToolAction" id="lights_off_action3">
										<property name="cmd">gajim-remote change_status away</property>
										<property name="kill_child">false</property>
									</object>
								</child>
							</object>
						</child>
						<child type="else">
							<object class="IfThenElseMultiAction" id="lights_on_action_multi">
								<child>
									<object class="IfThenElseExternalToolAction" id="lights_on_action">
										<property name="cmd">gnome-screensaver-command -d</property>
										<property name="kill_child">false</property>
									</object>
								</child>
								<child>
									<object class="IfThenElseExternalToolAction" id="lights_on_action2">
										<property name="cmd">gajim-remote change_status online</property>
										<property name="kill_child">false</property>
									</object>
								</child>
							</object>
						</child>
					</object>
				</child>
				<child>
					<object class="IfThenElseChain" id="movie_chain">
						<child type="if">
							<object class="IfThenElseExternalToolCheck" id="check_movie">
								<property name="cmd">./Scripts/check_movie.sh</property>
								<property name="true_status">1</property>
								<property name="false_status"></property>
								<property name="compare_old_state">true</property>
							 </object>
						</child>
						<child type="then">
							<object class="IfThenElseExternalToolAction" id="movie_on_action">
								<property name="cmd">gajim-remote change_status away "watching movie"</property>
								<property name="kill_child">false</property>
							</object>
						</child>
						<child type="else">
							<object class="IfThenElseExternalToolAction" id="movie_off_action">
								<property name="cmd">gajim-remote change_status online</property>
								<property name="kill_child">false</property>
							</object>
						</child>
					</object>
				</child>
			</object>
		</child>
	</object>
</interface>