Variable empty vs not set

4,841 views
Skip to first unread message

Kevin Taylor

unread,
Jul 25, 2011, 5:30:24 AM7/25/11
to tas...@googlegroups.com
If I set a a varable e.g. %input using a Variable Query, and hit the green tick without entering any text,
the variable is set to an empty string. The variable editor shows it as being set.
However, if I then (in the same task) set the text of a Zoom element to this value, "%input" appears instead of a blank, as if it were not set.
If I set another variable to a string containing the value of %input, e.g. Set %feedback = "You typed %input", I get "%input" instead of a blank.
Further, I cannot find any way to distinguish, using "Is Set", "Isn't Set", "Matches" or "Doesn't Match" between %input being blank and %input being not set.

Kevin
(Using Tasker v 1.1b13m)

Pent

unread,
Jul 25, 2011, 12:17:57 PM7/25/11
to Tasker
> If I set a a varable e.g. %input using a Variable Query, and hit the green
> tick without entering any text,
> the variable is set to an empty string. The variable editor shows it as
> being set.

No, just because it shows it doesn't mean it has a value. That's
because it's mentioned somewhere in your profiles and tasks and the
variable editor thinks that you might want to give it a value so it
shows it for convenience.

However, variables can get set to empty strings sometimes. You can
check for an empty string with !+ (not-one-or-more-characters).

Pent

Kevin Taylor

unread,
Jul 25, 2011, 4:58:45 PM7/25/11
to tas...@googlegroups.com
Using the variable in this case (no text entered), I get the value "%input" printed, as if it were not set,
but defining four actions after the Variable Query with the conditions:
A if %input Is Set
B if %input Isn't Set
C if %input Matches +
D if %input Doesn't Match + (Is this what you mean by !+ ? - I also tried %input Matches !+ with the same result)
actions A and C are executed,
not A and D as I would expect if %input is set to an empty string,
or B and D as I would expect if %input is not set.
In fact, A and C are executed whether I enter text or not.

I do Variable Clear before the Variable Query, to make sure I always start in the same state.

Kevin

Pent

unread,
Jul 29, 2011, 4:29:22 AM7/29/11
to Tasker
> Using the variable in this case (no text entered), I get the value "%input"
> printed, as if it were not set,
> but defining four actions after the Variable Query with the conditions:
> A if %input Is Set
> B if %input Isn't Set
> C if %input Matches +
> D if %input Doesn't Match + (Is this what you mean by !+ ? - I also tried
> %input Matches !+ with the same result)
> actions A and C are executed,
> not A and D as I would expect if %input is set to an empty string,
> or B and D as I would expect if %input is not set.
> In fact, A and C are executed whether I enter text or not.

Thanks for experimenting scientifically :-)

I'll take a look. C should not be matching either empty or unset for
starters.

According to the Variable Query code, if you enter an empty string the
variable should be set to an empty string.

Pent

Pent

unread,
Jul 29, 2011, 6:23:42 AM7/29/11
to Tasker

> I'll take a look. C should not be matching either empty or unset for
> starters.

OK, the reason for that is that the variable replacement code is
treating an empty string as 'not set' and leaving the variable name
there, which matches
+.

It think it's time to make a clear differentation between empty-string
and not-set, and variables with an empty string set should have their
variable name replaced with that empty string in texts. However, the
timing is bad to implement that right now, it will have to wait till
after 1.1 since it's bound to cause some incompatibility with some
people's tasks.

Pent

Marty Elder

unread,
Nov 22, 2013, 10:03:51 PM11/22/13
to tas...@googlegroups.com
Was this ever worked on? Just wondering as I'm working with Tasker and trying to test for an app running or not running (not cached either) and setting a %TestVar to the value in /proc/{pid}/oom_adj .. but I can't seem to figure out how to test when the value doesn't exist but Tasker still has my Variable and considers it to be set.

OOM_ADJ is 0/1/2 if the app is running or in the background.  It's > 2 if it's been recently closed.  But once the process clears the OOM_ADJ is no longer present so you can't test for it and the variable stays empty but testing shows it considers it to be "something".

Bob Hansen

unread,
Nov 22, 2013, 10:30:59 PM11/22/13
to tas...@googlegroups.com
If an attempt is made to get the oom_adj value and it doesn't exist the command will fail and an error flag will be set. I have used Run Shell to get oom_adj values. Here is an example:

  SwiftKey Check (149)
  A1: Run Shell [ Command:cat /proc/$(pgrep com.touchtype.swiftkey)/oom_adj Timeout (Seconds):0 Use Root:Off Store Output In:%oom_adj Store Errors In:%err Store Result In: Continue Task After Error:On ]
  A2: If [ %err Is Set ]
  A3: Flash [ Text:SwiftKey not running Long:On ]
  A4: Else If [ %oom_adj < 2 ]
  A5: Flash [ Text:SwiftKey 
  %oom_adj Running in foreground Long:On ]
  A6: Else If [ %oom_adj > 1 ]
  A7: Flash [ Text:SwiftKey
  %oom_adj Running in background or in memory Long:On ]
  A8: End If

Bob Hansen

unread,
Nov 22, 2013, 10:32:39 PM11/22/13
to tas...@googlegroups.com
Oh, as far as changing how an empty string is handled - it has not been changed.

Wietse van Buitenen

unread,
Nov 23, 2013, 2:10:30 AM11/23/13
to tas...@googlegroups.com
You can check if a var is empty with regex:
If %myvar Matches Regex ^%.*
This will be true if it's empty
Have been using it for some time now.

lavoice

unread,
May 29, 2015, 1:29:54 PM5/29/15
to tas...@googlegroups.com
Thank you Wietse. That's exactly what I was looking for.

Mike Wyzlic

unread,
Jun 12, 2015, 1:33:33 AM6/12/15
to tas...@googlegroups.com
You can also check by using %myvar eq \%myvar.  By escaping the % with a \, the comparison looks for a literal % sign instead of evaluating another variable.   This accomplishes the same thing as %myvar Matches Regex ^%.*, but is more specific in that it will only be true if %myvar is %myvar (or empty).  The Regex match would also catch any situation where %myvar actually had a real % sign as the first character of its value - though that would probably be very rare.
Reply all
Reply to author
Forward
0 new messages