What is the opposite of launch?

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
Rob van der Sloot
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 78
Joined: Sat Apr 17, 2010 9:21 am

What is the opposite of launch?

Post by Rob van der Sloot » Tue Jun 11, 2019 4:14 pm

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

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9643
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: What is the opposite of launch?

Post by dunbarx » Tue Jun 11, 2019 6:17 pm

Hi.

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

Craig

Rob van der Sloot
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 78
Joined: Sat Apr 17, 2010 9:21 am

Re: What is the opposite of launch?

Post by Rob van der Sloot » Wed Jun 12, 2019 2:13 pm

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

[-hh]
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2262
Joined: Thu Feb 28, 2013 11:52 pm
Location: Göttingen, DE

Re: What is the opposite of launch?

Post by [-hh] » Wed Jun 12, 2019 4:10 pm

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!]
Last edited by [-hh] on Thu Jun 13, 2019 6:43 pm, edited 1 time in total.
shiftLock happens

LCMark
Livecode Staff Member
Livecode Staff Member
Posts: 1207
Joined: Thu Apr 11, 2013 11:27 am

Re: What is the opposite of launch?

Post by LCMark » Thu Jun 13, 2019 12:42 pm

@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.

Thierry
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 875
Joined: Wed Nov 22, 2006 3:42 pm

Re: What is the opposite of launch?

Post by Thierry » Thu Jun 13, 2019 1:17 pm

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
!
SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!

Rob van der Sloot
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 78
Joined: Sat Apr 17, 2010 9:21 am

Re: What is the opposite of launch?

Post by Rob van der Sloot » Sat Jun 15, 2019 1:07 pm

OK, thanks again, but for the time being I am interested in a solution for W10.

sphere
Posts: 1145
Joined: Sat Sep 27, 2014 10:32 am
Location: Earth, Except when i Jump

Re: What is the opposite of launch?

Post by sphere » Mon Jun 17, 2019 11:54 am

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.

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9823
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: What is the opposite of launch?

Post by FourthWorld » Mon Jun 17, 2019 6:08 pm

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.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

sphere
Posts: 1145
Joined: Sat Sep 27, 2014 10:32 am
Location: Earth, Except when i Jump

Re: What is the opposite of launch?

Post by sphere » Mon Jun 17, 2019 7:26 pm

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

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7227
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: What is the opposite of launch?

Post by jacque » Tue Jun 18, 2019 4:48 pm

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.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

sphere
Posts: 1145
Joined: Sat Sep 27, 2014 10:32 am
Location: Earth, Except when i Jump

Re: What is the opposite of launch?

Post by sphere » Tue Jun 18, 2019 8:02 pm

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

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7227
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: What is the opposite of launch?

Post by jacque » Wed Jun 19, 2019 5:23 pm

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.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

sphere
Posts: 1145
Joined: Sat Sep 27, 2014 10:32 am
Location: Earth, Except when i Jump

Re: What is the opposite of launch?

Post by sphere » Wed Jun 19, 2019 7:21 pm

Ok i can try that, thanks for the suggestion.

Post Reply

Return to “Getting Started with LiveCode - Experienced Developers”