Actiongroup called from a plugin

Posted on
Fri Oct 18, 2019 2:02 am
Umtauscher offline
User avatar
Posts: 552
Joined: Oct 03, 2014
Location: Cologne, Germany

Actiongroup called from a plugin

Hi,

sorry for crossposting this issue. I first posted it on the Notification-Plugin subforum but I suppose it's better here.
This problem is connected to the possibilities in the Notification plugin but I think there are more things at work which might be of broader concern..
It seems using Python script, all action groups that are called in a sequence are executed nearly simultaniously which is a bad idea when using actiongroups as a kind of function call.
So here is the original post . I hope there is something to do about it.

I have a Notification category defined for the notificationplugi, that has a minor problem after I converted my Applescripts to Python,
I use an action group that plays a sound via afplay before an announcement is spoken.

Code: Select all
import subprocess
subprocess.call("/usr/bin/afplay /Users/wilhelm/Music/STARWAVE/c827.WAV",shell=True)


This AG is set in the "before speech" option of the notification category. This AG used to play a common sound using the "do shell script" statement calling afplay in an embedded AppleScript.
So the sound was played before the announcement was spoken by the OS.
After converting that mini scipt to python I realize, that the sound and the spoken text are produced simultaneously - I suppose the phython script runs in an additional thread so both are excecuted nearly at the same time.
What can I do?

Posted on
Fri Oct 18, 2019 2:48 am
kw123 offline
User avatar
Posts: 7695
Joined: May 12, 2013
Location: Dallas, TX

Re: Actiongroup called from a plugin

There is a delay option for each individual action in an action group. Set the first to 0 second to 2 secs ...




Sent from my iPhone using Tapatalk

Posted on
Fri Oct 18, 2019 5:55 am
Umtauscher offline
User avatar
Posts: 552
Joined: Oct 03, 2014
Location: Cologne, Germany

Re: Actiongroup called from a plugin

Thanks, but seriously?
That cannot be the only option!

And btw. I have no possibility to change that in a plugin.

Posted on
Fri Oct 18, 2019 6:04 am
FlyingDiver offline
User avatar
Posts: 5351
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: Actiongroup called from a plugin

Indigo will always try to run actions in an action group in parallel, when possible. That’s a design feature. If you need explicit sequencing, you need to do make it so yourself.

joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177

Posted on
Fri Oct 18, 2019 6:05 am
autolog offline
Posts: 3506
Joined: Sep 10, 2013
Location: West Sussex, UK [GMT aka UTC]

Re: Actiongroup called from a plugin

Umtauscher wrote:
Thanks, but seriously?
That cannot be the only option!

And btw. I have no possibility to change that in a plugin.

Currently when you are invoking subprocess, it's starting a completely independent thread that runs alongside you script. as soon as your script calls subprocess, it is proceeding to the next step and not waiting for the result of the subprocess.

You need to wait for the completion of the subprocess call. I did have some code somewhere but can't put my hands on it at the moment. Maybe someone else can chip in. :)

Posted on
Fri Oct 18, 2019 6:23 am
autolog offline
Posts: 3506
Joined: Sep 10, 2013
Location: West Sussex, UK [GMT aka UTC]

Re: Actiongroup called from a plugin

Found it - I had it bookmarked on Stack Overflow - How to get exit code from subprocess.Popen?

Is that enough to get you going? :)

Posted on
Fri Oct 18, 2019 6:34 am
Umtauscher offline
User avatar
Posts: 552
Joined: Oct 03, 2014
Location: Cologne, Germany

Re: Actiongroup called from a plugin

Thanks Jon,

I'm "going" since wednesday ;-)

Nevertheless I think I cannot do anything in my action group, because it's already started in parallel from the plugins code.
So unless there is a means to tell Indigo to run indigo.actionGroup.Execute waiting for the outcome I think I'm screwed.

Cheers
Wilhelm

Posted on
Fri Oct 18, 2019 6:46 am
autolog offline
Posts: 3506
Joined: Sep 10, 2013
Location: West Sussex, UK [GMT aka UTC]

Re: Actiongroup called from a plugin

