Share of some tricks (Passing Parameter & Handle Titles with non-English Words)

Announcements, general discussion
Post Reply
luiwingkin
Posts: 14
Joined: 06 Feb 2018, 05:23

Share of some tricks (Passing Parameter & Handle Titles with non-English Words)

Post by luiwingkin » 06 Feb 2018, 05:58

In fact, I am not using LuaMacros for Flight simulator so I have developed some special techniques for handling the passing parameters.
I am using lLuaMacros to trigger my python scripts, but parameters are required for my scripts.
Therefore, lmc_spawn cannot handle the requirement because only one parameter can be applied, which is occupied by the script name.

For instance, the following works.
lmc_spawn(python_path, program_path .. "ButtonEnd.py")

However,
lmc_spawn(python_path, program_path .. "ButtonEnd.py abc cde")
does not.

Therefore, I write a function something like this:

function run_execute(program, command, arg)
text = ""
full_command = "Start \"\" /B " .. program .. " \"".. command .. "\"" .. " " .. arg
print(full_command)
f = assert(io.popen(full_command, "r"))
for line in f:lines() do
text = text .. line .. " || " -- Cannot use "\n"
--print(line)
end -- for loop
f:close()
return text
end

Along with the undocumented function of "io.popen()", the command can be executed. :)

Also, the related implementation also enables the possibility of returning parameters. :P

For instance, you may write the python code to gain the value from "ClipBoard.py", etc. so as to return the value for your defined.

function getClipboard()
program = pythonw_path
command = program_path .. "GetClipboard.py"
text = ""
full_command = "Start /B " .. program .. " \"".. command .. "\""
--print(full_command)
f = assert(io.popen(full_command, "r"))
for line in f:lines() do
text = text .. line .. " \n " -- Cannot use "\n"
--print(line)
end -- for loop
f:close()
return text
end

Indeed, I have used the function to drive the Arduino board to send the IR command to my TV. :P

lmc_send_keys('^c')
res = getClipboard()
res = trim(res)
lmc_send_to_com('C3', res .. "\n")

================================================================

As my Windows and Office are Chinese versions, the title comparison provided by LuaMacros does not work on them.
Hence, I write the following code to deal with it.

function show_byte(tt)
text = ""
for i = 1,string.len(tt),1 do
text = text .. ", " .. string.byte(string.sub(tt,i,i))
end
print(string.sub(text,3)) -- cut the first two char "," " "
end

function chinese_compare(tt, carray)
if #carray == string.len(tt) then
print(string.len(tt))
print("Match in Size")
for i = 1,string.len(tt),1 do
if string.byte(string.sub(tt,i,i)) ~= carray then
return false
end
return true
end
else
return false
end
end

For each Chinese title, I use "show_byte(tt)" to obtain the byte values of them

tt = lmc_get_window_title()
print(tt)
show_byte(tt)

, while the following macro can be applied to do the comparison.

carray = {165, 92, 175, 224, 197, 220, 188, 198}
if (chinese_compare(tt, carray)) then
--Perform the task
end

:)

I hope the sharing can help some of the users of LuaMacros.

admin
Site Admin
Posts: 735
Joined: 01 Nov 2010, 13:00
Location: Prague, Czech republic
Contact:

Re: Share of some tricks (Passing Parameter & Handle Titles with non-English Words)

Post by admin » 06 Feb 2018, 09:24

Adding support for more parameters to lmc_spawn is not difficult... if it helps.
Petr Medek
LUAmacros author

luiwingkin
Posts: 14
Joined: 06 Feb 2018, 05:23

Re: Share of some tricks (Passing Parameter & Handle Titles with non-English Words)

Post by luiwingkin » 06 Feb 2018, 10:38

May I know how can I do this? :D

admin
Site Admin
Posts: 735
Joined: 01 Nov 2010, 13:00
Location: Prague, Czech republic
Contact:

Re: Share of some tricks (Passing Parameter & Handle Titles with non-English Words)

Post by admin » 07 Feb 2018, 09:48

You can't, it has to be doe in luamacros code, then new release.
Wait a few days
Petr Medek
LUAmacros author

luiwingkin
Posts: 14
Joined: 06 Feb 2018, 05:23

Re: Share of some tricks (Passing Parameter & Handle Titles with non-English Words)

Post by luiwingkin » 08 Feb 2018, 10:33

OK! wait for the new version!

luiwingkin
Posts: 14
Joined: 06 Feb 2018, 05:23

Re: Share of some tricks (Passing Parameter & Handle Titles with non-English Words)

Post by luiwingkin » 24 Sep 2018, 10:50

Finally, I find a solution to the support for multiple parameters.

c = program.." \""..arg1.."\" \""..arg2.."\" \""..arg3
lmc_spawn(c)

In fact, lmc_spawn adds an additional " after the .exe extension, so the additional " should before the first argument.
The following is my code for demonstration. As running python code requires the specification of python.exe so running the script needs for the passing of two parameters, namely, the script file and the option.

program_path = "C:\\Users\\WingKin\\Dropbox\\Small Tools\\"
python_path = "\"C:\\Program Files\\Python36\\python.exe\""
program = python_path
command = program_path .. "DownloadtoPath.py"
arg = "Collection_Run"
c = program.." \""..command.."\" \""..arg
lmc_spawn(c)

Hope the solution help before the new version!

Post Reply