Field data to shell script

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
Spready
Posts: 3
Joined: Sun Jun 21, 2020 2:30 am

Field data to shell script

Post by Spready » Sun Jun 21, 2020 2:44 am

Hi all, Only been using LC for a few days - new to coding but enjoying the journey!
Struggling with this easy issue.. I have a number of fields in my interface and I want the user inputted data to be picked up by the button at the bottom to run a command in a connected application.
The button and command works as a standalone but i cannot figure out how to get it to read the field data.. current script:

Code: Select all

on mouseUp pButtonNumber
   set the hideConsoleWindows to true
   get shell("ffmpeg -f lavfi -i color=c=blue:[[field "size"]] -t 5 -r 5 -pix_fmt yuv420p -tune stillimage test mp4")
   end mouseUp
So, the field is size, and this is where the user will enter the W x H required...

I have other fields for other parameters but once I figure out the first one, the others should be easy!

Thanks for helping..

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9387
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Field data to shell script

Post by richmond62 » Sun Jun 21, 2020 8:19 am

new to coding
and messing around with shell scripts already . . . Wow.

Spready
Posts: 3
Joined: Sun Jun 21, 2020 2:30 am

Re: Field data to shell script

Post by Spready » Sun Jun 21, 2020 9:13 am

Well, I can write the odd batch file ok - it's the coding of a GUI i'm struggling with!
Any suggestions welcome

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

Re: Field data to shell script

Post by Thierry » Sun Jun 21, 2020 9:39 am

Spready wrote:
Sun Jun 21, 2020 2:44 am
i cannot figure out how to get it to read the field data.. current script:

Code: Select all

   get shell("ffmpeg -f lavfi -i color=c=blue:[[field "size"]] -t 5 -r 5 -pix_fmt yuv420p -tune stillimage test mp4")
Hi Spready,

I'm surprised that your shell line works; it should flag an error in the script Editor ???
You can't put quotes inside a quoted text.

Anyway, If I think right,
I believe you need to merge your shell command to feed it with the content of your field "Size".
Then, you could do something like that (not tested):

Code: Select all

   get field  "size"
   get merge("ffmpeg -f lavfi -i color=c=blue:[[ IT ]] -t 5 -r 5 -pix_fmt yuv420p -tune stillimage test mp4")
   get shell( IT)
HTH,

Thierry
!
SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!

SparkOut
Posts: 2852
Joined: Sun Sep 23, 2007 4:58 pm

Re: Field data to shell script

Post by SparkOut » Sun Jun 21, 2020 9:52 am

Hi Spready

You know how to get the field contents into a variable, just not how to insert those contents into the command in the right place?

Getting the contents is simple anyway

Code: Select all

put field "size" into tSize
Combining that into the command string you want is also fairly easy, it gets tricky to visualise at times with the opening and closing of quotes when concatenating literal text with values and the spacing between.

Code: Select all

get shell("ffmpeg -f lavfi -i color=c=blue:" & tSize & " -t 5 -r 5 -pix_fmt yuv420p -tune stillimage test mp4")
The basic concatenation operator in LiveCode is &. There is a space between the tSize value and the -t switch thst follows. The double ampersand && operator could be used here to combine the string with a whitespace.
It can be easier to see by building up the final line in stages and add content "after" the current data

Code: Select all

put "ffmpeg -f lavfi -i color=c=blue:" into tCommand
put tSize & space after tCommand
put "-t 5 -r 5 -pix_fmt yuv420p -tune stillimage test mp4" after tCommand
get shell(tCommand)
It is also possible to use "merge" to combine text, which looks like maybe the way you were going, with the double square brackets. Thierry shows how above.

Getting the right concatenation is only a trivial part of the game though if you are having users insert their own values into the GUI. It will be much more work to ensure that the inserted values are valid (eg not text when a number is required) and within range (eg an integer between 1 and 10)

Spready
Posts: 3
Joined: Sun Jun 21, 2020 2:30 am

Re: Field data to shell script

Post by Spready » Sun Jun 21, 2020 10:07 am

Thank you for taking the time to reply.

I will test it shortly

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

Re: Field data to shell script

Post by FourthWorld » Sun Jun 21, 2020 10:12 am

You obtain a value with the shell function call, but then do nothing with it. Where should it appear?
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 - Complete Beginners”