News:

HOT TIP! Commands and groups can be copied and pasted directly from your command editor to the forum, and vice versa. This makes sharing command XML on the forum much easier!

Main Menu

Storing PC / User Name in a variable

Started by Haddood, February 17, 2016, 04:34:13 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Haddood

if one shares VC config cross multiple PCs (I use onedrive to sync it across 2 PCs), one might need to do things based on which PC VC is running on. Example: setting the microphone to listen to, or if the PCs are in different rooms, commands like "Lights On" will mean to turn different lights on ...etc.
here is a very simple and easy command to capture the PC name in a variable.

update: the command has been revised to store as well the current user name ... on XP requires service pack 2, and I kept the original as disabled for reference


<?xml version="1.0" encoding="utf-16"?>
<!--VoxCommando 2.2.1.4-->
<command id="867" name="Get PC &amp; User name" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
  <action>
    <cmdType>Launch.Capture</cmdType>
    <params>
      <param>C:\Windows\System32\hostname.exe</param>
      <param />
      <param>true</param>
    </params>
    <cmdRepeat>0</cmdRepeat>
  </action>
  <action>
    <cmdType>Results.SetVar</cmdType>
    <params>
      <param>PCName</param>
      <param>{LastResult}</param>
    </params>
    <cmdRepeat>0</cmdRepeat>
  </action>
  <action>
    <cmdType>Launch.Capture</cmdType>
    <params>
      <param>C:\Windows\System32\whoami.exe</param>
      <param />
      <param>true</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>Results.RegEx</cmdType>
    <params>
      <param>(.*?)\\(.*)</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>Results.SetVar</cmdType>
    <params>
      <param>PCName</param>
      <param>{Match.1.1}</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>Results.SetVar</cmdType>
    <params>
      <param>UserName</param>
      <param>{Match.1.2}</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <event>Windows.GetPC-UserName</event>
</command>
When Voice command gets tough, use hand gestures

PegLegTV

here's another method but using python instead

<?xml version="1.0" encoding="utf-16"?>
<!--VoxCommando 2.2.1.4-->
<command id="879" name="PC Username" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
  <action>
    <cmdType>PY.ExecString</cmdType>
    <params>
      <param>import getpass{CR}result=username = getpass.getuser()</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>Results.SetVar</cmdType>
    <params>
      <param>Username</param>
      <param>{LastResult}</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <event>VC.Loaded</event>
</command>