Page 1 of 1

What is the opposite of launch?

Posted: Tue Jun 11, 2019 4:14 pm
by Rob van der Sloot
I manage a number of LC Runtimes from one dashboard (also Runtime) with the launch command.
That works perfect.

But now I also want to close the runtimes from that same Dashboard.
How to do that?

Thanks
Rob van der Sloot

Re: What is the opposite of launch?

Posted: Tue Jun 11, 2019 6:17 pm
by dunbarx
Hi.

Just a guess, but does the "close Process" command fit here?

Craig

Re: What is the opposite of launch?

Posted: Wed Jun 12, 2019 2:13 pm
by Rob van der Sloot
Hi dunbarx,

That won't work, because the close proces command is only applicable to files who were opened by the "open process" command and that's only for background processing data.

thanks anyway,
Rob

Re: What is the opposite of launch?

Posted: Wed Jun 12, 2019 4:10 pm
by [-hh]
open process ... that's only for background processing ...
No. This is only a proposal of the dictionary.
But on Mac you can open only one instance of an app at one time.

After using open process you can check openProcesses() or openProcessIDs().
(Don't use LC 8, where openProcess is defunct).

For apps opened by open process that can NOT be closed by close process (as is the case on Mac*) you can try kill process (which works with LC 9 here also on Mac). Or, better, use the applescript given below by Thierry.

*[I opened erroneously a bug report: The dict already says, that close process is not supported on MacOS!]

Re: What is the opposite of launch?

Posted: Thu Jun 13, 2019 12:42 pm
by LCMark
@hh: Rob isn't entirely wrong in his assertion. The open process commands are designed to work with command-line / UNIX executables; rather than app bundles. From memory, the 'launch' command is more appropriate for app bundles.

@Rob: On macOS usually the best way to start and stop macOS apps (i.e. desktop apps) is using applescript I think... There's no direct way to 'cleanly' close a running macOS app - but applescript can be used to cause the system to send a 'close app' event which the app may or may not decide to honour.

Re: What is the opposite of launch?

Posted: Thu Jun 13, 2019 1:17 pm
by Thierry
LCMark wrote: There's no direct way to 'cleanly' close a running macOS app - but applescript can be used....
Here is how I do that in one of my LC tutorial:

Code: Select all

try
      get shell(format( \
            "osascript -e 'tell application \"MidiKeys\" to quit'"))
            
      get shell(format( \
            "osascript -e 'tell application \"MIDIMonitor.app\" to quit without saving'"))
            
end try
and both apps were opened via the launch command.

HTH,

Thierry

Re: What is the opposite of launch?

Posted: Sat Jun 15, 2019 1:07 pm
by Rob van der Sloot
OK, thanks again, but for the time being I am interested in a solution for W10.

Re: What is the opposite of launch?

Posted: Mon Jun 17, 2019 11:54 am
by sphere
I use something for Windows too, if i have time tonight and remember this thread i can post it here.
The working is similair to that of MacOs by calling the shell.

Even for Linux this is possible.

Re: What is the opposite of launch?

Posted: Mon Jun 17, 2019 6:08 pm
by FourthWorld
There are ways to use OS command line tools to find the target process and kill it. And depending on what those processes are doing, that may be okay.

But sometimes pulling the rug out from under a running process can be problematic.

Because the processes here are LiveCode standalones, it may be worth the modest effort to establish socket comms between those and the controlling app, to allow the controlling app to send it a message to quit, or any other messages that may be useful to run in such a worker pool.

Re: What is the opposite of launch?

Posted: Mon Jun 17, 2019 7:26 pm
by sphere
If this is the stack that starts another stack i have this in stack script closestackhandler:

Code: Select all

if the environment is "standalone application" then
         send "closeStack" to stack"yourapp"
      end if
If this is the stack whcih is started by the other stack i have this in the closestackhandler:

Code: Select all

if the environment is "standalone application" then
      if the platform is "Win32" then
         --added /T and /F, /T Terminates process and any child processes started by it, /F Forcefully Terminate process
         put "taskkill.exe" & space & "/F" & space & "/T" & space & "/IM" & space & "yourapp.exe" into tCommandToExec
         put shell  (tCommandToExec)
      else 
         if the platform is "MacOS" then
            put "osascript -e 'quit app" & quote & "youapp" & quote & "'" into tCommandToExec
            -- of pkill yourapp
            put shell (tCommandToExec)
         else
            if the platform is "Linux" then
               put shell("killall yourapp")
            end if
         end if
      end if
now i found that clicking on the X in Macos does not close the stack, in Macos i need to close the app via the menu. I don't know why, because clicking the X should also activate the close stack handler

Re: What is the opposite of launch?

Posted: Tue Jun 18, 2019 4:48 pm
by jacque
Clicking the X closes the window only. Most apps on Mac act this way since the user may want to open another document from the File menu. If you want to quit instead, add your quitting code to a CloseStack Request handler.

Re: What is the opposite of launch?

Posted: Tue Jun 18, 2019 8:02 pm
by sphere
Hi Jacque,

this is in my closestackrequest handler

Code: Select all

on closeStackRequest
   answer "Zeker weten dat je wil stoppen?" with "Ja" or "Nee"
   if it is "Ja" then
      pass closeStackRequest
   else
      if it is "Nee" then
         exit to top
      end if
   end if
end closeStackRequest
plus of course the closeStack handler like in he above post where also this is in:
quit
pass closeStack

Re: What is the opposite of launch?

Posted: Wed Jun 19, 2019 5:23 pm
by jacque
Ah. You're ahead of me already. :-)

I'd think that passing the request would trigger the closeStack handler so I'm not sure why it doesn't. Have you tried putting a breakpoint in the closeStack handler to see if it runs? If it doesn't you may have to call "closeStack" yourself.

Re: What is the opposite of launch?

Posted: Wed Jun 19, 2019 7:21 pm
by sphere
Ok i can try that, thanks for the suggestion.