K-Meleon
KMeleonWiki > Resources > MacroLibrary > Open Nick or Macro
Submitted by: MonkeeSage?
Notes:
Sometimes you need to run macros or open (bookmark / hotlist / favorites) nicknames and quicksearches; this macro aims to make that a little easier to do by presenting a single prompt that will handle either case. Note: Nicks and macros must have unique names or else it will always open the nick instead of the macro.
open_nick_macro { # vars $theurl1=""; $theurl2=""; $nick1=""; $nick2=""; $isNick=""; $isQs=""; $isMacro=""; # get the prompt text into $theurl $theurl = prompt("Nickname or macro to execute:", "Open"); # check for spaces in $theurl, if no spaces $theurl1 inherits $theurl $len = length($theurl); $index = index($theurl, " "); $index == -1 ? $theurl1 = $theurl : $theurl1 = substr($theurl, 0, $index); $index == -1 ? 0 : $theurl2 = substr($theurl, $index + 1, $len); # check for nickname $nick = pluginmsgex("bookmarks", "FindNick?", $theurl1, STRING); $nick == "" ? $nick = pluginmsgex("hotlist", "FindNick?", $theurl1, STRING) : 0; $nick == "" ? $nick = pluginmsgex("favorites", "FindNick?", $theurl1, STRING) : 0; # if not a nickname, it is a macro $nick == "" ? $isMacro = "TRUE" : 0; $isMacro == "TRUE" ? macros($theurl1) : 0; # otherwise is a nickname, check for quicksearch token $len = length($nick); $index = index($nick, "%s"); # if no quicksearch token, open as URL $index == -1 ? $isNick = "TRUE" : $isQs = "TRUE"; $isNick == "TRUE" ? open($nick) : 0; # otherwise is a quicksearch, tokenize $nick and replace # quicksearch token with $theurl2 $nick1 = substr($nick, 0, $index); $nick2 = substr($nick, $index + 2, $len); $isQs == "TRUE" ? open($nick1 . $theurl2 . $nick2) : 0; }
CTRL M = macros(open_nick_macro)
NickMacro? { macros(open_nick_macro) Open nick or macro hottool.bmp...? coldtool.bmp...? deadtool.bmp...? }
MonkeeSage? comments: You can also make this a nick / url prompt if you don't need to call macros from a prompt, by changing the following lines:
$isMacro=""; ... # if not a nickname, it is a macro $nick == "" ? $isMacro = "TRUE" : 0; $isMacro == "TRUE" ? macros($theurl1) : 0;
to:
$isURL=""; ... # if not a nickname, it is a URL $nick == "" ? $isURL = "TRUE" : 0; $isURL == "TRUE" ? open($theurl1) : 0;