Problem running script from Watch

I have a very simple script which I would like to run from the Apple Watch (Series 6). I created a shortcut which calls the Scriptable script but what I get is “Run Script”, I touch run and it just ends. I would like it to speak the result without any extra intervention. I know there are easier ways to do this without scriptable but I’m just trying to get a handle on how to get anything to work on the watch. I would also like it to show the results as text but when I tried to use the alert function that didn’t work on the watch either.
Here is the script:

var today = new Date();
var dd = String(today.getDate()).padStart(2, '0');
var mm = String(today.getMonth() + 1).padStart(2, '0'); //January is 0!
var yyyy = today.getFullYear();

today = mm + '/' + dd + '/' + yyyy;

var date1 = new Date('06/11/2020');
var date2 = new Date(today)

var Difference_In_Time = date2.getTime() - date1.getTime(); 
// To calculate the no. of days since Alan was born:
var Difference_In_Days = Math.round(Difference_In_Time / (1000 * 3600 * 24)); 
  Difference_In_Days + " days old.”
Speech.speak("Alan is " + Difference_In_Days + " days old.");

1 Like

I assume you accept this running on the phone - from the watch?

I’d like this to work - and I accept the above.

Sorry, but I am not sure what you are saying.

You said “problem running script from watch”. I was trying to figure out what you meant.

It seems the problem might be getting Speech.speak() to do anything useful on the watch.

I don’t know if this is part of your problem, but you have a wrong quote character in your script (look at the second one):

It shouldn’t be but ".

This could also be only a typo here and fine in your script, but since I noticed it I wanted to point it out.

This shortcut works from the watch for what you have above.

The key issue is that you are attempting to use Speech.speak(). You need to be in the scriptable app for Scriptable to be able to access the speech synthesis. You are running the script in Shortcuts, so Shortcuts is what has access to that, not Scriptable; plus Scriptable doesn’t have an Apple Watch component just yet (though Simon has been toying with complications in the last few days).

The workaround is simply to do the text generation in Scriptable, and then pass that back to Shortcuts to speak. That way, Shortcuts can speak it on the watch after the script runs as a purely inline action.

1 Like

Got it. I look forward to more integration with the Watch. Having Shortcuts back in WatchOS is very nice and being able to extend the range of actions to include Scriptable would make it even more useful.

1 Like