/** * tries to identify a running app with name and if not running tries to open it and tries to make it the foreground * application bringing its window with the given number to front * * @param appName name * @param num window * @return the App instance or null on failure */ public static App focus(String appName, int num) { return (new App("+" + appName)).focus(num); }
if (Type.EDITOR.equals(appType)) { if (runTime.runningMac) { app = new App(appsMac.get(appType)); if (app.window() != null) { app.focus(); aRegion.wait(0.5); win = app.window(); aRegion.click(win); aRegion.write("#M.a#B."); return win; } else { app.open(); win = app.waitForWindow(); app.focus(); aRegion.wait(0.5); aRegion.click(win); app = new App(appsWindows.get(appType)); if (app.window() != null) { app.focus(); aRegion.wait(0.5); win = app.window(); aRegion.click(win); aRegion.write("#C.a#B."); return win; } else { app.open(); win = app.waitForWindow(); app.focus();
/** * tries to close the app defined by this App instance * * @return this or null on failure */ public int close() { if (!isValid()) { return 0; } if (appPID > -1) { init(appPID); } else if (isImmediate) { init(); } int ret = _osUtil.close(makeAppEntry()); if (ret > -1) { Debug.action("App.close: %s", this.toStringShort()); appPID = -1; appWindow = ""; } else { Debug.error("App.close %s did not work", this); } return ret; } //</editor-fold>
private App openAndWait(int waitTime) { if (isImmediate) { appPID = _osUtil.open(appNameGiven); } else { AppEntry appEntry = makeAppEntry(); init(_osUtil.open(appEntry)); } if (appPID < 0) { Debug.error("App.open failed: " + appNameGiven + " not found"); notFound = true; } else { Debug.action("App.open " + this.toStringShort()); } if (isImmediate && notFound) { return null; } if (waitTime > 0) { if (!isRunning(waitTime)) { return null; } } return this; } //</editor-fold>
App app = new App(null); app.setBlockOnOpen(true); app.open();
init(appNameGiven); Debug.log(3, "App.create: %s", toStringShort());
public App(int pid) { appNameGiven = "FromPID"; appName = ""; appPID = pid; appWindow = ""; init(pid); }
/** * 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) * * @return the region */ public Region window() { if (appPID != 0) { return asRegion(_osUtil.getWindow(appPID)); } return asRegion(_osUtil.getWindow(appNameGiven)); }
/** * tries to identify a running app with name and if not running tries to open it and tries to make it the foreground * application bringing its topmost window to front * * @param appName name * @return the App instance or null on failure */ public static App focus(String appName) { return focus(appName, 0); }
public static void getApps() { getApps(null); }
/** * * @return content * @deprecated use App. ... instead */ @Deprecated public static String getClipboard() { return App.getClipboard(); }
public AppEntry makeAppEntry() { String name = appName; String window = appWindow; if (name.isEmpty() && appOptions.isEmpty()) { name = appNameGiven; } if (isImmediate && !window.startsWith("!")) { window = "!" + window; } if (notFound) { name = "!" + name; } String pid = getPID().toString(); AppEntry appEntry = new AppEntry(name, pid, window, appNameGiven, appOptions); return appEntry; } //</editor-fold>
/** * tries to make it the foreground application bringing its window with the given number to front * * @param num window * @return the App instance or null on failure */ public App focus(int num) { if (!isValid()) { if (!appWindow.startsWith("!")) { return this; } } if (isImmediate) { appPID = _osUtil.switchto(appNameGiven, num); } else { init(_osUtil.switchto(makeAppEntry(), num)); } if (appPID < 0) { Debug.error("App.focus failed: " + (num > 0 ? " #" + num : "") + " " + this.toString()); return null; } else { Debug.action("App.focus: " + (num > 0 ? " #" + num : "") + " " + this.toStringShort()); if (appPID < 1) { init(); } } return this; } //</editor-fold>
/** * evaluates the region currently occupied by the systemwide frontmost window (usually the one that has focus for * mouse and keyboard actions) * * @return the region */ public static Region focusedWindow() { return asRegion(_osUtil.getFocusedWindow()); } //</editor-fold>
@Override public String toString() { if (!appWindow.startsWith("!")) { init(); } return String.format("[%d:%s (%s)] %s", appPID, appName, appWindow, appNameGiven); }