Author Topic: I can't seem to get a command to work the way it should.  (Read 1380 times)

iceblast

  • Sr. Member
  • ****
  • Posts: 374
I can't seem to get a command to work the way it should.
« on: July 03, 2019, 01:31:09 PM »
I use the browser Opera. Opera has a window called Speed Dial - Opera.

I want to hit a button, and I want VA to do 3 things.

1. If the Active Windows Title is Speed Dial - Opera, I want it to put the Cursor in the address bar. The command for that is Left Ctrl+Left Shift+\

2. If the Active Windows Title isn't Speed Dial - Opera, and Speed Dial - Opera is open in the background, I would like it brought to the Foreground, and made the Active Window, then hit Left Ctrl+Left Shift+\

3. If Speed Dial - Opera doesn't exist, I would like Speed Dial - Opera to be opened, by this command.

Run application 'c:\program files (x86)\opera\opera 19\launcher.exe'


The way it's working now is. It will do 1. and 2., but it will continue on and do 3. as well. Opening a extra Speed Dial that I don't need.

I've been using this command for a long time, and it never use to do this. Now, I can't seem to get it to stop doing it. I have no idea what I'm doing wrong, or if VA is just ignoring a command.

Here is how my command looks, this use to work. Either I'm doing something wrong, wouldn't surprise me, or VA is.

Code: [Select]
Begin Text Compare : [{ACTIVEWINDOWTITLE}] Equals 'Speed Dial - Opera'
    Pause 0.2 seconds
    Press and release Left Ctrl+Left Shift+\ | keys
End Condition - Exit when condition met
Begin Text Compare : [{ACTIVEWINDOWTITLE}] Does Not Equal 'Speed Dial - Opera'
    Display window 'Speed Dial - Opera' as [Show]
    Pause 1 second
    Press and release Left Ctrl+Left Shift+\ | keys
End Condition
Begin Text Compare : [{ACTIVEWINDOWTITLE}] Does Not Equal 'Speed Dial - Opera'
    Run application 'c:\program files (x86)\opera\opera 19\launcher.exe'
    Pause 1 second
    Press and release Left Ctrl+Left Shift+\ | keys
End Condition - Exit when condition met

Thanks for your time, hope there is a answer.



Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4782
  • RTFM
Re: I can't seem to get a command to work the way it should.
« Reply #1 on: July 03, 2019, 01:57:38 PM »
You're instructing VoiceAttack to do exactly what you're describing.

The way it is set up, your command cannot accomplish the intended behavior. You're checking the active window title twice, but never whether the window exists in the background.

It also appears you have
Code: [Select]
End Conditionwhere you intended to have
Code: [Select]
End Condition - Exit when condition met

You can use the "{WINDOWEXISTS:}" token (which requires a text value); I would also really recommend using "Else If" and "Else", instead:
Code: [Select]
Set Text [~speedDialTitle] to 'Speed Dial - Opera'
Begin Text Compare : [{ACTIVEWINDOWTITLE}] Equals 'Speed Dial - Opera'
    Pause 0.2 seconds
Else If  Text Compare : [{WINDOWEXISTS:~speedDialTitle}] Equals '1'
    Display window 'Speed Dial - Opera' as [Show]
    Pause 1 second
Else
    Run application 'c:\program files (x86)\opera\opera 19\launcher.exe'
    Pause 1 second
End Condition
Press and release Left Ctrl+Left Shift+\ | keys

This aids readability by visually grouping mutually exclusive conditions, and is more compact.

There is also no need to use the "When this block is reached, exit command if condition met" option at the end of a command; When the last action in the action list is reached, the command will exit automatically.

Instead of duplicating the keypress action for each conditional branch, only the actions that are unique to each remain, and the same keypress action is now shared by all.

iceblast

  • Sr. Member
  • ****
  • Posts: 374
Re: I can't seem to get a command to work the way it should.
« Reply #2 on: July 03, 2019, 02:46:21 PM »
Sorry, but your command doesn't work. Mine would at least switch to the Speed Dial - Opera window, before going on to opening a new speed dial anyway, yours doesn't, it just directly opens a new speed dial.

This is your command I'm using.
Code: [Select]
Set Text [Speed] to 'Speed Dial - Opera'
Begin Text Compare : [{ACTIVEWINDOWTITLE}] Equals 'Speed Dial - Opera'
    Pause 0.2 seconds
Else If Text Compare : [{WINDOWEXISTS:Speed}] Equals '1'
    Display window 'Speed Dial - Opera' as [Show]
    Pause 1 seconds
Else
    Run application 'c:\program files (x86)\opera\opera 19\launcher.exe'
    Pause 1 second
