Author Topic: Application Refocusing  (Read 2678 times)

lkearney999

  • Guest
Application Refocusing
« on: April 18, 2018, 11:55:51 PM »
https://i.imgur.com/99odmx7.png
The idea is to minimize and maximize chrome on command but when execute it loops open and closed.

Gary

  • Administrator
  • Hero Member
  • *****
  • Posts: 2832
Re: Application Refocusing
« Reply #1 on: April 19, 2018, 07:21:06 AM »
By just looking at your actions, it should work without looping.  In the edit command screen what do you have set in the repeating section for that command?

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4782
  • RTFM
Re: Application Refocusing
« Reply #2 on: April 19, 2018, 08:08:16 AM »
I duplicated the command structure, but as I don't have Chrome to test with I used Notepad instead; It doesn't loop on my machine.


That said, using jumps should not be necessary at all if you use "Else If" and "Else" actions:
Code: [Select]
Set Text [~targetWindowName] to '*Google Chrome*'
Begin Text Compare : [{WINDOWEXISTS:~targetWindowName}] Equals '0'
    Run application 'C:\Program Files (x86)\Google\Chrome\chrome.exe'
    Set Boolean [Chrome State] to True
Else If Boolean Compare : [Chrome State] Equals False
    Display window '*Google Chrome*' as [Maximize]
    Set Boolean [Chrome State] to True
Else
    Display window '*Google Chrome*' as [Minimize]
    Set Boolean [Chrome State] to False
End Condition

This also uses a token to check whether Chrome is running(It's actually checking whether a Chrome window exists, because there is no built-in method of checking if a process exists, currently), so that if you close Chrome the command will reopen Chrome and reset its internal state so that the next execution should minimize it(I'm assuming Chrome always starts with a visible window).


There is a topic that attempts to explain the basics of control flow, which may be of interest.