Run macro from macro

Snurre

Well-known member
Hey all
I know I can run a macro from a macro, but is it possible to return to the first macro when completed?
 

Jacob L

Moderator (Lawsonator)
You could use wait until trigger action, and use variable changes. You'd need to change a variable from second macro
 

Snurre

Well-known member
Here is an example of what I would like to do
I have some macro's in which it changes sound settings, instead of changing in all the macro's it would be nice for maintenance just to change it in one place
From different macro's I would like to run a "Sound change" macro from a "If" condition and then return to the calling macro and continue
I know there is a "Sound Profile" app, but I want to keep my phone as "clean" as possible and use as few apps as possible
All I can get MD to do is just great
Recycling rocks ๐Ÿ˜‰
 

Jacob L

Moderator (Lawsonator)
Macro run action might help you. It has an option to wait before moving to the next actions.
 

Snurre

Well-known member
I don't really think that helps me, when it changes settings it don't return to where it was called
Or is it just me?
Be gentle, I'm Danish ๐Ÿคฃ
 

tanutanu

Well-known member
I don't really think that helps me, when it changes settings it don't return to where it was called
Or is it just me?
Be gentle, I'm Danish ๐Ÿคฃ
You have 3 options I recommend you as below:

1. Writing the return value in a global variable and exec the caller macro again using it as the trigger. You can use Wait until action instead. It's much easier than the days when I wrote the same thing with many if/endif code blocks.
2. Writing the return value as a notification text and exec the caller macro. It means using the notification as a scratchpad. It is helpful to know what happens while coding and debugging as well.
3. Sending the return value as a broadcast intent and the caller catch it. I remember the sound volume changing is broadcasted everytime.

Unfortunately, I have no good examples but all of them should work because I had experiences to use them:)
 

Snurre

Well-known member
Yeah I think I know what you mean, but I think it will start the first macro again and not just continue from where it was called
Or am I wrong?
 

Ray_Johnson

New member
Yeah I think I know what you mean, but I think it will start the first macro again and not just continue from where it was called
Or am I wrong?
Did you try to set the 'Wait until return' option whey you call the 'slave' macro from your main macro?
What happens when you set this?
 

tanutanu

Well-known member
Yeah I think I know what you mean, but I think it will start the first macro again and not just continue from where it was called
Or am I wrong?
When you use Wait until action, the caller macro waiting until another finished or cancelled *EDITED*the condition is fulfilled. you can return to the next statement of the caller and resume it:) It's definitely helpful๐Ÿ‘
In this case, don't add Macrodroid variable change as a trigger, put it into Wait until action like this(when expect 1-100 for the return value).
 

Attachments

  • IMG_20211117_231933.jpg
    IMG_20211117_231933.jpg
    249.6 KB · Views: 23
Last edited:

tanutanu

Well-known member
Wow, this works for me ๐Ÿ‘

I've just made 3 macro's for testing and runs pefectly (for now ๐Ÿคž) without any variables
View attachment 1592View attachment 1593
View attachment 1594

Thx guys ๐Ÿ˜Š
It's ok if you don't need any return values:)

Either you need or not, the colled macro works as "semi-parallel" executable subroutine.
Once you call the function-ish macro, by Run macro action, it starts proceeding immediately, and progress till a statement which has the context to wait, cancel or finish. On the breaking time, MD main process switches the current executive target back to caller macro(or 3rd, 4th... macros).
So it doesn't guarantee it finished what you want to do in the subroutine. In some cases, you can't avoid to place wait actions before you get the final result of the subroutine, i.e. it contains UI interaction, replace_all to long text, too many loops or so. You need to mind their dependency carefully while running semi-asynchronously when you didn't ticked Wait to complete... option. It might cause an unexpected behavior.
 

Snurre

Well-known member
In this particular situation I don't need a return value, but I can see what you mean and I'm using the Wait to complete
I have some other plans about these functions so you gave me some ideas to fool around with ๐Ÿ˜‰
 

tanutanu

Well-known member
In this particular situation I don't need a return value, but I can see what you mean and I'm using the Wait to complete
I have some other plans about these functions so you gave me some ideas to fool around with ๐Ÿ˜‰
haha, give me one more beer when we're gonna achieve something in future;)
I'd like to drink Togo beer. I remember it is made in one of nordic countries :unsure:
 

Snurre

Well-known member
Thats a deal ๐Ÿป
But I've never heard of Togo beer, the only Thing I know about Togo, is that it's a country in westafrica ๐Ÿ™‚
But ok, they might have good beer there ๐Ÿคฃ
 

Snurre

Well-known member
ใ‚ใ‹ใ‚Šใพใ—ใŸใ€ใใ‚Œใชใ‚‰็งใฏ๐Ÿ˜‰ใจไธ€็ท’ใงใ™ใŒใ€ใใฎๅๅ‰ใฎๅŒ—ๆฌงใƒ“ใƒผใƒซใ‚’็Ÿฅใ‚Šใพใ›ใ‚“๐Ÿคฃ
Just trying google translate๐Ÿ˜‰
 
Last edited:

tanutanu

Well-known member
ใ‚ใ‹ใ‚Šใพใ—ใŸใ€ใใ‚Œใชใ‚‰็งใฏ๐Ÿ˜‰ใจไธ€็ท’ใงใ™ใŒใ€ใใฎๅๅ‰ใฎๅŒ—ๆฌงใƒ“ใƒผใƒซใ‚’็Ÿฅใ‚Šใพใ›ใ‚“๐Ÿคฃ
Just trying google translate๐Ÿ˜‰
I googled it, seems former Finnish beer brewed in 70's:unsure:
It revived and is brewed in Japan now๐Ÿ™ƒ So It's very easy for me to buy it...
I need to translate what the crazy Google translator said:ROFLMAO: and I can never get what you mean exactly๐Ÿคช
 

Attachments

  • IMG_20211118_224356.jpg
    IMG_20211118_224356.jpg
    222.1 KB · Views: 1

Snurre

Well-known member
Yeah google translate succes, I think I'll stick with english ๐Ÿ˜‰
I was just trying to say "Ok I got what you mean" ๐Ÿ™‚
But I did found out that Togo was one of your great war heroes ๐Ÿ‘
So, when the beer is so easy to by in Japan then you could bring me one when you come to Denmark for a Tuborg Christmas beer ๐Ÿคช๐Ÿคฃ
 
Top