mdm.Process.create(...) should return pid (process id) of process that was started by running that method.
For example running "open -b com.apple.Safari" should open instance of Safari browser - and it is assumed that its pid should be returned. That pid could be later used to monitor started process status.
In current build the process id returned is pid of shell process invoked by mdm.Process.create - not pid of process that was started as results of using shell integration.
For example if pid is 3049 then it will be because it is pid of underlying process:
kacper 3049 0.0 0.1 2448756 3332 ?? Rs 1:43PM 0:00.02 /usr/bin/open -g -b com.apple.TextEdit
To repeat please use provided sources and build OS X project and run.
The project is based on code:
applicationComplete="mdm.Application.init(this);">
import flash.utils.setTimeout;
import mdm.*;
// will hold number (process id/pid)
private var processID:Number = -1;
/**
* open TextEdit.app behind application
* record process ID returned by method for future use
* To use below code correctly make sure that TextEdit instance
* is closed
*/
private function openTextEdit():void
{
mdm.Process.setParams("-g", "-b", "com.apple.TextEdit");
processID = mdm.Process.create("My Title", 0, 0, 500, 600, "", "/usr/bin/open", "/usr/bin", 3, 4);
output.text += "processID returned is: "+processID+"\n";
// now we should have processID,
// so let's grab terminal output for process lists for TextEdit
getPidsList();
// use little delay to make sure that process is already up and running
setTimeout(getPidsList, 500);
}
private function getPidsList():void
{
// the output should be similar to:
// processID returned is: 2835
// list pids using ps aux | grept TextEdit
// kacper 2836 6.8 0.3 2762200 8324 ?? S 1:31PM 0:00.08 /Applications/TextEdit.app/Contents/MacOS/TextEdit -psn_0_516222
// kacper 2839 0.0 0.0 2425520 168 ?? R 1:31PM 0:00.00 grep TextEdit
// kacper 2837 0.0 0.0 2435464 640 ?? Ss 1:31PM 0:00.01 /bin/sh -c ps aux | grep TextEdit
mdm.MacShell.exec("ps aux | grep TextEdit");
var outputStr:String = mdm.MacShell.output;
output.text += "list pids using ps aux | grept TextEdit"+"\n";
output.text += outputStr;
}
]]>
|
Expected behavior is that mdm.Process.create(...) should return pid of resulting process.
There are work arounds available depending on what exact use of pid was planned.
For example one could use AppleScript to check if started application is still running:
var CR:String = "\r";
var TAB:String = "\t";
var LF:String = "\n";
var script:String = "set isRunning to false"+CR;
script += "if appIsRunning(\"Safari\") then"+CR;
script += TAB+"set isRunning to true"+CR;
script += "end if"+CR;
script += "return get isRunning"+CR;
script += "on appIsRunning(appName)"+CR;
script += TAB+"tell application \"System Events\" to (name of processes) contains appName"+CR;
script += "end appIsRunning"+CR;
mdm.AppleScript.setScript(script);
mdm.AppleScript.compileScript();
mdm.AppleScript.run();
var outputStr:String = mdm.AppleScript.getResult();
var isRunning:Boolean = new Boolean(outputStr == "true");
|