Play folder with right button with iTunes

automatoritunesscript

This answer to Play folder with right button with VLC explains how playing all the audio tracks within a folder can be accomplished when using VLC.

I don't want to install VLC, how can I accomplish something similar with iTunes?

Best Answer

In Automator app, create a new quick action. Select the option “folders” for the item “workflow receives current” and select Finder app as your choice for the application to run this service with.

Next, add an AppleScript action to your workflow and insert this following AppleScript code into that new action.

property nameExtensions : {"mp3", "wav", "aiff", "m4a"}
on run {input, parameters}
    set thisFolder to input as string
    set newPlaylist to {}

    tell application "System Events"
        set theseFiles to every file of folder thisFolder
        set folderName to name of folder thisFolder
    end tell

    repeat with i from 1 to the count of theseFiles
        set thisFile to item i of theseFiles
        tell application "System Events"
            if name extension of thisFile is in nameExtensions then
                set thisFile to thisFile as alias
                set end of newPlaylist to thisFile
            end if
        end tell
    end repeat

    tell application "iTunes"
        set newPlaylist1 to make new playlist with properties {name:folderName}
        add newPlaylist to newPlaylist1
        play newPlaylist1
    end tell
end run

enter image description here

You can save your Automator file now and name it something like “Play in iTunes”

Now all you need to do is right-click on any folder containing your audio files that you want to be played in iTunes, and select the menu item item “Quick Action” / “Play in iTunes”

enter image description here

This will create a new playlist in iTunes with the name of the folder containing your audio files and will start playing that playlist immediately.

If you don't want that playlist to be permanent and you want to remove the files after listening to them… sounds like a good little project to get your feet wet with by adding an additional code that will do that for you.

As a side note, you may need to add more audio file formats to the first line in the AppleScript code.

Anyway I think this is all a good starting point for you