I have two small macros which demo a system to quickly test if a certain macro is running on the system. The MacroIf.kmm file produces an ini file with all the names of active macros. The TestForMacro.kmm file is a demo of how query the ini file.
I had hoped the the query method could be used in toolbars.cfg but it does not seem to work as a %if query.
@ Jujuland
The $macroModules string seems only to have active macro names. Therefore I did not have to go to prefs.js to get inactive ones.
MacroIf.kmm
# K-Meleon Macros (http://kmeleon.sourceforge.net/wiki/index.php?id=MacroLanguage)
#
# ---------- MacroIf.kmm
# ---------- Runs at init to produce an ini file with all active macro names
#
# Dependencies : main.kmm
# Resources : -
# Preferences : -
# Version : 0.2 10-14-09
# --------------------------------------------------------------------------------
_MacroIf_RunCode{
$_MacroIf_MList = substr($macroModules,1);
$_MacroIf_Dist = index($_MacroIf_MList,";");
while($_MacroIf_Dist > 1) {
$_MacroIf_Unit = substr($_MacroIf_MList,0,$_MacroIf_Dist);
$_MacroIf_Section = "MacroNames";
$_MacroIf_Value = true ;
iniwrite($_MacroIf_Section, $_MacroIf_Unit, $_MacroIf_Value, $_MacroIf_Path);
$_MacroIf_MList = substr($_MacroIf_MList,$_MacroIf_Dist+1);
$_MacroIf_Dist = index($_MacroIf_MList,";");
}
## - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
$_MacroIf_Path=getfolder(UserMacroFolder)."\\MacroIf.ini";
$OnInit=$OnInit."_MacroIf_RunCode;";
$macroModules=$macroModules."MacroIf;";
TestForMacro.kmm
# K-Meleon Macros (http://kmeleon.sourceforge.net/wiki/index.php?id=MacroLanguage)
#
# ---------- TestForMacro.kmm
# ---------- Demo of method to test if a macro is running on the system
#
# Dependencies : main.kmm
# Resources : -
# Preferences : -
# Version : 0.1 10-14-09
# --------------------------------------------------------------------------------
_TestForMacro_RunCode {
## -- Try with $_TFM_Query set to "MacroIf" and then try with it set to "NothingElse"
$_TFM_Query = "MacroIf" ;
#$_TFM_Query = "NothingElse" ;
if (iniread("MacroNames", $_TFM_Query, $_tfm_value, $_TestForMacro_Path) != true){
alert($_TFM_Query." macro not active", "Results of query on ".$_TFM_Query." in MacroIf.ini", INFO);
} else {
alert($_TFM_Query." macro active", "Results of query on ".$_TFM_Query." in MacroIf.ini", INFO);
}
}
_TestForMacro_GetPath { $_TestForMacro_Path=getfolder(UserMacroFolder)."\\MacroIf.ini"; }
_TestForMacro_BuildMenu { setmenu("&Tools",macro,"Test for macro",_TestForMacro_RunCode,Misc); }
$OnStartup=$OnStartup."_TestForMacro_GetPath;";
$OnInit=$OnInit."_TestForMacro_BuildMenu;";
$macroModules=$macroModules."TestForMacro;";