Run macro before all other macros at startup

J70P

New member
I want a macro to be executed before all others when MacroDroid starts, for example to set initial values for variables. There is "Device Boot" and "MacroDroid Initialised". But both don't seem to run before any other macros. Tasker has the "Monitor Start" trigger for this purpose. Is there something similar in MacroDroid?
 

Abalsam

Active member
I want a macro to be executed before all others when MacroDroid starts, for example to set initial values for variables. There is "Device Boot" and "MacroDroid Initialised". But both don't seem to run before any other macros. Tasker has the "Monitor Start" trigger for this purpose. Is there something similar in MacroDroid?
You might have to come at this differently. Instead of trying to force one macro to launch and complete before the others, all you need to do is make sure the macro of interest completes before the other macros start being processed.

Instead I would have the initializing macro record as it's last action a global variable called BootTime of system time - uptime (in seconds) as that would be the time in seconds when android last started up. Then I would have the other macros configured to start at device boot start with a loop configured to do the following:

Continue running until BootTime+uptime (in seconds) +1 > system time
Pause 1 minute
End loop

This would give the macro you want to use to initialize a chance to complete before anything else starts up.

Hope that helps
 

Snurre

Well-known member
I want a macro to be executed before all others when MacroDroid starts, for example to set initial values for variables. There is "Device Boot" and "MacroDroid Initialised". But both don't seem to run before any other macros. Tasker has the "Monitor Start" trigger for this purpose. Is there something similar in MacroDroid?
I think it would be possible to disable all macro's (except the one you would run first) when you close MD
When MD starts it will run that macro and as the last action in this would be to enable your other macro's
Just a thought
 

Abalsam

Active member
I think it would be possible to disable all macro's (except the one you would run first) when you close MD
When MD starts it will run that macro and as the last action in this would be to enable your other macro's
Just a thought
Snurre,

If the phone restarts without you having a chance to disable all other macros, your suggestion would not work.
 

Snurre

Well-known member
You could also try to set a little delay in the beginning of the "conflicting" macro's
 

J70P

New member
Thanks for your suggestions.

I am currently using Tasker and I am thinking of switching to MacroDroid.

If I have as many macros in MacroDroid as I have in Tasker, I think the suggestions are too complicated. My opinion is, that it should be possible from the program side. To set initial values for variables, to read a config file and so on.
 

Abalsam

Active member
Thanks for your suggestions.

I am currently using Tasker and I am thinking of switching to MacroDroid.

If I have as many macros in MacroDroid as I have in Tasker, I think the suggestions are too complicated. My opinion is, that it should be possible from the program side. To set initial values for variables, to read a config file and so on.
One thing I would point out is that variables persist between reboots so in theory, you would only need to set them once and then update them as needed.
 

RSF

Well-known member
@Threshold -

MacroDroid doesn't have that construct of guaranteeing to start a macro before any others; furthermore, it doesn't have the Tasker construct of priority either, which is how you can guarantee that a such macro not only starts, but also completes, before other macros.

To further @Abalsam 's comment, MacroDroid's local, as well as global, variables persist after a macro finishes executing -- unlike in Tasker, That may help you avoid some of what you're doing in Tasker. (and it's a good feature in general -- helpful in debugging, etc.).

But if you do a macro to complete prior to all other macros, you'll need to implement something like the timer scheme suggested above. You would only need to write the logic once, in either a macro or a similar concept MacroDroid introduced recently called "Action Blocks". Then add a single step to the beginning of each of your (post-bootup) macros to call that macro/action block which would wait until your boot-up macro finishes.

I acknowledge it'd be nicer to have MacroDroid facilitate this more automatically, but I don't think there's a way to do that currently.
 

Terithee

New member
Would this not work to solve the problem

Trigger on boot
Set variables
Wait 5-10 seconds
Call next macro
Wait
Call next macro

Repeat untill all of your on boot macros have run
(Note triggers for subsequent macros would be empty and not on boot)

I believe this workaround would give you the ability to prioritize all of your on boot macros.

(Sorry dont have the time to build and upload an example)
 

Abalsam

Active member
Would this not work to solve the problem

Trigger on boot
Set variables
Wait 5-10 seconds
Call next macro
Wait
Call next macro

Repeat untill all of your on boot macros have run
(Note triggers for subsequent macros would be empty and not on boot)

I believe this workaround would give you the ability to prioritize all of your on boot macros.

