Action to close/restart an app and power off the device

cska133

Member
Remember UI actions automate the actions you perform manually.
Oh, what does this mean? UI actions automate my manual actions, is that what you mean? In this case they will automate my manual actions for how I power off the device?
 

cska133

Member
It also works on the locked screen.

The attached macro powers off the phone when the screen has been off for 3 hours.

Wether the macro will work will depend on the phone/tablet and android version.

The macro works on my Sony 5v on Android 14.
Hi,

Ok my tablet seems to be able to show Power options when screen off and locked. But where to find [Power Off] when i choose UI Interaction -> Click? The Click options are On actual Focus/Text/XY/Application/ID ?!
 
Last edited:

dhj49er

Well-known member
Hi,

Ok my tablet seems to be able to show Power options when screen off and locked. But where to find [Power Off] when i choose UI Interaction -> Click? The Click options are On actual Focus/Text/XY/Application/ID ?!
You shouldn't be looking in UI interaction for power off.
When power options are on the screen what do you manually to power off?
 

cska133

Member
When power options are on the screen what do you manually to power off?
I click on PowerOff. There are some more power option listed, so i choose PowerOff. When executing the macro, the power options are displayed . Is that wrong?
 
Last edited:

cska133

Member
Here it is.
For testing I set the time delay to 10sec.
In relation to the triggers in your macro i made lokal variable "PowerOff" set to true and then to false (see 2. screenshot at the bottom). But the Value Type i used was "boolean", is that right?
In the UI Interaction->Click I just wrote "power off", because I dont find power off entry option to choose.. The Click options I have are on the 3. Secreenshot.

thanks

PS:
On my tablet when screen is off I have to long press the power button and then the screen goes on and the power options are shown without unlocking the lock screen. Maybe this should be changed in the macro? although when i start the above macro screen goes on and the power option are shown, but no further action (=no Click on PowerOff)
 

Attachments

  • 20240405_224539.jpg
    20240405_224539.jpg
    967.9 KB · Views: 9
  • 20240405_224555.jpg
    20240405_224555.jpg
    999.4 KB · Views: 9
  • 20240405_230006.jpg
    20240405_230006.jpg
    2.2 MB · Views: 9
Last edited:

Qarboz

Well-known member
Any idea?
Try to use X-Y coordinate.
To find them you can use a crude but functional method.
Cover the screen with a transparent film, e.g., the one for food; press the button to show the power off menu; with a marker mark the area of the power off button; exit the power off menu; in MacroDroid, in the UI interaction action select XY, in the coordinate entry window click on "Toggle touch location overlay" (the coordinates are shown at the top); tap inside the area you marked with the marker and look at the coordinate values you need to enter.
Note that the coordinates are only valid if the screen is in the same orientation as when you acquired them (portrait or landscape); to work around macro malfunctions, before showing the shutdown menu with an action you can force the screen into the correct orientation, and after the click restore the automatic orientation (possibly add a short delay before the latter action)
 

cska133

Member
thanks you, it sounds hopeful, i will try it.

But just for my knowledge: I often read in the forum here about following action UI interaction->click->poweroff. Since i can not find poweroff after selecting UI interaction and then Click, how can this action be implemented in macros? What am I doing or understanding wrong?
 

Qarboz

Well-known member
But just for my knowledge: I often read in the forum here about following action UI interaction->click->poweroff. Since i can not find poweroff after selecting UI interaction and then Click, how can this action be implemented in macros? What am I doing or understanding wrong?
Android device manufacturers customize the operating system to their liking.
E.g. instead of poweroff it could be power[space]off, or turn off, or use word(s) in the language of the device (e.g. Spegni in Italian)
 

dhj49er

Well-known member
thanks you, it sounds hopeful, i will try it.

But just for my knowledge: I often read in the forum here about following action UI interaction->click->poweroff. Since i can not find poweroff after selecting UI interaction and then Click, how can this action be implemented in macros? What am I doing or understanding wrong?
I don't think you fully understand what a UI interaction is.

A good place to get basic information is the MD wiki.

Ui interaction>click>power off

This refers to a Click type UI interaction action.

On selecting click a drop down menu will appear. This contains the different types of click action. Select the one labelled text. In the next screen type in power off.

When the macro runs, the action will perform a click on the specified text.

You need to ensure that the correct screen is displayed before the UI click action is run.

It's worth spending time to familiarise yourself with the basics. Then you'll be able to try different actions and know what to change if they don't do what you want.
 

Dm114

Well-known member
I don't think you fully understand what a UI interaction is.

A good place to get basic information is the MD wiki.

Ui interaction>click>power off

This refers to a Click type UI interaction action.

On selecting click a drop down menu will appear. This contains the different types of click action. Select the one labelled text. In the next screen type in power off.

When the macro runs, the action will perform a click on the specified text.

You need to ensure that the correct screen is displayed before the UI click action is run.

It's worth spending time to familiarise yourself with the basics. Then you'll be able to try different actions and know what to change if they don't do what you want.
👏👏

As text recognition doesn't always work, it sometimes worth using (x,y) coordinates... The inconvenience is that coordinates depend on device (orientation and model): nothing is perfect! 😉😀
 

cska133

Member
Android device manufacturers customize the operating system to their liking.
E.g. instead of poweroff it could be power[space]off, or turn off, or use word(s) in the language of the device (e.g. Spegni in Italian)
Sure but on the power options popup i see what the text of the power off button is. So if the language is also importent , in my case i use German as system language and the poweroff button is called "ausschalten". So i should type in "ausschalten" , right?
Or you mean the text could not be that what i see?


On selecting click a drop down menu will appear. This contains the different types of click action. Select the one labelled text. In the next screen type in power off.
I do understand what the UI Interaction is, but yes I was thinking that after selecting Click there will be options to select poweroff. But as i already wrote earlier I understood that there is no such direct option to choose poweroff. Thats way my question was how to provide poweroff. I still have to test the XY coordinations.
But anyway still back to what you wrote @dhj49er . After choosing UI Interaction->Click there are options provided: (translation from German) Text content/XY location/identify in Application / view ID. @dhj49er you wrote:
Select the one labelled text
What do you mean with "the one labelled text"? Is that the text content option? If I choose Click->text content I get following popup (see screenshot). Should I type in here "Power off"?
@Qarboz Respectively is it where you ment I have to know the exact text (language importent) of the button and type it in on this place? In my case poweroff in German is "ausschalten" what i have to type in?
 

Attachments

  • Screenshot_20240409-093626_MacroDroid.jpg
    Screenshot_20240409-093626_MacroDroid.jpg
    79.7 KB · Views: 3

dhj49er

Well-known member
Thanks for the answer, i will try this.

Related to the macro example of @dhj49er in answer #32 https://www.macrodroidforum.com/ind...-app-and-power-off-the-device.6358/post-38555 I created local variable PowerOff with Type "boolean", is that correct? Or it should be integer or string or else?
The clue is in the set variable action

Set PowerOff True

Integer variables are whole numbers
String variables are text.
Boolean variable, as the name suggests, have 2 states, True and False.

I urge you to look up the basics on the MD Wiki.
 

Dimlos

Well-known member
@cska133
If I upload a macro, can I import and run it?
Does it turn off immediately after pressing ausschalten? Or does another message appear?
 
Last edited:

Dimlos

Well-known member
Try this macro.
If you see another message after pressing ausschalten, please edit it.
 

Attachments

  • Macro.jpg
    Macro.jpg
    430 KB · Views: 7
  • Power_Off.macro
    1.9 KB · Views: 0
Top