What is Macintosh equivalent of relaunch handler?

Richard Gaskin ambassador at fourthworld.com
Fri Mar 29 03:14:12 EDT 2019


Bill Vlahos wrote:

 >> On Mar 28, 2019, at 2:54 PM, Richard Gaskin wrote:
 >>
 >> Bill Vlahos wrote:
 >> > I want my application to be able to catch parameters sent to it via
 >> > the command line.
 >>
 >> Ah, much simpler problem.
 >>
 >> macOS is a certified Unix.  It works just like Linux.
 >>
 >> On startup, you can check $# for the number of args passed in the
 >> command line, or $1, $2, etc. to get the value of any one of them.
 >>
 >> If you need really sophisticated command-line argument handling, 
check out the getOpt function Peter Brett added for that:
 >>
 >> https://livecode.fandom.com/wiki/Getopt
 >>
 >
 > GetOpt looks exactly like what I want.

But it's just a function. First we have to figure out which message 
you'll use to call it from.


 > The docs specify on startup is only sent when the application is
 > opened. This won’t work for me as I want to catch command line
 > parameters ongoing while my application stays open.

True, but you're running from command line, yes?  That's usually used 
for faceless apps, with appleEvents used for GUIs.

But I understand: the app you want to call your LC-made app doesn't send 
AE, but can make command line calls - is that correct?

That's an interesting case I've never explored. I wonder if your app 
still gets 'odoc' events, or some other event, when receiving arguments 
to a running Mac app from the command line.  Maybe worth trying.


 > What would the syntax be if I want to catch 3 items some of which
 > could contain multiple words with a space between them?

If you post a few examples we can come up with parsers, but you know 
your way around chunk expressions so you could probably do that part 
better than most on your own.

To get the args, just know that any word is an arg, and a quoted string 
counts as one word, so this:

on startup
    put $1 &cr& $2 &cr& $3
end startup

...when call from:

   ./myapp ThisIsArg1 "And this is a multi-word arg" "this,is,delimited"

...would give you:

    ThisIsArg1
    "And this is a multi-word arg"
    "this,is,delimited"

 From there you can parse to your heart's delight.

That is, once we figure out how your app will get notification...

-- 
  Richard Gaskin
  Fourth World Systems
  Software Design and Development for the Desktop, Mobile, and the Web
  ____________________________________________________________________
  Ambassador at FourthWorld.com                http://www.FourthWorld.com




More information about the use-livecode mailing list