Register forum user name Search FAQ

Gammon Forum

Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the password reset link.

Due to spam on this forum, all posts now need moderator approval.

 Entire forum ➜ MUSHclient ➜ General ➜ Execute a script on hyperlink click?

Execute a script on hyperlink click?

It is now over 60 days since the last post. This thread is closed.     Refresh page


Posted by Kahenraz   (75 posts)  Bio
Date Mon 19 Mar 2018 12:29 PM (UTC)
Message
From what I can tell the action performed on a hyperlink is sent to the world. Is it possible to have it instead execute some lua code?
Top

Posted by Fiendish   USA  (2,534 posts)  Bio   Global Moderator
Date Reply #1 on Mon 19 Mar 2018 02:00 PM (UTC)
Message
Yeah. It's a little buried inside the docs, but if you look at https://www.gammon.com.au/scripts/doc.php?function=Hyperlink you should find a section that starts

Quote:
From version 3.42 you can also call a script in a plugin from a Hyperlink


The description could be cleaned up, because it looks like it was written specifically for VBscript, but mostly you can just mentally replace any use of the word "sub" with "function" and then "&" between strings becomes ".." for Lua

https://github.com/fiendish/aardwolfclientpackage
Top

Posted by Kahenraz   (75 posts)  Bio
Date Reply #2 on Mon 19 Mar 2018 03:36 PM (UTC)
Message
I can't find a way to make it work for the current scope. For example, the documentation says that I must provide a plugin id but I want to call a function that is already accessible and is not part of any plugin.

Is there a plugin id that I can provide that represents the current scope?
Top

Posted by Fiendish   USA  (2,534 posts)  Bio   Global Moderator
Date Reply #3 on Mon 19 Mar 2018 05:23 PM (UTC)
Message
Quote:
Is there a plugin id that I can provide that represents the current scope?

I don't think so.

https://github.com/fiendish/aardwolfclientpackage
Top

Posted by Nick Gammon   Australia  (23,133 posts)  Bio   Forum Administrator
Date Reply #4 on Mon 19 Mar 2018 10:30 PM (UTC)
Message
About the only way you can do that is make a small plugin (there is a plugin wizard that makes writing plugins easy) to be the target of the hyperlink. If you are desperate to go back to global script space have the plugin "Execute" some alias that the main script then catches and acts upon.

Template:function=Execute Execute

The documentation for the Execute script function is available online. It is also in the MUSHclient help file.



You could pass arguments to the executed alias.

eg.


function hyperlinkCallback (arg)
  Execute ("6f5b06cfe811fb62ba399eb0 " .. tostring (arg))
end -- of hyperlinkCallback


That first thing is just some random string that hopefully you don't normally type. Then make an alias in the main world script that matches:


6f5b06cfe811fb62ba399eb0 *


Now you know when the hyperlink was clicked and what the argument to it was.




An example of such a plugin would be:

Template:saveplugin=Hyperlink_Redirector To save and install the Hyperlink_Redirector plugin do this:
  1. Copy between the lines below (to the Clipboard)
  2. Open a text editor (such as Notepad) and paste the plugin into it
  3. Save to disk on your PC, preferably in your plugins directory, as Hyperlink_Redirector.xml
  4. Go to the MUSHclient File menu -> Plugins
  5. Click "Add"
  6. Choose the file Hyperlink_Redirector.xml (which you just saved in step 3) as a plugin
  7. Click "Close"



<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE muclient>
<muclient>
<plugin
   name="Hyperlink_Redirector"
   author="Nick Gammon"
   id="54ba3415104e5371948c933d"
   language="Lua"
   purpose="Catches a hyperlink function call and sends to execute"
   date_written="2018-03-20 07:37:13"
   requires="5.00"
   version="1.0"
   >
</plugin>

<!--  Script  -->

<script>
<![CDATA[
function hyperlinkCallback (arg)
  Execute ("6f5b06cfe811fb62ba399eb0 " .. tostring (arg))
end -- of hyperlinkCallback
]]>
</script>
</muclient>





Example alias:


