Efficiently coding lifehacks with AI

Efficiently coding lifehacks with AI

In my time coaching and mentoring, I have had occasions to make the case for doing work upfront to save 10x work/time/money/frustration down the road. Recently I had a personal example that I thought I would share.

Over the years, I’ve amassed quite a collection of music. In the days before streaming, I used to enjoy cataloging and organizing my collection using tools like MusicBrainz Picard. However, one task that I do not enjoy is organizing files. As such, I often leave this task to whatever music database software I’m using (which has been MusicBee for a long time now).

No software program is perfect and I’ve had my share of frustrations with them all, including MusicBee. One of the biggest issues I had involved its file auto-organization. Somewhere along the way, it screwed up and put 5,000 or so album folders into an artist folder called “Unknown.” Considering my penchant for keeping things organized, this really irked me. Then one day I was trying to find an album and couldn’t because it had been dumped into the “Unknown.”

Being fed up with this issue, I decided to finally do something about it. I already use an alternate file explorer for windows called Directory Opus (aka dopus). One of the features of Dopus that is really great, but eluded me in the past, is its scripting functionality. This feature allows users to build their own custom functionality which greatly enhances the possibilities for efficiencies in everyday file management.

With the advent of AI, I am now empowered to code scripts and built my own efficiencies and save myself time. Using my Sider.ai account, I was able to utilize the Claude Sonnet 4 Think model (with web searching capabilities) to build a complete script to handle organizing my “Unknown” mess—a task I never would have had the time for otherwise. Once tested, I was able to, with the touch of a few buttons, completely organize all 5,000 folders in the background while I did other work.

While it did take me a little bit to get the code working the way I wanted it, it took a lot less time than trying to manually complete that task. And this is just a personal example. Imagine the efficiencies to be found at school or in the workplace. Examples like this are why AI is such a game changer.

Below is the script I created completely using AI. The coding language is JScript, which I have zero experience with outside of this exercise. Feel free to use this code if you also are a music organizer and happen to use Directory Opus!

JavaScript
// ========================================================================
// Music Library Organizer for Directory Opus
// ========================================================================
// Created by: Berkeley Goodloe
// Last Updated: June 20, 2025
// Contact: [email protected]
// 
// This script was completely coded using Claude Sonnet 4 Think AI model
//
// DESCRIPTION:
// Automatically organizes music files into Artist\Album folder structure
// based on metadata. Works with selected files or folders containing music.
// Handles duplicates and cleans up empty source folders.
//
// NOTE: This script is designed to ignore non-music files in the source 
// folder and delete the folder anyways. This means files like folder.jpg
// will be casualties if not backed up elsewhere.
//
//
// CONFIGURATION:
// *** EDIT THIS LINE TO CHANGE YOUR MUSIC LIBRARY PATH ***
// Change "F:\\music" below to your desired music library location
// ========================================================================

