Skip to main content
Commonmark migration
Source Link

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][1]][1]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. [1]: https://i.sstatic.net/R5fCm.jpg

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][1]][1]

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. [1]: https://i.sstatic.net/R5fCm.jpg

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.

Source Link
CJK
  • 5.6k
  • 9
  • 19

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][1]][1]

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. [1]: https://i.sstatic.net/R5fCm.jpg