Class App


  • public class App
    extends java.lang.Object
    App implements features to manage (open, switch to, close) applications. on the system we are running on and to access their assets like windows
    TAKE CARE: function behavior differs depending on the running system (cosult the docs for more info)
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  App.Type  
    • Constructor Summary

      Constructors 
      Constructor Description
      App()  
      App​(java.lang.String name)  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean close()
      tries to close the app defined by this App instance, waits max 10 seconds for the app to no longer be running
      boolean close​(int waitTime)
      tries to close the app defined by this App instance, waits max given seconds for the app to no longer be running
      static boolean close​(java.lang.String appName)
      tries to identify a running app with the given name and then tries to close it
      int closeByKey()  
      int closeByKey​(int waitTime)  
      boolean focus()
      tries to make it the foreground application bringing its frontmost window to front
      static App focus​(java.lang.String title)
      tries to identify a running app with name or (part of) window title bringing its topmost window to front
      static App focus​(java.lang.String title, int index)
      tries to identify a running app with name or (part of) window title bringing its window with given index to front
      static Region focusedWindow()
      evaluates the region currently occupied by the systemwide frontmost window (usually the one that has focus for mouse and keyboard actions)
      static java.util.List<App> getApps()  
      static java.util.List<App> getApps​(java.lang.String name)  
      static java.lang.String getClipboard()
      evaluates the current textual content of the system clipboard
      java.lang.String getExec()  
      java.lang.String getName()  
      java.lang.String getNameGiven()  
      java.lang.String getOptions()  
      int getPID()  
      java.lang.String getTitle()  
      java.lang.String getTitle​(int windowNumber)  
      java.lang.String getToken()  
      java.util.List<Region> getWindows()  
      java.lang.String getWindowTitle()  
      java.lang.String getWorkDir()  
      boolean hasFocus()  
      boolean hasWindow()  
      boolean isClosing()  
      boolean isRunning()  
      boolean isRunning​(int maxTime)  
      boolean isValid()  
      boolean isWindow()  
      static void listApps()  
      static void listApps​(java.lang.String name)  
      static void log​(java.lang.String msg, java.lang.Object... args)  
      static void logOff()  
      static void logOn()  
      boolean open()
      tries to open the app defined by this App instance
      do not wait for the app to get running
      boolean open​(int waitTime)
      tries to open the app defined by this App instance
      and waits until app is running
      static App open​(java.lang.String appName)
      tries to open an app using the given name and waits 1 sec for being ready If the app is already open, it is brought to foreground
      static App open​(java.lang.String appName, int waitTime)
      tries to open an app using the given name and waits waitTime for being ready If the app is already open, it is brought to foreground
      static boolean openLink​(java.lang.String url)  
      static void pause​(float time)  
      static void pause​(int time)  
      void reset()  
      static int run​(java.lang.String cmd)
      the given text is parsed into a String[] suitable for issuing a Runtime.getRuntime().exec(args).
      static void setClipboard​(java.lang.String text)
      sets the current textual content of the system clipboard to the given text
      void setExec​(java.lang.String exec)  
      void setFocused​(boolean state)  
      void setName​(java.lang.String name)  
      void setNameGiven​(java.lang.String nameGiven)  
      void setPID​(int appPID)  
      void setPID​(java.lang.String appPID)  
      void setToken​(java.lang.String appToken)  
      App setUsing​(java.lang.String options)  
      void setWindow​(java.lang.String appWindow)  
      boolean setWorkDir()  
      boolean setWorkDir​(java.lang.String workDirPath)  
      static Region start​(App.Type appType)  
      java.lang.String toString()  
      java.lang.String toStringShort()  
      Region waitForWindow()  
      Region waitForWindow​(int seconds)  
      Region window()
      evaluates the region currently occupied by the topmost window of this App instance.
      Region window​(int winNum)
      evaluates the region currently occupied by the window with the given number of this App instance.
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • lastRunReturnCode

        public static int lastRunReturnCode
      • lastRunStdout

        public static java.lang.String lastRunStdout
      • lastRunStderr

        public static java.lang.String lastRunStderr
      • lastRunResult

        public static java.lang.String lastRunResult
    • Constructor Detail

      • App

        public App()
      • App

        public App​(java.lang.String name)
    • Method Detail

      • isWindow

        public boolean isWindow()
      • waitForWindow

        public Region waitForWindow()
      • waitForWindow

        public Region waitForWindow​(int seconds)
      • openLink

        public static boolean openLink​(java.lang.String url)
      • pause

        public static void pause​(int time)
      • pause

        public static void pause​(float time)
      • log

        public static void log​(java.lang.String msg,
                               java.lang.Object... args)
      • logOn

        public static void logOn()
      • logOff

        public static void logOff()
      • reset

        public void reset()
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • toStringShort

        public java.lang.String toStringShort()
      • getApps

        public static java.util.List<App> getApps()
      • getApps

        public static java.util.List<App> getApps​(java.lang.String name)
      • listApps

        public static void listApps()
      • listApps

        public static void listApps​(java.lang.String name)
      • getToken

        public java.lang.String getToken()
      • setToken

        public void setToken​(java.lang.String appToken)
      • setUsing

        public App setUsing​(java.lang.String options)
      • setNameGiven

        public void setNameGiven​(java.lang.String nameGiven)
      • getNameGiven

        public java.lang.String getNameGiven()
      • getOptions

        public java.lang.String getOptions()
      • getName

        public java.lang.String getName()
      • setName

        public void setName​(java.lang.String name)
      • getExec

        public java.lang.String getExec()
      • setExec

        public void setExec​(java.lang.String exec)
      • getTitle

        public java.lang.String getTitle()
      • getTitle

        public java.lang.String getTitle​(int windowNumber)
      • getWindowTitle

        public java.lang.String getWindowTitle()
      • setWindow

        public void setWindow​(java.lang.String appWindow)
      • setPID

        public void setPID​(int appPID)
      • setPID

        public void setPID​(java.lang.String appPID)
      • getPID

        public int getPID()
      • setWorkDir

        public boolean setWorkDir()
      • setWorkDir

        public boolean setWorkDir​(java.lang.String workDirPath)
      • getWorkDir

        public java.lang.String getWorkDir()
      • isValid

        public boolean isValid()
      • isRunning

        public boolean isRunning()
      • isRunning

        public boolean isRunning​(int maxTime)
      • hasWindow

        public boolean hasWindow()
      • open

        public static App open​(java.lang.String appName,
                               int waitTime)
        tries to open an app using the given name and waits waitTime for being ready If the app is already open, it is brought to foreground
        Parameters:
        appName - name - something that could be used on commandline to start the app
        waitTime - to wait for app to open (secs)
        Returns:
        the App instance
      • open

        public static App open​(java.lang.String appName)
        tries to open an app using the given name and waits 1 sec for being ready If the app is already open, it is brought to foreground
        Parameters:
        appName - name - something that could be used on commandline to start the app
        Returns:
        the App instance
      • open

        public boolean open()
        tries to open the app defined by this App instance
        do not wait for the app to get running
        Returns:
        this or null on failure
      • open

        public boolean open​(int waitTime)
        tries to open the app defined by this App instance
        and waits until app is running
        Parameters:
        waitTime - max waittime until running
        Returns:
        this or null on failure
      • close

        public static boolean close​(java.lang.String appName)
        tries to identify a running app with the given name and then tries to close it
        Parameters:
        appName - name
        Returns:
        0 for success -1 otherwise
      • isClosing

        public boolean isClosing()
      • close

        public boolean close()
        tries to close the app defined by this App instance, waits max 10 seconds for the app to no longer be running
        Returns:
        this or null on failure
      • close

        public boolean close​(int waitTime)
        tries to close the app defined by this App instance, waits max given seconds for the app to no longer be running
        Parameters:
        waitTime - to wait for app to close (secs)
        Returns:
        this or null on failure
      • closeByKey

        public int closeByKey()
      • closeByKey

        public int closeByKey​(int waitTime)
      • setFocused

        public void setFocused​(boolean state)
      • hasFocus

        public boolean hasFocus()
      • focus

        public static App focus​(java.lang.String title)
        tries to identify a running app with name or (part of) window title bringing its topmost window to front
        Parameters:
        title - name
        Returns:
        an App instance - is invalid and not useable if not found as running
      • focus

        public static App focus​(java.lang.String title,
                                int index)
        tries to identify a running app with name or (part of) window title bringing its window with given index to front
        Parameters:
        index - of the window among the found windows
        title - name
        Returns:
        an App instance - is invalid and not useable if not found as running
      • focus

        public boolean focus()
        tries to make it the foreground application bringing its frontmost window to front
        Returns:
        the App instance
      • window

        public Region window()
        evaluates the region currently occupied by the topmost window of this App instance. The region might not be fully visible, not visible at all or invalid with respect to the current monitor configuration (outside any screen)
        Returns:
        the region
      • window

        public Region window​(int winNum)
        evaluates the region currently occupied by the window with the given number of this App instance. The region might not be fully visible, not visible at all or invalid with respect to the current monitor configuration (outside any screen)
        Parameters:
        winNum - window
        Returns:
        the region
      • focusedWindow

        public static Region focusedWindow()
        evaluates the region currently occupied by the systemwide frontmost window (usually the one that has focus for mouse and keyboard actions)
        Returns:
        the region
      • getWindows

        public java.util.List<Region> getWindows()
      • run

        public static int run​(java.lang.String cmd)
        the given text is parsed into a String[] suitable for issuing a Runtime.getRuntime().exec(args). quoting is preserved/obeyed. the first item must be an executable valid for the running system.
        After completion, the following information is available:
        App.lastRunResult: a string containing the complete result according to the docs of the run() command
        App.lastRunStdout: a string containing only the output lines that went to stdout
        App.lastRunStderr: a string containing only the output lines that went to stderr
        App.lastRunReturnCode: the value, that is returnd as returncode
        Parameters:
        cmd - the command to run starting with an executable item
        Returns:
        the final returncode of the command execution
      • getClipboard

        public static java.lang.String getClipboard()
        evaluates the current textual content of the system clipboard
        Returns:
        the textual content or empty string if not possible
      • setClipboard

        public static void setClipboard​(java.lang.String text)
        sets the current textual content of the system clipboard to the given text
        Parameters:
        text - text