How to launch an external process synchronously in Electron - electron

In Electron,
I need to call an external program to do some work, wait for it to finish and terminate, and then move on to my next line of code.
I've tried shell.openItem("/applications/apptocall.app")
This works to launch the app, but it runs the next line of code in my electron app immediately instead of waiting for the externally launched app to finish.
What is the easiest way to do this?

The shell.openItem command of the Electron API is not meant to control the execution of external executables.
Instead, check out the node.js API for child_process.execFileSync (Docs).
There are certain limitations when using the child_process API along with ASAR archive packaging in Electron concerning fs.stats and child_process.spawn, you should read up on these issues here.

Related

How does a UI app inspectors (like the one in Appium) work?

Appium has a way to inspect the view hierarchy of an app using an inspector. I am interested in building one myself.
I know the overview answer of: it uses some webdriver to accomplish this. But how?
It puzzles me that a separate iOS app can some how communicate to another app, and show even its screen.
How does it work under the hood? or how does the iOS app communicate to the UI inspector to send its screen shots and hierarchy?
It puzzles me that a separate iOS app can some how communicate to another app, and show even its screen.
Yes! Apps should not be able to do this. But there exists a special kind of app, built just for testing, which IS able to do this.
The way this is done is using Apple's XCUITest framework. When you write an XCUITest in XCode, it builds a special app which is able to start your test app and then communicate with it using the XCUITest methods. These methods allow you to inspect elements in the view.
In order to create a view tree, you start at the root view and iterate over the children, building out a tree with a tree traversal.
Normally, the XCUITest app exits when your test script finishes, which means you won't be able to access it from a desktop app for viewing the tree as it updates. If you write your test script to run an infinite loop and open a network port for communication with an outside process, now you can build your viewer. This is exactly what Appium does, so I suggest you check out the appium source code and maybe just use that?
More information in this blog post
[edit]: Oh yeah, Appium uses Feacebook's WebDriverAgent project as the script that runs on the app. So WebDriverAgent is basically an XCUITest script which runs a server and can take commands during a test. Appium does a ton of work to bundle and package it into the special kind of companion app that is able to access your app, installs it on the iOS device, and then runs the test. WebDriverAgent has a command which iterates over the UIHierarchy and returns the whole tree.

App starting and closing itself when i run the Eclipse Code

I am automating Mobile .app(ipa) file using Appium and Eclipse.
I have set the desired capabilities.
When I run the code, App initiates and closes instantly.
What could be the possible reason ? Please suggest.

Updating Electron app

The Electron framework from GitHub has a feature that lets you automatically update your app by using some server utility called Squirrel. What I am wondering is whether an Electron app can simply just update itself without depending on any server utility. Since an Electron app is basically a web-based app using HTML and Javascript, couldn't you just create an "empty" app that has no UI or code other than some bootup Javascript code that downloads the entire UI and other scripts to run the app?

Swift - Execute SSH Command in iOS

I want to execute a Shell Command in my Swift Application.
I read that i can't use NSTask, because there is no built in SSH in the iPhone. Now my question is how i can implement this without NSTask.
Instead of creating your own app you may want to look into an iOS app called 'Workflow'. It includes a module called 'Run Script Over SSH' which does exactly what the title states.
Any use of API that forks and spawns a new process is disallowed by the App Store rules, so if you want to do this for an app you plan to submit, the short answer is that you can't.
NSTask and the exec*(3) family of C library functions certainly exist on iOS, but they aren't public API.
If you need SSH functionality, you need to find a library that provides that functionality to pass App Store review.

What applescript commands can be sent to iOS Simulator?

I know you can tell the iOS Simulator to quit with applescript. Can you tell it to go "home" from the current app? And then click on the app's icon to relaunch it? This would be useful for me for Application Tests that need to verify background tasks complete and numerous other cases.
Any AppleScriptable app must export a scripting dictionary in order for AppleScript to know what its commands are. You can see any app's dictionary by opening the app in Script Editor.
Note that even if an app doesn't provide script commands for what you want, System UI Scripting or Automator can likely still be used to drive its UI. (For example, to choose the Home or Rotate commands in iOS Simulator's menu bar.)
There's also iOS-specific UI automation stuff you can do from the Instruments app that comes with Xcode.
The iOS Simulator does not directly support AppleScript. It doesn't have a scripting dictionary. This means that the only real way to manipulate it in AppleScript is to use the UI commands that work for any application.

Resources