Array question

ARME

Active member
Let's say I have an array which has stored the names of the apps I have. Is it possible that if I remove one of those app, its entry is removed from the array ?
 

Dm114

Well-known member
Let's say I have an array which has stored the names of the apps I have. Is it possible that if I remove one of those app, its entry is removed from the array ?
I would suggest either to create a macro to remove apps (physically and in your array) or re-populate a new array with remaining apps.
 

ARME

Active member
I would suggest either to create a macro to remove apps (physically and in your array) or re-populate a new array with remaining apps.
So is not possible to manually uninstall an app and the macro (using as trigger "application removed" to get the app name) removing it from the array ?
 

ARME

Active member
There is the "clear array" action but I don't know how to make it remove the entry of the apps I uninstall.
 

Endercraft

Moderator (& bug finder :D)
If you want to do it with an array, you'll have to iterate the whole array to find the key then delete it. If you want the array to not haven't a missing index then you should json output then json parse but it may only work fine with sub-arrays.
However it is easier with a dictionary.
I have 2 dictionaries of installed apps, dictionary[app name]=app package and one dictionary[app package]=app name.
This lets me choose the entry I want easily, for example to find the app name based on the app package and the other way around or delete the entry (dictionaries also don't have the problem of missing index).
 

ARME

Active member
If you want to do it with an array, you'll have to iterate the whole array to find the key then delete it. If you want the array to not haven't a missing index then you should json output then json parse but it may only work fine with sub-arrays.
However it is easier with a dictionary.
I have 2 dictionaries of installed apps, dictionary[app name]=app package and one dictionary[app package]=app name.
This lets me choose the entry I want easily, for example to find the app name based on the app package and the other way around or delete the entry (dictionaries also don't have the problem of missing index).
Pretending I have other apps in the dictionary, what's the formula I have to write in the "clear" action?
 

Attachments

  • Screenshot_2023-08-27-14-00-42-46_2e840d222d67ef3caca3a1c67d71d48f.jpg
    Screenshot_2023-08-27-14-00-42-46_2e840d222d67ef3caca3a1c67d71d48f.jpg
    132 KB · Views: 10
  • Screenshot_2023-08-27-14-01-34-62_2e840d222d67ef3caca3a1c67d71d48f.jpg
    Screenshot_2023-08-27-14-01-34-62_2e840d222d67ef3caca3a1c67d71d48f.jpg
    406.5 KB · Views: 10

Endercraft

Moderator (& bug finder :D)
Iit seems you can only use the app package magic text with uninstall (so [[app_package]]), so you have to do it this way.
 

ARME

Active member
Still don't understand what I'm doing wrong
 

Attachments

  • Remove_app_from_dictionary.macro
    2 KB · Views: 4

Dm114

Well-known member
If you want to do it with an array, you'll have to iterate the whole array to find the key then delete it. If you want the array to not haven't a missing index then you should json output then json parse but it may only work fine with sub-arrays.
However it is easier with a dictionary.
I have 2 dictionaries of installed apps, dictionary[app name]=app package and one dictionary[app package]=app name.
This lets me choose the entry I want easily, for example to find the app name based on the app package and the other way around or delete the entry (dictionaries also don't have the problem of missing index).
Unfortunately MD Dictionaries are not (not yet?) real databases so we must have 2 of them to have a 2-entry system. As we generally don't deal with huge amounts of data, it's fully "philosophically" acceptable and... efficient. 😀
 

ARME

Active member
If you want to do it with an array, you'll have to iterate the whole array to find the key then delete it. If you want the array to not haven't a missing index then you should json output then json parse but it may only work fine with sub-arrays.
However it is easier with a dictionary.
I have 2 dictionaries of installed apps, dictionary[app name]=app package and one dictionary[app package]=app name.
This lets me choose the entry I want easily, for example to find the app name based on the app package and the other way around or delete the entry (dictionaries also don't have the problem of missing index).
What's the problem of missing index ? It's because you don't like when it's missing?
 

Quidn

Passionate Member
There is the "clear array" action but I don't know how to make it remove the entry of the apps I uninstall.
If you want to do it with an array, you'll have to iterate the whole array to find the key then delete it. If you want the array to not haven't a missing index then you should json output then json parse but it may only work fine with sub-arrays.
However it is easier with a dictionary.
I have 2 dictionaries of installed apps, dictionary[app name]=app package and one dictionary[app package]=app name.
This lets me choose the entry I want easily, for example to find the app name based on the app package and the other way around or delete the entry (dictionaries also don't have the problem of missing index).


If using array is necessary, it can be done like this, but not at all practical for this case. Using dictionary makes sense.


Q230907RemoveArrayItem-before.pngQ230907RemoveArrayItem-after.png
Q230907RemoveArrayItem.pngQ230907RemoveArrayItem-ablock.png
 

Attachments

  • Q230907RemoveArrayItem.macro
    7.1 KB · Views: 0

Quidn

Passionate Member
Unfortunately MD Dictionaries are not (not yet?) real databases so we must have 2 of them to have a 2-entry system. As we generally don't deal with huge amounts of data, it's fully "philosophically" acceptable and... efficient. 😀

Dictionary of MacroDroid is much like JSON which is similar to but not an object. (i.e., key-value dataset structure without characteristics of object)
So it isn't database as you said and in my opinion is isn't likely to be evolve to database, because both concept are too different.



What's the problem of missing index ? It's because you don't like when it's missing?

It might not be harmful directly but may causes unexpected result when processing.
If you want to keep using array, my Action Block above will prevent the problem.
 

ARME

Active member
Dictionary of MacroDroid is much like JSON which is similar to but not an object. (i.e., key-value dataset structure without characteristics of object)
So it isn't database as you said and in my opinion is isn't likely to be evolve to database, because both concept are too different.





It might not be harmful directly but may causes unexpected result when processing.
If you want to keep using array, my Action Block above will prevent the problem.
Ok thanks, I'll use dictionary then
 
Top