How to Open web link in panel in GH

I was going to ask the question but figured it out myself (first ever working GH and C# script at the same time.)

Here’s how to open a URL from a panel on clicking a toggle button!

This is for my “references” on where i found a GH script and avoid copy pastes. Hope it helps the beginners like me.

Open Weblink.gh (6.0 KB)

private void RunScript(object x, object y, ref object A)
{
System.Diagnostics.Process.Start(x);
}

Never thought it would be this simple.

But this brings the question why there isn’t a proper formatted text panel (with clickable links) in GH? Unless there is already - not found so far… If there is, thanks for the hint.

This is rather scary and dangerous as far as I’m concerned… Especially because it fires when the file is first opened, without clicking the Toggle. This could easily trigger a file download and be buried deeply in what otherwise appears to be innocuous code. Danger,

Replacing the Toggle with a Button causes it to fire twice when the button is clicked, opening two browser tabs.

We’re doooomed! Just add the url of your gh file, save, set windows’ ulr auto-open link to true and start that infinite loop…

Damn, there’s no a simple button in GH? This seems a bit unwanted ‘default’ behavior in the least - i never expected that button to click on ‘startup’ - how come? Oh, i didn’t add a “if button is on” clause…

Hilarious that the Button clicks twice! Didn’t expect that…
If you disable it, it launches again too! My c# script was too basic to be true…

Fixed…

private void RunScript(string URL, bool ClickMe, ref object A)
{
if(ClickMe)
{
System.Diagnostics.Process.Start(URL);
}
}

on mouseup
  if URL is not opened in browser then openlink URL
end mouseup

GH is my HyperCard 6.0 come true but the fact that you can’t script the button just tilted in my head! I really miss (in GH) the button and fields you could lay in your card (GH canvas) and script their behavior natively in the GUI/canvas. Adding cards/tabviews in the canvas would be cool to organize scripts (in some cases…) - but ok, im sure those ideas were explored and not practical vs the zoom gui… Still, gives me an idea or two…

The formatted text field in HyperCard was a great “Canvas related” help/labeling/status info/display for ‘easier’ documentation, buttons helped a lot for not just ‘functions’ but also for navigation - there was/is no zoom/vector gui (unless you want to program it - can be done natively too)). A custom icon/pict button could offer pop help text when hovering, or go to to parts of the script like the jump button (but with names of groups or modules, etc)

Back to learning GH.
Sorry, it’s Sunday buckload of ideas…

1 Like