The attached macro picks a file at random from a folder, then plays it (assuming it's a media file). You could add whatever trigger you like to it.
Note that you'll need to update:
- the value of the music_folder local variable, to be the folder from which you want to pick a random file
- the value of the writeable_folder local variable, to be a folder that MacroDroid can write to (later versions of Android are very picky about which folders apps can write to; the Documents folder seems to work)
If you wanted another app to play the music file (e.g. PowerAmp, or YouTube Music, or Spotify, etc.), you'd want to replace the last set of actions with whatever your app needs (presumably a
Send Intent action of some sort). You could get rid of the
writeable_folder local variable in that case, as well.