Can you provide a bit more detail on the settings for the plugin, so that we get a fuller picture of what you are trying to achieve?

It might help us suggest a work-around. :)

Posted on
Fri Oct 18, 2019 7:03 am
Umtauscher offline
User avatar
Posts: 552
Joined: Oct 03, 2014
Location: Cologne, Germany

Re: Actiongroup called from a plugin

The plugin I am talking about is the Notification Plugin.
This plugin has the possibility to create devices called "notification category" where you can define, what should happen when a certain notification is triggerd/sent.
At the bottom of the settings dialog is the possibility to set an action group that is fired before and after a spoken announcement.
I used the before action group to play a Startrek Computer Beep before any anaouncement made.

The action group originally was an embedded Apple Script that played that sound using the afplay shell command.
This was properly in sync, the sound played and afterwards the spoken announcement was played.

Convertig that script resulted in the sound/beep playing simultaneously with the spoken announcement. So my diagnosis is, the action group is executed parallel to the rest of the plugins code resulting in 2 things happening at the same time.

Whatever I do to my script will not help, because the script is already running in parallel to the plugins actions.

I hope this is understandable....

Posted on
Fri Oct 18, 2019 7:07 am
autolog offline
Posts: 3506
Joined: Sep 10, 2013
Location: West Sussex, UK [GMT aka UTC]

Re: Actiongroup called from a plugin

Yes - that is what I understood. :)

What I am wondering is if the actual speaking could be moved into the Python script. If this is the case you would have control over it. That's why I was asking about the exact settings you had. I have been looking at the documentation for the plugin and it has a large number of settings. I wanted to narrow down the specifics of what you were using. :)

Posted on
Fri Oct 18, 2019 7:20 am
FlyingDiver offline
User avatar
Posts: 5351
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: Actiongroup called from a plugin

I think the problem is that your python script is returning before the sound is played. If you could make the sub process call wait to complete, or add a delay to the end of the script, it would work.

joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177

Posted on
Fri Oct 18, 2019 7:25 am
Umtauscher offline
User avatar
Posts: 552
Joined: Oct 03, 2014
Location: Cologne, Germany

Re: Actiongroup called from a plugin

Well the beauty of the plugin is, that it takes a line of text announcement and publishes it depending on the whereabouts of the person you want to notify.
If I would do that in a specific script, I wouldn't need the plugin at all.

What I was merely stating is that it's totally incompatible to execute a python script in an actiongroup in parallel where as an AppleScript would run synchronous to the calling code.
For example it is not possible to set a variable in one ActionGroup and react on that variable in another because you don't know which finishes first.

Posted on
Fri Oct 18, 2019 7:28 am
Umtauscher offline
User avatar
Posts: 552
Joined: Oct 03, 2014
Location: Cologne, Germany

Re: Actiongroup called from a plugin

FlyingDiver wrote:
I think the problem is that your python script is returning before the sound is played. If you could make the sub process call wait to complete, or add a delay to the end of the script, it would work.

I think the problem is, that whatever I do, my script is already running in parallel to the calling code. So I could delay it, but could not make it run earlier.
I tried what you suggest already and it makes no difference.

Posted on
Fri Oct 18, 2019 7:36 am
Umtauscher offline
User avatar
Posts: 552
Joined: Oct 03, 2014
Location: Cologne, Germany

Re: Actiongroup called from a plugin

So the real question is:
Is there any way the plugin code could call "indigo.actionGroup.Execute()" and wait for it to finish?

Posted on
Fri Oct 18, 2019 7:36 am
FlyingDiver offline
User avatar
Posts: 5351
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: Actiongroup called from a plugin

Umtauscher wrote:
So my diagnosis is, the action group is executed parallel to the rest of the plugins code resulting in 2 things happening at the same time.

Whatever I do to my script will not help, because the script is already running in parallel to the plugins actions.


I don’t think that’s correct because the plugin didn’t change. Only the script in the action group changed. So my conclusion is that the script is exiting before the sound is played. Which means you can fix this in the script.

joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177

Who is online

Users browsing this forum: No registered users and 1 guest