How to Create a Command-Line Tool with LiveCode?

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

icouto
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 92
Joined: Wed May 29, 2013 1:54 am
Location: Sydney, Australia

How to Create a Command-Line Tool with LiveCode?

Post by icouto » Fri Aug 24, 2018 6:51 am

I know it is possible to write 'livecode script' (.lc) files, which can then be interpreted by LiveCode Server, but I was wondering whether it is possible to create an actual command-line tool with LiveCode? - ie., an all-in-one standalone binary intended to be run from the command-line only.

I have been unable to find any instructions or references anywhere.

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

Re: How to Create a Command-Line Tool with LiveCode?

Post by FourthWorld » Fri Aug 24, 2018 7:13 am

Standalones can be run facelessly by adding -ui to the command line options.

This getopt library well help parse command line args:
http://lists.runrev.com/pipermail/use-l ... 28347.html
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

icouto
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 92
Joined: Wed May 29, 2013 1:54 am
Location: Sydney, Australia

Re: How to Create a Command-Line Tool with LiveCode?

Post by icouto » Fri Aug 24, 2018 7:52 am

Wow, that was a quick reply!
FourthWorld wrote:
Fri Aug 24, 2018 7:13 am
Standalones can be run facelessly by adding -ui to the command line options.
What command are you using to run the standalone? I'm on a Mac, and trying to simply 'run' the standalone on the command-line - with or without '-ui' flags - does not work:

Code: Select all

$ mylivecodetool.app -ui
-bash: mylivecodetool.app: is a directory
Trying to open the bundle and access the binary directly causes an error:

Code: Select all

$ mylivecodetool.app/Contents/MacOS/mylivecodetool -ui
TIS/TSM in non-main thread environment, ERROR : This is NOT allowed. Please call TIS/TSM in main thread!!!
The 'open' command doesn't support `-ui` flags either, and yields the same error.

Ultimately, I would like to be able to use my compiled tool simply like this:

Code: Select all

$ mylivecodetool -a -b -c blablabla
Is that possible?

AndyP
Posts: 614
Joined: Wed Aug 27, 2008 12:57 pm
Location: Seeheim, Germany (ex UK)
Contact:

Re: How to Create a Command-Line Tool with LiveCode?

Post by AndyP » Fri Aug 24, 2018 9:43 am

Have a look at this in the Nabble forums.

http://runtime-revolution.278305.n4.nab ... l#a4664056
Andy Piddock
https://livecode1001.blogspot.com Built with LiveCode
https://github.com/AndyPiddock/TinyIDE Mini IDE alternative
https://github.com/AndyPiddock/Seth Editor color theming
http://livecodeshare.runrev.com/stack/897/ LiveCode-Multi-Search

icouto
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 92
Joined: Wed May 29, 2013 1:54 am
Location: Sydney, Australia

Re: How to Create a Command-Line Tool with LiveCode?

Post by icouto » Fri Aug 24, 2018 10:55 am

