Author Topic: OSD.ShowText will not show results from Regex  (Read 2084 times)

0 Members and 1 Guest are viewing this topic.

paulbeauvais

  • Jr. Member
  • **
  • Posts: 22
  • Karma: 2
    • View Profile
OSD.ShowText will not show results from Regex
« on: February 22, 2016, 12:08:33 AM »
I am honestly not sure if this is an OSD issues, a Regex issue, or a Me issue.

I started to write a plugin to trigger events on sunrise and sunset (as an experiment), but then it hit me that all the tools to do this were already there. 

I could use the special google calendar for sunrise and sunset to get the time and then use regular expression to pull out the information.  In testing I tried to through the results of the regex into an osd.showtext using {match.1}.  The OSD box shows up on the screen, but it is solid black with no text in it. (OSD.showtext is working with other results like {lastresult}.

I used the regext tool and I do get the results I think I am going to get (namely the time).

Logfile and history both show 1 result coming back.

any thoughts?

Code: [Select]
<?xml version="1.0" encoding="utf-16"?>
<!--VoxCommando 2.2.0.7-->
<command id="823" name="newcommandname" enabled="true" alwaysOn="False" confirm="True" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
  <action>
    <cmdType>GgCal.GetDay</cmdType>
    <params>
      <param>4</param>
      <param>sunrise and sunset for Philadelphia</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>Results.RegEx</cmdType>
    <params>
      <param>\d{1,2}:\d{2}am</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>OSD.ShowText</cmdType>
    <params>
      <param>{Match.1}</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
</command>

Kalle

  • $upporter
  • Hero Member
  • *****
  • Posts: 2319
  • Karma: 47
    • View Profile
Re: OSD.ShowText will not show results from Regex
« Reply #1 on: February 22, 2016, 01:25:11 AM »
Hi paulbeauvais,
so far I can see - please try brackets around your regex like   (\d{1,2}:\d{2}am)
« Last Edit: February 22, 2016, 03:35:59 AM by Kalle »
***********  get excited and make things  **********

paulbeauvais

  • Jr. Member
  • **
  • Posts: 22
  • Karma: 2
    • View Profile
Re: OSD.ShowText will not show results from Regex
« Reply #2 on: February 22, 2016, 01:39:22 AM »
That worked, but I have no idea why that worked.  The regular expression itself does not need it, and the documentation does not show it. 

One oddity, putting the parenthesis around the expression causes vc to return the result twice, once in {match.1} and once in {match1.1}.

Thanks for the help.

PegLegTV

  • $upporter
  • Hero Member
  • *****
  • Posts: 500
  • Karma: 43
    • View Profile
Re: OSD.ShowText will not show results from Regex
« Reply #3 on: February 22, 2016, 02:34:54 AM »
here's another method of getting sunrise and sunset events

you can use the WUnder plugin if you don't want to use the GgCal Plugin:

Code: [Select]
<?xml version="1.0" encoding="utf-16"?>
<!--VoxCommando 2.2.1.4-->
<commandGroup open="True" name="Sunrise / Sunset" enabled="True" prefix="" priority="0" requiredProcess="" description="">
  <command id="1047" name="Sunrise / Sunset" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
    <action>
      <cmdType>WUnder.GetCustom</cmdType>
      <params>
        <param>{A.sunset}</param>
      </params>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <action>
      <cmdType>VC.SetEventTimer</cmdType>
      <params>
        <param>{LastResult}</param>
        <param>Sunset</param>
        <param>On</param>
      </params>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <action>
      <cmdType>WUnder.GetCustom</cmdType>
      <params>
        <param>{A.sunrise}</param>
      </params>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <action>
      <cmdType>VC.SetEventTimer</cmdType>
      <params>
        <param>{LastResult}</param>
        <param>Sunrise</param>
      </params>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <event>VC.Loaded</event>
    <event>Sunrise</event>
    <event>Sunset</event>
  </command>
</commandGroup>

this command uses VC.SetEventTimer set to sunrise and sunset
it will set the timers when you first start VC and then Set them again at Sunrise and at Sunset



nime5ter

  • Administrator
  • Hero Member
  • *****
  • Posts: 2012
  • Karma: 61
    • View Profile
    • Getting Started with VoxCommando
Re: OSD.ShowText will not show results from Regex
« Reply #4 on: February 22, 2016, 08:06:35 AM »
I started to write a plugin to trigger events on sunrise and sunset (as an experiment), but then it hit me that all the tools to do this were already there. 

This is absolutely true. One of the things that comes up often on the forum when users ask for special plugins is the fact that most of what they want is already possible, but requires becoming more familiar with the program .

For the most part, plugins simply make it easier for users who are not programmers. When we made plugin suggestions, it was based on your expressed desire to start with something easy, while still being of use to other users.

If you take a look at the XML exchange board, there's a thread from 2014 where Haddood shows how to trigger daily sunrise and sunset events using the Weather Underground plugin (WUnder). http://voxcommando.com/forum/index.php?topic=1711.
« Last Edit: February 22, 2016, 09:29:02 AM by nime5ter »
TIPS: POST VC VERSION #. Explain what you want VC to do. Say what you've tried & what happened, or post a video demo. Attach VC log. Link to instructions followed.  Post your command (xml)

paulbeauvais

  • Jr. Member
  • **
  • Posts: 22
  • Karma: 2
    • View Profile
Re: OSD.ShowText will not show results from Regex
« Reply #5 on: February 22, 2016, 10:42:43 AM »
Sorry, I just gave too much information. I am playing around and trying to learn.  I do not really need a sunrise/sunset event.  I come up with little projects so I have a goal while learning.  I will try not to give the extraneous information in the future as to not confuse the issues I am having.

I have some ideas for plugins (like the FTP and Wordpress plugins that I am working on) but I do not want to recreate functionality unless there is some sort of advantage (clearly there are already easy ways to make sunrise sunset work).

I was really just asking about why my regular expression did not work (still not sure why the parenthesis work, but I am not going to over think it).

As always you guys are great with the answers and it makes this platform much more useful.  I cannot figure out the relationship you guys have to each other, seems like there is a small core community answering most of the questions on the forums.

have a good day!

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7715
  • Karma: 116
    • View Profile
    • VoxCommando
Re: OSD.ShowText will not show results from Regex
« Reply #6 on: February 22, 2016, 12:27:06 PM »
I was really just asking about why my regular expression did not work (still not sure why the parenthesis work, but I am not going to over think it).

That's just how RegEx works.  You use brackets to specify which part of the pattern you want to capture.  If you were forced to keep the entire pattern then RegEx would be pretty useless most of the time.

You can look on any website that talks about RegEx to learn about the purpose of  brackets.
http://www.rexegg.com/regex-cookbook.html#capturing

If you use more than one set of brackets those give you submatches {Match.*.1}, {Match.*.2} etc. and those are concatenated into {Match.*}.  If you only use one set of brackets to capture then {Match.*} will be equivalent to {Match.*.1}.

There is only one example on the wiki for the Results.Regex action.  It is very simple and shows how brackets are used:

Code: [Select]
For example, if {LastResult} contains this line:
Artist: Beck

then the regex pattern might be:
Artist:\s(.*?)

which would return the string Beck as a match.

There is some more info on the use of the {Match} variables on the variables page of the wiki: http://voxcommando.com/mediawiki/index.php?title=Variables

There are numerous examples on the forum which show more complex scenarios including using multiple captures.

Even though it is a bit long, if you take the time to watch the tutorial on using the Regex Tool, you won't regret it!


paulbeauvais

  • Jr. Member
  • **
  • Posts: 22
  • Karma: 2
    • View Profile
Re: OSD.ShowText will not show results from Regex
« Reply #7 on: February 22, 2016, 12:37:11 PM »
The brackets are fine and make sense.  The issue is that \d{1,2}:\d{2}am returns a result, works in the RgX tool, but when I want to display the results in OSD I just get a black box.

(\d{1,2}:\d{2}am)  (the expression with parenthesis around it) returns two results (one in {Match.1} and on in Match.1.1), but OSD displays the proper results.

I am more than happy using the parenthesis.  it is an easy work around, and give the results we need.

thanks,

Paul

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7715
  • Karma: 116
    • View Profile
    • VoxCommando
Re: OSD.ShowText will not show results from Regex
« Reply #8 on: February 22, 2016, 12:39:34 PM »
It is not a work around.  You just need to learn the correct way to do it.

If you watch the video you will understand.
« Last Edit: February 22, 2016, 12:42:44 PM by jitterjames »