End Condition
Press and release Left Ctrl+Left Shift+\ | keys


My Old Command
Code: [Select]
Begin Text Compare : [{ACTIVEWINDOWTITLE}] Equals 'Speed Dial - Opera'
    Pause 0.2 seconds
    Press and release Left Ctrl+Left Shift+\ | keys
End Condition - Exit when condition met
Begin Text Compare : [{ACTIVEWINDOWTITLE}] Does Not Equal 'Speed Dial - Opera'
    Display window 'Speed Dial - Opera' as [Show]
    Pause 1 second
    Press and release Left Ctrl+Left Shift+\ | keys
End Condition
Begin Text Compare : [{ACTIVEWINDOWTITLE}] Does Not Equal 'Speed Dial - Opera'
    Run application 'c:\program files (x86)\opera\opera 19\launcher.exe'
    Pause 1 second
    Press and release Left Ctrl+Left Shift+\ | keys
End Condition - Exit when condition met


Let me explain my thought process. From what I understand, VA reads a command in order from top to bottom.

1. It checks that Speed Dial - Opera is the Active Window.
Code: [Select]
Begin Text Compare : [{ACTIVEWINDOWTITLE}] Equals 'Speed Dial - Opera'
    Pause 0.2 seconds
    Press and release Left Ctrl+Left Shift+\ | keys
End Condition - Exit when condition met

2. If Speed Dial - Opera isn't Active Window, try to bring it Forward.
Code: [Select]
Begin Text Compare : [{ACTIVEWINDOWTITLE}] Does Not Equal 'Speed Dial - Opera'
    Display window 'Speed Dial - Opera' as [Show]
    Pause 1 second
    Press and release Left Ctrl+Left Shift+\ | keys
End Condition

I give it 1 second to bring the window to the foreground and put the cursor in the address bar. The one second is long enough to do all those things. So by the time it hits 3. The Active window should be Speed Dial - Opera, which should mean it shouldn't run 3. Because Active Window does Equal Speed Dial - Opera. Yet, it continues on to 3.

3. Speed Dial - Opera isn't a Window, then open a new one.
Code: [Select]
Begin Text Compare : [{ACTIVEWINDOWTITLE}] Does Not Equal 'Speed Dial - Opera'
    Run application 'c:\program files (x86)\opera\opera 19\launcher.exe'
    Pause 1 second
    Press and release Left Ctrl+Left Shift+\ | keys
End Condition - Exit when condition met
[/code]


Now, this command use to work all the time, now it works only some of the time. Sorry, but your command never worked.

It's a real head scratcher. This should be a simple command, yet, it's not.

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4782
  • RTFM
Re: I can't seem to get a command to work the way it should.
« Reply #3 on: July 03, 2019, 03:01:58 PM »
My example works fine on my machine, though I don't have Opera to test with, so I used Notepad instead:
Code: [Select]
Set Text [~targetTitle] to 'Untitled - Notepad'
Begin Text Compare : [{ACTIVEWINDOWTITLE}] Equals [~targetTitle]
    Write [Blue] 'Window is active' to log
    Pause 0,2 seconds
Else If Text Compare : [{WINDOWEXISTS:~targetTitle}] Equals '1'
    Write [Blue] 'Window exists' to log
    Display window '{TXT:~targetTitle}' as [Show]
    Pause 1 second
Else
    Run application 'notepad'
    Pause 1 second
End Condition
Press A key and hold for 0,01 seconds and release

Are you sure the complete window title is still "Speed Dial - Opera"? Do you have the Opera window minimized?

iceblast

  • Sr. Member
  • ****
  • Posts: 374
Re: I can't seem to get a command to work the way it should.
« Reply #4 on: July 03, 2019, 03:25:49 PM »
Yeah, I'm positive the windows title is correct, and it's not Minimize. Otherwise it would never bring forward Speed Dial - Opera.

Ok, It seems to be working with this command now. Hopefully, that doesn't change.

Code: [Select]
Begin Text Compare : [{ACTIVEWINDOWTITLE}] Contains 'Speed Dial - Opera'
    Pause 0.2 seconds
    Press and release Left Ctrl+Left Shift+\ | keys
End Condition - Exit when condition met
Display window 'Speed Dial - Opera' as [Show]
Pause 1 second
Begin Text Compare : [{ACTIVEWINDOWTITLE}] Does Not Equal 'Speed Dial - Opera'
    Run application 'c:\program files (x86)\opera\opera 19\launcher.exe'
    Pause 1 second
End Condition
Press and release Left Ctrl+Left Shift+\ | keys