Thank you for the link, @AndyP - it does have some useful script code there that will come handy! Unfortunately, it does not answer any of my questions... :(

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

Re: How to Create a Command-Line Tool with LiveCode?

Post by FourthWorld » Fri Aug 24, 2018 12:32 pm

Mac apps are actually folders, rather than single file executables. You'll find the executable within the .app bundle nested a couple folders in (sorry, don't have my Mac on right now and I forget the exact folder names, but if you the around inside the bundle you'll find it easily enough).
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

icouto
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 92
Joined: Wed May 29, 2013 1:54 am
Location: Sydney, Australia

Re: How to Create a Command-Line Tool with LiveCode?

Post by icouto » Fri Aug 24, 2018 2:37 pm

Thank you for the guidance, @FourthWorld! As I mentioned a couple of posts above, I've actually already looked inside the app bundle(=.app folder), found the executable, and tried running that both with and without the '-ui' flag. It runs into a fatal error:

Code: Select all

$ mylivecodetool.app/Contents/MacOS/mylivecodetool -ui
2018-08-24 23:34:18.666 mylivecodetool[43918:17761058] pid(43918)/euid(501) is calling TIS/TSM in non-main thread environment, ERROR : This is NOT allowed. Please call TIS/TSM in main thread!!!
I have tried saving the standalone both with LC9 stable, as well as the latest RC2 version - no difference. Am I missing something obvious?

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

Re: How to Create a Command-Line Tool with LiveCode?

Post by FourthWorld » Fri Aug 24, 2018 4:55 pm

Yep, you were on top of the path thing indeed. I was on auto-pilot, and most of the issues I've seen with CLI on macOS have been about the path into the bundle.

Once I got your latest message I found the issue intriguing, as I do a lot of automation work which requires me to run standalones from the command line. And sure enough, I got the same message.

I filed a bug report - see my notes here:
https://quality.livecode.com/show_bug.cgi?id=21524

One possible difference between your experience and mine: here, though I get the error message output, the app runs normally. This is consistent with reports of this behavior with other apps in macOS 10.13 I found in a web search.

Is your app not running at all?
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

icouto
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 92
Joined: Wed May 29, 2013 1:54 am
Location: Sydney, Australia

Re: How to Create a Command-Line Tool with LiveCode?

Post by icouto » Sun Aug 26, 2018 12:25 am

TBH, I merely had a 'skeleton' of an app as a test - the app did nothing - as I was just starting to tinker with a command-line setup.

Is it possible to 'echo' something to the terminal, as a test? How do we go about building a '-h' or '--help'?

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

Re: How to Create a Command-Line Tool with LiveCode?

Post by FourthWorld » Sun Aug 26, 2018 12:35 am

When run from the command line the "put" command will output to the terminal.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

icouto
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 92
Joined: Wed May 29, 2013 1:54 am
Location: Sydney, Australia

Re: How to Create a Command-Line Tool with LiveCode?

Post by icouto » Sun Aug 26, 2018 12:56 am

Thank you, Richard!

Yes, it does output my 'Hello World' - so it is working, although only after it gives me the warning (repeatedly)...

Thank you for filing the bug report! Does this mean that the only way to create a 'command-line tool' in LiveCode right now would be to run it as a hash-bang script under LiveCode Server?

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

Re: How to Create a Command-Line Tool with LiveCode?

Post by FourthWorld » Sun Aug 26, 2018 3:25 am

That's an interesting question. When you run it that way does it output no errors?

You may be able to just drop backa version or two to do what you were originally planning. I think this is a fairly recent regression.

What are you working on? Very few of us use LC the command line, but it's so capable I prefer it to anything else.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

icouto
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 92
Joined: Wed May 29, 2013 1:54 am
Location: Sydney, Australia

Re: How to Create a Command-Line Tool with LiveCode?

Post by icouto » Sun Aug 26, 2018 3:56 am

There is a command-line tool that we use for one of our CMSs, and unfortunately the developer has decided to drop support for it - they don't want to develop it any further, as it's getting too many requests for enhancements, and "taking away from time spent developing the CMS itself". I thought this sounded like a good development opportunity! ;-)

This particular tool only does some fairly basic stuff atm: download git repositories (which the developers using it are already supposed to have in their machines), create some files (via interactive wizards), and update some components (via git, again). I'd love to be able to try and do it in LiveCode, but am starting to think that it may be easier to actually develop a GUI for it, than trying to do it as a command-line tool...

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

Re: How to Create a Command-Line Tool with LiveCode?

Post by FourthWorld » Sun Aug 26, 2018 4:28 am

I was intrigued by your suggestion, and indeed it works well: when I run a text file containing a script with the shebang line pointing to my copy of LC Server 9.0.1rc2 it runs the script and produces no errors.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

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

Re: How to Create a Command-Line Tool with LiveCode?

Post by FourthWorld » Mon Aug 27, 2018 9:55 pm

Bug already fixed, in queue for next build:
https://quality.livecode.com/show_bug.cgi?id=21524
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

Post Reply

Return to “Getting Started with LiveCode - Experienced Developers”