Skip to content

Instantly share code, notes, and snippets.

@mlabbe
Created July 3, 2025 17:22
Show Gist options
  • Select an option

  • Save mlabbe/f6799275140976b42ea9073f32f066a3 to your computer and use it in GitHub Desktop.

Select an option

Save mlabbe/f6799275140976b42ea9073f32f066a3 to your computer and use it in GitHub Desktop.
play random album
#!/usr/bin/env perl
use strict;
use warnings;
use utf8;
use File::Find;
use List::Util 'shuffle';
# config
my $music_dir = "$ENV{HOME}/Music/mp3s";
my $num_albums = 1;
my $vlc = "/Applications/VLC.app/Contents/MacOS/VLC";
if ($#ARGV >= 0) {
$num_albums = $ARGV[0];
}
# music
opendir(my $dh, $music_dir) or die "Can't open $music_dir: $!";
my @albums = grep {
-d "$music_dir/$_" && !/^\./
} readdir($dh);
closedir $dh;
@albums = shuffle(@albums);
@albums = @albums[0 .. $num_albums - 1] if @albums > $num_albums;
my @paths = map { "$music_dir/$_" } @albums;
my $args = join ' ', map { quotemeta($_) } @paths;
print "Playing album(s):\n";
foreach (@paths) {
print " $_\n";
}
exec "$vlc $args";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment