This repository has been archived by the owner on Jan 25, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
randomize.sh
63 lines (52 loc) · 1.44 KB
/
randomize.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/bin/bash
clear
# setting colours to beautify messages
green='\033[0;32m'
nocol='\033[0m'
# store all music files in an array, then sort it randomly
contents=(~/Music/*)
IFS=$'\n' random=($(sort -R <<< "${contents[*]}"))
unset IFS
# number of tracks to be played
# which is the number of elements in the array
size=${#random[@]}
# number of digits in the variable 'size'
# used to format information messages
length=${#size}
# display the order in which the tracks will be played
count=1
echo -e "${green}The tracks will be played in the following order.${nocol}"
for item in ${random[@]}; do
printf "%*d\t" $length $count
echo $(basename ${item%.*})
count=$(($count+1))
done
echo
# play tracks in that order
count=1
for item in ${random[@]}; do
# send a desktop notification to tell
# which track is currently playing
# no idea why this works
# I copied it from the code for a program called 'undistract-me'
notify=$(command -v notify-send)
if [ -x "$notify" ]; then
$notify \
-i dialog-information \
-u low \
"$count" \
"$(basename ${item%.*})"
else
echo -en "\a"
fi
# display the same information on the Terminal
echo -en "${green}"
printf "now playing %*d of %*d" $length $count $length $size
echo -e "${nocol}\t$(basename ${item%.*})"
# display the PID of this script for kicks
echo -e "${green}process ID: $$${nocol}"
# open VLC without interface and play one track
cvlc --play-and-exit $item
count=$(($count+1))
clear
done