<aliases>
  <alias
   match="6f5b06cfe811fb62ba399eb0 *"
   enabled="y"
   send_to="12"
   sequence="100"
  >
  <send>Note ("Hyperlink clicked with argument: %1")</send>
  </alias>
</aliases>


Template:pasting For advice on how to copy the above, and paste it into MUSHclient, please see Pasting XML.





Now you can make your hyperlink as you have a plugin ID:


Hyperlink ("!!54ba3415104e5371948c933d:hyperlinkCallback(foo)", "Shown text", "hover text", "yellow", "green", 0)

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Kahenraz   (75 posts)  Bio
Date Reply #5 on Tue 20 Mar 2018 08:02 PM (UTC)
Message
That's a pretty complicated workaround. Would it be too much to ask to get this kind of support added natively for a future update?
Top

Posted by Nick Gammon   Australia  (23,133 posts)  Bio   Forum Administrator
Date Reply #6 on Tue 20 Mar 2018 09:41 PM (UTC)
Message
Actually it is much simpler than that. Re-reading the source gives this solution:


Hyperlink ("foo", "Shown text", "hover text", "yellow", "green", 0)


The hyperlink action is executed (sent to the command processor) so all you have to do now is make an alias that matches "foo".

That alias can execute a script. Make the word "foo" something long and complicated as you don't want to accidentally fire if someone types it. My earlier example of a long hex string would be fine:


Hyperlink ("6f5b06cfe811fb62ba399eb0", "Shown text", "hover text", "yellow", "green", 0)

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Nick Gammon   Australia  (23,133 posts)  Bio   Forum Administrator
Date Reply #7 on Tue 20 Mar 2018 09:46 PM (UTC)

Amended on Tue 20 Mar 2018 09:47 PM (UTC) by Nick Gammon

Message
You could be fancier and make an alias that just executes arbitrary scripts, eg.


<aliases>
  <alias
   match="6f5b06cfe811fb62ba399eb0 *"
   enabled="y"
   send_to="12"
   sequence="100"
  >
  <send>%1</send>
  </alias>
</aliases>


All that does is send its argument as a script. Now your hyperlink could be:


Hyperlink ("6f5b06cfe811fb62ba399eb0 print ('hello world')", "Shown text", "hover text", "yellow", "green", 0)


The script "print ('hello world')" will be passed as a wildcard to the alias matching '6f5b06cfe811fb62ba399eb0 *' which will then execute it. That way you could run any script you like, with a single alias as the go-between.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Kahenraz   (75 posts)  Bio
Date Reply #8 on Tue 20 Mar 2018 09:47 PM (UTC)

Amended on Tue 20 Mar 2018 09:48 PM (UTC) by Kahenraz

Message
I appreciate the workarounds but they all still add a lot of necessary coupling and complication.

Would it be possible to simply implement the ability to call a local function with "!!func()" rather than the form "!!plugin:func()"?
Top

Posted by Nick Gammon   Australia  (23,133 posts)  Bio   Forum Administrator
Date Reply #9 on Tue 20 Mar 2018 10:13 PM (UTC)
Message
It's not that easy because the ordinary scripting interface has to allow for multiple languages, some of which have fixed numbers of arguments (unlike Lua).

If I implement !!func() next someone will want !!func(arg1,arg2,arg3) and then things will get complicated.

A single redirecting alias, as suggested in my previous post, is hardly a lot of extra complication. It's one alias that would let you call arbitrary scripts with arbitrary numbers of arguments.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Kahenraz   (75 posts)  Bio
Date Reply #10 on Wed 21 Mar 2018 08:30 AM (UTC)

Amended on Wed 21 Mar 2018 08:32 AM (UTC) by Kahenraz

Message
That's a pretty complicated workaround. Would it be too much to ask to get this kind of support added natively for a future update?
Top

Posted by Kahenraz   (75 posts)  Bio
Date Reply #11 on Wed 21 Mar 2018 08:33 AM (UTC)
Message
An alternative would be to mention in the docs that it's a Lua-exclusive feature, since that tends to be the most common language used for scripting for Mush anyways.
Top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


29,203 views.

It is now over 60 days since the last post. This thread is closed.     Refresh page

Go to topic:           Search the forum


[Go to top] top

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.