function OnClick(clickData) {
    var cmd = clickData.func.command;
    var tab = clickData.func.sourcetab;
    var fsu = DOpus.FSUtil;
    
    // *** CHANGE THIS PATH TO YOUR MUSIC LIBRARY LOCATION ***
    var baseDir = "F:\\music";
    
    var sourceFolders = DOpus.Create.Vector();
    var processedFiles = 0;
    var movedFiles = 0;
    var deletedDuplicates = 0;
    var skippedFiles = 0;
    
    var filesToProcess = DOpus.Create.Vector();
    var processedPaths = DOpus.Create.Vector();
    
    // Process selected directories
    for (var e = new Enumerator(tab.selected_dirs); !e.atEnd(); e.moveNext()) {
        var folder = e.item();
        CollectMusicFilesWithDupeCheck(folder.realpath, filesToProcess, processedPaths);
    }
    
    // Process selected individual files
    for (var e = new Enumerator(tab.selected_files); !e.atEnd(); e.moveNext()) {
        var file = e.item();
        if (IsMusic(file.name)) {
            var filePath = String(file.realpath);
            if (!VectorContains(processedPaths, filePath)) {
                filesToProcess.push_back(file);
                processedPaths.push_back(filePath);
            }
        }
    }
    
    // Process all collected files
    for (var i = 0; i < filesToProcess.count; i++) {
        var file = filesToProcess(i);
        processedFiles++;
        
        try {
            var fileMeta = file.metadata;
            
            if (fileMeta != "none" && fileMeta.audio) {
                var audioMeta = fileMeta.audio;
                
                var albumArtist = audioMeta.mp3albumartist || audioMeta.mp3artist || "";
                var album = audioMeta.mp3album || "";
                
                albumArtist = CleanFolderName(String(albumArtist));
                album = CleanFolderName(String(album));
                
                if (albumArtist != "" && album != "") {
                    var artistDir = baseDir + "\\" + albumArtist;
                    var albumDir = artistDir + "\\" + album;
                    var destFile = albumDir + "\\" + file.name;
                    
                    if (!fsu.Exists(artistDir)) {
                        cmd.RunCommand("CreateFolder \"" + artistDir + "\"");
                    }
                    if (!fsu.Exists(albumDir)) {
                        cmd.RunCommand("CreateFolder \"" + albumDir + "\"");
                    }
                    
                    if (fsu.Exists(destFile)) {
                        cmd.RunCommand("Delete \"" + file.realpath + "\" QUIET");
                        DOpus.Output("Deleted duplicate: " + file.name + " (already exists in " + albumArtist + "\\" + album + ")");
                        deletedDuplicates++;
                    } else {
                        cmd.RunCommand("Copy MOVE \"" + file.realpath + "\" TO \"" + albumDir + "\"");
                        DOpus.Output("Moved: " + file.name + " -> " + albumArtist + "\\" + album);
                        movedFiles++;
                    }
                    
                    var sourceFolder = String(file.path);
                    if (!VectorContains(sourceFolders, sourceFolder)) {
                        sourceFolders.push_back(sourceFolder);
                    }
                    
                } else {
                    DOpus.Output("Skipped (missing metadata): " + file.name + " [Artist: '" + albumArtist + "', Album: '" + album + "']");
                    skippedFiles++;
                }
            } else {
                DOpus.Output("Skipped (no audio metadata): " + file.name);
                skippedFiles++;
            }
        } catch (e) {
            DOpus.Output("Error processing " + file.name + ": " + e.message);
            skippedFiles++;
        }
    }
    
    // Clean up empty source folders
    if (sourceFolders.count > 0) {
        DOpus.Output("--- Cleaning up source folders ---");
        for (var i = 0; i < sourceFolders.count; i++) {
            var sourceFolder = sourceFolders(i);
            try {
                if (!FolderHasAudioFiles(sourceFolder)) {
                    cmd.RunCommand("Delete \"" + sourceFolder + "\" QUIET");
                    DOpus.Output("Deleted source folder: " + sourceFolder);
                } else {
                    DOpus.Output("Source folder still contains audio files: " + sourceFolder);
                }
            } catch (e) {
                DOpus.Output("Error deleting source folder " + sourceFolder + ": " + e.message);
            }
        }
    }
    
    DOpus.Output("--- SUMMARY ---");
    DOpus.Output("Processed: " + processedFiles + " music files");
    DOpus.Output("Moved: " + movedFiles + " files");
    DOpus.Output("Deleted duplicates: " + deletedDuplicates + " files");
    DOpus.Output("Skipped: " + skippedFiles + " files");
    
    cmd.RunCommand("Go REFRESH");
}

function CollectMusicFilesWithDupeCheck(folderPath, fileVector, pathVector) {
    try {
        var folderEnum = DOpus.FSUtil.ReadDir(folderPath);
        
        while (!folderEnum.complete) {
            var item = folderEnum.next;
            if (item && !item.is_dir && IsMusic(item.name)) {
                var fullPath = folderPath + "\\" + item.name;
                var fileItem = DOpus.FSUtil.GetItem(fullPath);
                if (fileItem) {
                    var filePath = String(fileItem.realpath);
                    if (!VectorContains(pathVector, filePath)) {
                        fileVector.push_back(fileItem);
                        pathVector.push_back(filePath);
                    }
                }
            }
        }
        
        folderEnum.Close();
    } catch (e) {
        DOpus.Output("Error collecting files from folder " + folderPath + ": " + e.message);
    }
}

function VectorContains(vector, value) {
    for (var i = 0; i < vector.count; i++) {
        if (vector(i) == value) {
            return true;
        }
    }
    return false;
}

function FolderHasAudioFiles(folderPath) {
    try {
        var folderEnum = DOpus.FSUtil.ReadDir(folderPath, false);
        
        while (!folderEnum.complete) {
            var folderItem = folderEnum.next;
            if (!folderItem.is_dir && IsMusic(folderItem.name)) {
                return true;
            }
        }
        
        return false;
        
    } catch (e) {
        DOpus.Output("Error checking folder contents: " + e.message);
        return true;
    }
}

function IsMusic(filename) {
    var ext = filename.substr(filename.lastIndexOf('.') + 1).toLowerCase();
    return (ext == "mp3" || ext == "flac" || ext == "m4a" || ext == "wma" || ext == "ogg" || ext == "wav");
}

function CleanFolderName(name) {
    if (!name || name == "undefined") return "";
    
    name = name.replace(/[<>:"/\\|?*]/g, "_");
    name = name.replace(/^[\s.]+|[\s.]+$/g, "");
    
    return name;
}

Welcome

headshot portrait of Berkeley Goodloe

This is the personal homepage of
T. Berkeley Goodloe, where you’ll find writings on various current topics that I’m encountering, experiencing, or working on. This includes productivity, student success, and my attempts to analogize modular synthesis into everyday life.

Let’s connect