(Sorry dont have the time to build and upload an example)
In theory this would work assuming your intended order is maintained and you correctly call the next link in the chain.

But again, since macrodroid variables retain their values what exactly would you be initializing?
 
You can detect shutdown and set a boolean or macrodroid mode, say Shutdown.

Add a constraint to all macros "mode not Shutdown". They will never run when you restart....

In you start up macro, trigger on macrodroid initialized. Do your stuff. Change macrodroid mode from Shutdown to Startup.

Now, all your other macros can run.
 

Attachments

  • Mode_Shutdown.macro
    2.7 KB · Views: 10

Abalsam

Active member
You can detect shutdown and set a boolean or macrodroid mode, say Shutdown.

Add a constraint to all macros "mode not Shutdown". They will never run when you restart....

In you start up macro, trigger on macrodroid initialized. Do your stuff. Change macrodroid mode from Shutdown to Startup.

Now, all your other macros can run.
I had not thought of using modes thank you for the suggestion. However, since the original question was related to ensuring the designated macro ran first before the others instead of the others not running at all, your solution would have to be modified so that the other macros to run at boot wait until the mode is reset.
 
I had not thought of using modes thank you for the suggestion. However, since the original question was related to ensuring the designated macro ran first before the others instead of the others not running at all, your solution would have to be modified so that the other macros to run at boot wait until the mode is reset.
I believe that is exactly what would happen. On shutdown, set a mode that keeps all maroos but one from starting. How? Add a constraint to all macros but one.

For that one unconstrained macro, triggered by Macrodroid Initialized, you remove the constraint.
 

Qarboz

Well-known member
I believe that is exactly what would happen. On shutdown, set a mode that keeps all maroos but one from starting. How? Add a constraint to all macros but one.

For that one unconstrained macro, triggered by Macrodroid Initialized, you remove the constraint.

You should know which triggers the other Threshold macros use.
Because if they use i.e. Macrodroid initialized and this trigger has a constraint I don't think they work, since that trigger has already occurred and does not repeat until restart, but when there will still be the constraint that blocks the macro...
I think that in the various macros that have to wait for the execution of the "master" macro as the first action there should be a while/do with the condition of the Macrodroid mode (or the boolean variable = true)
 
You should know which triggers the other Threshold macros use.
Because if they use i.e. Macrodroid initialized and this trigger has a constraint I don't think they work, since that trigger has already occurred and does not repeat until restart, but when there will still be the constraint that blocks the macro...
I think that in the various macros that have to wait for the execution of the "master" macro as the first action there should be a while/do with the condition of the Macrodroid mode (or the boolean variable = true)
I know that I can run another macro, so whatever actions currently triggered by macrodroid Initialized can be a new macro and executed after the special actions and the mode changed to Startup. You may have to rearrange some code or be creative about how you get that code executed.

I'm no pretending to know all about the collective actions and triggers. I do know that this can be done with a little imagination. I do it using the method described.
 

J70P

New member
You can detect shutdown and set a boolean or macrodroid mode, say Shutdown.

Add a constraint to all macros "mode not Shutdown". They will never run when you restart....

In you start up macro, trigger on macrodroid initialized. Do your stuff. Change macrodroid mode from Shutdown to Startup.

Now, all your other macros can run.

I like this idea. For a user invoked reboot ... but what about the case that Android restarts MadroDroid?

See for example https://www.macrodroidforum.com/index.php?threads/macro-run-at-boot.1638/
 
Why do you think this is necessary? I'm sure you have a good reason. I'm not aware of any triggers due to Macrodroid restarting, at least I do not see any when I toggle the enable/disable switch.

The only thing I know how to do is detect device start, as previously described. I don't see a way to detect app crash and restart. Can you describe why you need to do your special actions on app restart?
 

Abalsam

Active member
Why do you think this is necessary? I'm sure you have a good reason. I'm not aware of any triggers due to Macrodroid restarting, at least I do not see any when I toggle the enable/disable switch.

The only thing I know how to do is detect device start, as previously described. I don't see a way to detect app crash and restart. Can you describe why you need to do your special actions on app restart?
The trigger macrodroid initialized would cover not only the first time macrodroid starts after a reboot but also if macrodroid restarts due to a software update or an android os forced macrodroid restart (which happens occasionally). I would be interested in that trigger to ensure that some macdroid functions which do not resume after a macrodroid restart such as stopwatches, resume correctly.
 
Top