Improvement requests :  K-Meleon Web Browser Forum
Use this forum to talk about a feature you're missing. 
Macro pause like the WScript Sleep method
Posted by: JamesD
Date: October 03, 2008 01:19PM

I wonder if it would be possible to get a pause statement for the macro language? Could be modeled on the sleep method for WScript. Would need to be pause( value ) where value is number of milliseconds.

This could allow a macro to wait for completion of an external application called by the exec statement.

Options: ReplyQuote
Re: Macro pause like the WScript Sleep method
Posted by: JujuLand (unlogged)
Date: October 05, 2008 08:52AM

exec function has no wait param, and can't wait for external end of execution.

You can use the functions made by mark 307, to wait for the end of execution, or to test the content of a file , but in this case, it can make problem with K-Meleon which seems don't answer (for OS)

A way would be something like this

your external process does:

-create a flag file
-execute what you need
-delete the flag file

in you macro:

your_function{

$_nbTries=0
while (tries<5) &_test
tries== 5 ? &error:0;

....
}

_test{
does the flag file exists ?
no > tries = 10 > return
yes > tries = tries +1 > tempo > return
}

tempo is a call to utils kplugin to wait x ms (1000 = 1s)

You can replace the exist flag way by a file content test depending of what your process does.

A+

Options: ReplyQuote
Re: Macro pause like the WScript Sleep method
Posted by: JamesD
Date: October 07, 2008 06:05PM

@ JujuLand

This sounds like it could be really useful. Can you give me the exact syntax for the call "tempo to kplugin utils"?

Thanks for your help.

Options: ReplyQuote
Re: Macro pause like the WScript Sleep method
Posted by: JujuLand (unlogged)
Date: October 08, 2008 11:55AM

Here is the txt file accompagning the dll version 0.07 (by mark307):

FIXME: Broken English

Macro Utilities Plugin
Version 0.0.7

* Summary

This plugin contains some commands to use in macros.cfg.


* Install

Just copy "utils.dll" to kplugins folder.


* Uninstall

Delete "utils.dll".


* How to use

** file IO

# check whether file is exist
# returns "true" or "false"

$result = pluginmsgex(utils, "exist", $file, STRING);

# copy file

pluginmsg(utils, "copyfile", $from, $to);

# rename file

pluginmsg(utils, "rename", $from, $to);

# delete file

pluginmsg(utils, "unlink", $file);

# read text from file and return them.
# if file isn't exist, this returns "".

$text = pluginmsgex(utils, "read", $file, STRING);

# write text to file
# if file is exist, file will be replaced.

pluginmsg(utils, "write", $file, $text);

# append text to file
# if file isn't exist, file will be created.

pluginmsg(utils, "append", $file, $text);

# make directory
# returns "true" or "false"

$result = pluginmsgex(utils, "mkdir", $path, STRING);


** Dialog

# show the file open dialog by GetOpenFileName Win32 API.

$name = pluginmsgex(utils, "GetOpenFileName", $default, STRING);

# show the file save dialog by GetSaveFileName Win32 API.

$name = pluginmsgex(utils, "GetSaveFileName", $default, STRING);

# show the folder select dialog by SHBrowseForFolder Win32 API.

$name = pluginmsgex(utils, "SelectDirectory", $default, STRING);


** OS

# read registory
# key is like "HKCU\\Software\\K-Meleon\\K-Meleon\\General\\InstallDir"

$value = pluginmsgex(utils, "RegRead", $key, STRING);

# get environment variable

$value = pluginmsgex(utils, "getenv", $name, STRING);

# execute program and wait for process termination
# unit of timeout is millisecond.
# timeout must be greater than -1 and less than 10000 (10sec)
# if timeout is -1, it waits 10000 (10sec).

pluginmsg(utils, "exec", $command, $timeout);

# wait
# timeout must be greater than zero and less than 10000 (10sec)

pluginmsg(utils, "sleep", $timeout);

# Get OS Version
# Gets os version by GetVersionEx Win32API
# Field is "Major", "Minor", "Build", "Platform", "CSD", or "".
# These are associated with dwMajorVersion, dwMinorVersion,
# dwBuildNumber, dwPlatformId, szCSDVersion, or all.

$value = pluginmsgex(utils, "GetOSVer", $field, STRING);

# useful idiom: 9X or NT
$os = pluginmsgex(utils, "GetOSVer", "Platform") == 2 ? "NT" : "9X";

# Get current time
# format is same as strftime C function
# see http://msdn2.microsoft.com/en-us/library/fe06s4ak.aspx

$result = pluginmsgex(utils, "strftime", $format);


** string

# convert Windows charset to UTF8

$utf8 = pluginmsgex(utils, "EncodeUTF8", $text, STRING);

# convert UTF8 to Windows charset

$text = pluginmsgex(utils, "DecodeUTF8", $utf8, STRING);

# URL escaping

$escaped = pluginmsgex(utils, "urlescape", $text, STRING);


* How to add command

1. Select command type
- pluginmsg
two arguments, no return value
- pluginmsgex
one argument, one return value
Arguments are always pointer of char (or NULL).

If you choose pluginmsg, jump to 3.
If you choose pluginmsgex, continue.

2. Select type of return value.
- BOOL
same as int
- INT
same as int
- STRING
same as pointer of char

If you choice STRING, you have to assign a return value by malloc.

3. Write a function.

4. Add your function to struct funcs in utils.cpp.
First member is command name.

Second member is command type.
If command type is pluginmsg, this member must be TYPE_MSG.
If command type is pluginmsgex, this member must be TYPE_MSGEX.

Third member is the function you write.

5. Build and test.


* License

This software is distributed under GPL (see COPYING).

A+

Options: ReplyQuote
Re: Macro pause like the WScript Sleep method
Posted by: JamesD
Date: October 08, 2008 04:02PM

Wow! That is a lot of possibilities. This can be obtained just by adding the utils.dll file to kplugins?

Is the utils.dll file part of lua macros? I am trying to get that but the site does not work.
http://luaforge.net/frs/download.php/3677/lua5_1_4_Win32_bin.zip
This just times out.

Is lua macros the place to find the utils.dll file?

Options: ReplyQuote
Re: Macro pause like the WScript Sleep method
Posted by: JujuLand (unlogged)
Date: October 08, 2008 05:17PM

No, utils and luamacros are different kplugins, and none is required by the other.

If you don't have utils.dll, you can find it in an extension (quicknote, for example).

A+

Options: ReplyQuote
Re: Macro pause like the WScript Sleep method
Posted by: JamesD
Date: October 08, 2008 09:38PM

Thanks.

As soon as I can, I will have a look at extensions.

Options: ReplyQuote


K-Meleon forum is powered by Phorum.