Package org.sikuli.script
Class App
- java.lang.Object
-
- org.sikuli.script.App
-
public class App extends 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 classApp.Type
-
Field Summary
Fields Modifier and Type Field Description static StringlastRunResultstatic intlastRunReturnCodestatic StringlastRunStderrstatic StringlastRunStdout
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanclose()tries to close the app defined by this App instance, waits max 10 seconds for the app to no longer be runningbooleanclose(int waitTime)tries to close the app defined by this App instance, waits max given seconds for the app to no longer be runningstatic booleanclose(String appName)tries to identify a running app with the given name and then tries to close itintcloseByKey()intcloseByKey(int waitTime)booleanfocus()tries to make it the foreground application bringing its frontmost window to frontstatic Appfocus(String title)tries to identify a running app with name or (part of) window title bringing its topmost window to frontstatic Appfocus(String title, int index)tries to identify a running app with name or (part of) window title bringing its window with given index to frontstatic RegionfocusedWindow()evaluates the region currently occupied by the systemwide frontmost window (usually the one that has focus for mouse and keyboard actions)static List<App>getApps()static List<App>getApps(String name)static StringgetClipboard()evaluates the current textual content of the system clipboardStringgetExec()StringgetName()StringgetNameGiven()StringgetOptions()intgetPID()StringgetTitle()StringgetTitle(int windowNumber)StringgetToken()List<Region>getWindows()StringgetWindowTitle()StringgetWorkDir()booleanhasFocus()booleanhasWindow()booleanisClosing()booleanisRunning()booleanisRunning(int maxTime)booleanisValid()booleanisWindow()static voidlistApps()static voidlistApps(String name)static voidlog(String msg, Object... args)static voidlogOff()static voidlogOn()booleanopen()tries to open the app defined by this App instance
do not wait for the app to get runningbooleanopen(int waitTime)tries to open the app defined by this App instance
and waits until app is runningstatic Appopen(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 foregroundstatic Appopen(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 foregroundstatic booleanopenLink(String url)static voidpause(float time)static voidpause(int time)voidreset()static intrun(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 returncodestatic voidsetClipboard(String text)sets the current textual content of the system clipboard to the given textvoidsetExec(String exec)voidsetFocused(boolean state)voidsetName(String name)voidsetNameGiven(String nameGiven)voidsetPID(int appPID)voidsetPID(String appPID)voidsetToken(String appToken)AppsetUsing(String options)voidsetWindow(String appWindow)booleansetWorkDir()booleansetWorkDir(String workDirPath)static Regionstart(App.Type appType)StringtoString()StringtoStringShort()RegionwaitForWindow()RegionwaitForWindow(int seconds)Regionwindow()evaluates the region currently occupied by the topmost window of this App instance.Regionwindow(int winNum)evaluates the region currently occupied by the window with the given number of this App instance.
-
-
-
Constructor Detail
-
App
public App()
-
App
public App(String name)
-
-
Method Detail
-
isWindow
public boolean isWindow()
-
waitForWindow
public Region waitForWindow()
-
waitForWindow
public Region waitForWindow(int seconds)
-
openLink
public static boolean openLink(String url)
-
pause
public static void pause(int time)
-
pause
public static void pause(float time)
-
logOn
public static void logOn()
-
logOff
public static void logOff()
-
reset
public void reset()
-
toStringShort
public String toStringShort()
-
listApps
public static void listApps()
-
listApps
public static void listApps(String name)
-
getToken
public String getToken()
-
setToken
public void setToken(String appToken)
-
setNameGiven
public void setNameGiven(String nameGiven)
-
getNameGiven
public String getNameGiven()
-
getOptions
public String getOptions()
-
getName
public String getName()
-
setName
public void setName(String name)
-
getExec
public String getExec()
-
setExec
public void setExec(String exec)
-
getTitle
public String getTitle()
-
getTitle
public String getTitle(int windowNumber)
-
getWindowTitle
public String getWindowTitle()
-
setWindow
public void setWindow(String appWindow)
-
setPID
public void setPID(int appPID)
-
setPID
public void setPID(String appPID)
-
getPID
public int getPID()
-
setWorkDir
public boolean setWorkDir()
-
setWorkDir
public boolean setWorkDir(String workDirPath)
-
getWorkDir
public 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(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 appwaitTime- to wait for app to open (secs)- Returns:
- the App instance
-
open
public static App open(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(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(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(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 windowstitle- 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
-
run
public static int run(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 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(String text)
sets the current textual content of the system clipboard to the given text- Parameters:
text- text
-
-