Start a function instead of url

Hi, i need to run a function on a click to a text. How can I do it? I cant get it to work. I tried to do it with .url etc. Any idea? Thanks!

const AcVal = AcStack.addText("➤ Klima starten")
AcVal.font = Font.boldSystemFont(12)
AcVal.url = myFunction() // this does not work.

May be that’s feasible by including the function in another script and stating that via a URL?

Thanks for your reply. I cant use multiple script cause it must stay simple to install for others. I cant believe that i cant use a “hyperlink” to start a function.

You could use a single script to install the other scripts. Then you can use multiple scripts and keep the installation simple.

But i have multiple login tokens etc. in my script and cant push them to the “new/second” script via url. have to think about it … thanks

Have them in the installation script and have that script write a settings file.

@mountbatt Would something like this work for you? PS: This is a really quick and dirty example.

I added query parameter to the URL and used that to display different console.log() statements. Seems to work ok in my testing.

1 Like

I’ve also used .url extensively in this widget here:

Unless I’m missing something it should be possible to run a function based on which url is tapped although a little workaround is required.

Thanks. Nice! Will have a look.

1 Like

Were you able to get it to work?

Thanks alot! I got it to work. Not the best solution, cause the widget opens Scriptable App, then opens the widget in the App and then the code gets submitted as a attr parameter. But at the end: it seems to work :slight_smile: Again: thanks for your help!

I said: “not the best solution” … sorry. I think it is limited to this behaviour by Apple … Not your fault etc.

Yes, I hope Apple would make this behaviour a lot more subtle ie: a simple banner saying “Scriptable is running your script” would be sufficient compared to opening the host app.

Regarding the widget opening in Scriptable, perhaps something like this would work for you?

if (config.runsInApp) {

if (config.runsInWidget) {
  // run your function without invoking the w.presentSmall()

Working example can be seen here:

1 Like

Oh thats could be a helpful solution. Will again have a look :smile: Thanks