Page 1 of 1
I'm Brand New to Livecode and Making a Simple Scipt
Posted: Wed Aug 19, 2020 12:56 am
by really34
I am making a simple script to show:
Serial Number
Hostname
Mac Address
on mouseUp
set the hideConsoleWindows to true
put empty into fld "fldOut"
put "wmic bios get serialnumber" into tCom1
put "Serial is " & line 3 of shell(tCom1) into line 1 of fld "fldout"
put "hostname" into tCom2
put "hostname is " & line 1 of shell(tCom2) into line 2 of fld "fldout"
end mouseUp
This works fine, but when I add the following to the script I get an error.
I think it might be because it is trying to interpret the PowerShell command even though it is in quotes.
What am I doing wrong here?
put "powershell "$(Get-NetAdapter -Name "Ethernet").MacAddress"" into tCom3
put "Mac Address is " & line 1 of shell(tCom2) into line 3 of fld "fldout"
Re: I'm Brand New to Livecode and Making a Simple Scipt
Posted: Wed Aug 19, 2020 2:59 am
by FourthWorld
really34 wrote: ↑Wed Aug 19, 2020 12:56 am
This works fine, but when I add the following to the script I get an error.
What does the error say?
Re: I'm Brand New to Livecode and Making a Simple Scipt
Posted: Wed Aug 19, 2020 9:33 am
by AxWald
Hi,
assume here is the error:
Code: Select all
put "powershell "$(Get-NetAdapter -Name "Ethernet").MacAddress"" into tCom3
You want to put a string into tCom3, but this string contains quotes - this way the interpreter get's confused & throws an error.
2 ways to solve this:
1.) Replace all quotes but the outermost pair with " & quote & ":
Code: Select all
put "powershell " & quote & "$(Get-NetAdapter -Name " & quote & "Ethernet" & quote & ").MacAddress" & quote into tCom3
Looks confusing? ;-)
2.) Define a function to quote a string, and use this:
Code: Select all
put "powershell " & kwote("$(Get-NetAdapter -Name " & kwote("Ethernet") & ").MacAddress") into tCom3
function kwote what,sQuotes
/* Quotes "what" with double quotes. Uses single quotes is sQuotes is true.
- put "fortytwo" into myVar
. put kwote(myVar) => "fortytwo"
. put kwote(myVar, true) => 'fortytwo' */
if sQuotes is not true then put false into sQuotes -- set default
if not sQuotes then -- double quotes
return quote & what & quote
else -- single quotes
return "'" & what & "'"
end if
end kwote
Less confusing?
Well, concatenating correctly isn't easy at first. But it comes fast, with training. And a quoting function is essential.
Have fun!
Re: I'm Brand New to Livecode and Making a Simple Scipt
Posted: Wed Aug 19, 2020 1:39 pm
by dunbarx
Hi.
Do you see what AxWald meant? Imagine you had to use the five character string "foo" for some purpose, and the quotes had to be explicitly included with that string. You cannot, in LC say (pseudo):
Because LC will intrerpret that string as a literal, and provide only a three character string. But if you say:
Code: Select all
use the string quote & "foo" & quote
LC will pass a five character string, framed by ASCII 34.
It is the only way LC can interpret the use of what is ordinarily a unique character that defines literals as a character in its own right. The word "quote" is considered a constant.
Craig
Re: I'm Brand New to Livecode and Making a Simple Scipt
Posted: Wed Aug 19, 2020 11:15 pm
by really34
Thank You it worked!
My next question is will preopenstack have an effect on the load time of line 4 in fld out.
It takes a few seconds to get the MAC address though powershell, so I read about preopenstack.
What exactly is preopenstack intended for?
on preopenstack
put "powershell " & quote & "$(Get-NetAdapter -Name " & quote & "Ethernet" & quote & ").MacAddress" & quote into tCom4
end preopenstack
on OpenStack
set the hideConsoleWindows to true
put empty into fld "fldOut"
put "wmic bios get serialnumber" into tCom1
put "Serial is " & line 3 of shell(tCom1) into line 1 of fld "fldout"
put "hostname" into tCom2
put "Hostname is " & line 1 of shell(tCom2) into line 2 of fld "fldout"
put "wmic bios get smbiosbiosversion" into tCom3
put "Bios Version is " & line 3 of shell(tCom3) into line 3 of fld "fldout"
put "powershell " & quote & "$(Get-NetAdapter -Name " & quote & "Ethernet" & quote & ").MacAddress" & quote into tCom4
put "Ethernet Mac Address is " & line 1 of shell(tCom4) into line 4 of fld "fldout"
end OpenStack
Re: I'm Brand New to Livecode and Making a Simple Scipt
Posted: Wed Aug 19, 2020 11:15 pm
by really34
Thank You it worked!
My next question is will preopenstack have an effect on the load time of line 4 in fld out.
It takes a few seconds to get the MAC address though powershell, so I read about preopenstack.
What exactly is preopenstack intended for?
on preopenstack
put "powershell " & quote & "$(Get-NetAdapter -Name " & quote & "Ethernet" & quote & ").MacAddress" & quote into tCom4
end preopenstack
on OpenStack
set the hideConsoleWindows to true
put empty into fld "fldOut"
put "wmic bios get serialnumber" into tCom1
put "Serial is " & line 3 of shell(tCom1) into line 1 of fld "fldout"
put "hostname" into tCom2
put "Hostname is " & line 1 of shell(tCom2) into line 2 of fld "fldout"
put "wmic bios get smbiosbiosversion" into tCom3
put "Bios Version is " & line 3 of shell(tCom3) into line 3 of fld "fldout"
put "powershell " & quote & "$(Get-NetAdapter -Name " & quote & "Ethernet" & quote & ").MacAddress" & quote into tCom4
put "Ethernet Mac Address is " & line 1 of shell(tCom4) into line 4 of fld "fldout"
end OpenStack
Re: I'm Brand New to Livecode and Making a Simple Scipt
Posted: Thu Aug 20, 2020 2:13 am
by dunbarx
Hi.
Please enclose your code offerings between the code tags: "</>".
It makes them much easier to read.
Craig
Re: I'm Brand New to Livecode and Making a Simple Scipt
Posted: Thu Aug 20, 2020 8:53 am
by AxWald
Hi,
from the dictionary, bold by me:
PreOpenStack: Sent to the destination card when you open a stack.
Handle the preOpenStack message to update a card's appearance before the card appears on screen.
The preOpenStack message is sent before the openStack message. Unlike openStack, preOpenStack handlers are executed before the stack window appears. Because of this, the preOpenStack handler is a good place to put code that adjusts the size, position, and appearance of objects; the changes are made before the stack appears.
1.) Put it (and openStack!) into cd 1 of the stack where it is used. This way it's only called for this stack, and not for every stack you open.
2.) What's in preOpenStack happens before the window is drawn. So any code here will add to the "perceived startup time" of your stack.
3.) Additionally, preOpenStack is very early in the startUp order - be careful, there might be still some libraries not yet loaded!
For your problem:
Your shell calls will take a considerable time. I'd not have it run without user interaction - this just feels not good, staring at the screen, waiting for something to happen, not knowing what happens!
Instead make the user actively request the fetching of these data, with appropriate warning:
Code: Select all
Dear User!
I will now fetch some valuable system data:
- your MAC adress,
- your computer serial number,
- your hostname and
- your BIOS version.
This will take some time, please be patient!
[CANCEL] [OK]
Then show a busy cursor, and take your time - the user will accept it gladly.
Have fun!