3

I have a workflow that gets the track name of a single track in my mp3 player and stores it in a variable. I then use this in the Spotlight action to find that track in my iTunes Library, but the Spotlight action gives multiple results when I want only want the exact track not all tracks that contains the name.

I need some way or a script to replace this action. All searches gives Terminal commands that I don't understand or how to use with Automator.

enter image description here

Here's an applescript I found that works but is really really slow, it beach-balls the Finder on every loop, Is there a way to speed this up,my library has over 10,000 tracks? thanks https://www.dropbox.com/s/o14eb19b2459vdo/by%20default%202018-07-19%20at%20Thursday%2C%2019%20Jul%20%2017.55.18.PNG?dl=0

3
  • 1
    Please upload your Automator workflow, or post links to screenshots of it. We need to see what you’re doing.
    – CJK
    Commented Jul 14, 2018 at 22:04
  • You look like you're running an older Mac system. Does your version of Automator have iTunes actions, specifically one called Find iTunes Tracks ?
    – CJK
    Commented Jul 15, 2018 at 7:15
  • Hi sorry for late reply, yes I'm using Snow leopard but I also have El Capitan, that iTunes action doesn't use variables either. The example given is not the worst, sometimes for a given track I'll get 6 to 10 results when the exact name of the track should give only 1 result.I'm simply trying to create a playlist from all the tracks on my mp3 player, which at the moment is 218 and all those tracks are in my library. I need to find only the the track I'm looking for. Commented Jul 16, 2018 at 15:43

1 Answer 1

1

I don't have Snow Leopard, so I'm limited in what I can test as being viable for your system. Therefore, please bear in mind that the following solution was devised and tested using the following:

System info: AppleScript version: "2.7", system version: "10.13.5"

With that said, I see now reason that this shouldn't work on El Capitan. It might work on Snow Leopard, but I'm less sure.

My proposed solution is to replace your Spotlight Automator action with a Run AppleScript action:

Automator Workflow

The code contained in the Run AppleScript is as follows:

    use framework "Foundation"
    
    property ca : a reference to current application
    
    
    on run {input, parameters}
        set MusicFolder to "/Volumes/Media/Music/iTunes/iTunes Music/Music/"
        
        set FileManager to ca's NSFileManager's defaultManager()
        set MusicFiles to (FileManager's subpathsAtPath:MusicFolder)'s ¬
            pathsMatchingExtensions:{"mp3", "m4a"}
        set [filename] to input
        set format to "SELF endswith " & ("/" & filename & ".mp3")'s quoted form & ¬
            " OR SELF endswith " & ("/" & filename & ".m4a")'s quoted form
        set filter to ca's NSPredicate's predicateWithFormat:format
        
        set matches to {}
        
        repeat with match in (MusicFiles's filteredArrayUsingPredicate:filter) #'
            set end of matches to POSIX file (MusicFolder & match as text) as alias
        end repeat
        
        return matches
    end run

This will return tracks with the exact filename supplied by the trackName variable in the workflow. Therefore, had I set trackName in my test run to "Everywhere I Go" (i.e. without the preceding "04"), the search would have returned an empty result.

Also, bear in mind that you may have some tracks that have identical filenames from different folders/albums. If there are two files in different folders both called "01 Song.mp3", both files will be returned in the search.

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .