Stuck in macro to search the Finder

Hello.
I’m stuck in a macro I started.
I want to search in Finder for a text string from a list in Excel.
I tried to do a Screen capture of the results to use it with the System Clipboards conditions, but it always will have an image whether Finder found results or not. (I tried also to explore using the CLIPBOARDSEED function but didn’t see how/if it can help me.)
Any help will be appreciated! Thanks!

Search in Finder for text from a list in XL Macro (v11.0.3)

Search in Finder for text from a list in XL.kmmacros (10 KB)

Are all the songs in a particular directory? What do you want to do with them if found?

Would it be worthwhile doing something like this in an Execute shell script action?

cd /Users/johnsmith/example/test/
find . -name "*foo*.mp3" -type f -exec ls "{}" \;

Save the result to a variable, and test whether it's empty, and if it's not... do whatever you want to do with each listed file.

(The hardwired directory and search pattern could of course be replaced by variables).

1 Like

Not a particular directory. I'm rebuilding my MBP after everything was erased completely. About 240 songs have the exclamation mark next to them (missing).
I connect my external hard disk. The search is done in my internal/external hard disks+iCloud.
If a song isn't found I go on to the next one in the XL list (I will find it later from my CDs or from a Dropbox back up), if found I double click it, It plays in my Music app and is added to my ~/Music folder.

Sorry Kevin. I wouldn't know how to do it.
If you could be so kind and elaborate a bit (something like explaining it to someone in 1st grade) :rofl: I would be happy to try.

Especially now that I have a better idea of what you are trying to do, I don't think my suggestion there would be the most efficient.

I think I might now approach it as follows:

  1. Export the Excel list as plain text.
  2. Copy the audio files to the Music folder.
  3. Generate a list of them (using ls in an Execute shell script action).
  4. Compare the two lists to see which files are missing.

However... I do not use iTunes/Music for this sort of library duty (I have been using Swinsian instead for a long time, so my memory of how Music does such things is not fresh – and even when I used iTunes as a music library I didn't have it set to copy files to the Music folder). Therefore I will not elaborate further because I think it likely that someone else who uses Music.app in the same way that you do will have a better idea of the ideal solution.

Regardless of the approach, though, I would want to handle the files in bulk as much as possible – not by copying from Excel and checking one at a time using the Finder.

That's not the problem. I know exactly which songs are missing (and this IS the Excel list; all the missing songs).
Actually, finding them is pretty easy:
1- Created a regular new playlist (Cmd+N) (Called it "Existing")
2- Created a smart playlist (Cmd+option+N) (Called it "Missing")
3- In the "Songs" playlist (where all the songs are) hit Cmd+A. Dragged all songs to the "Existing" playlist and all the missing are in the "Missing" playlist.

To go on with my macro I need to know how to tell KM when the search didn't find any songs (in contrast to when the results are populated).
It is not a big deal. I can do it manually of course, but then, this is the whole purpose of KM...

Comparing to:

Hi @Saul, on my Mac, I could tell when Finder returns a result:

  1. In Finder, search for the song. (Song is returned)
  2. Press tab twice, then down arrow. (Song should be selected in Finder)
  3. Finder menu, File > Get Info is enabled

Get Info is enabled if a song is selected
Get info is disabled if search did not find the song


Hope that helps.

ChrisQ

Hi Chris.
Thanks for trying.
When the search returns a song there is no problem, I just play it and it adds it to the library/Music app.
My problem is when there are no results. I was wondering if there is a way to tell KM that nothing was found.

You just need to check if the Finder menu, File > Get Info is enabled or not. Try this If then else action.

1 Like

Yes! It works!!! That's EXACTLY what I meant!!
Thanks for not giving up! :star_struck:
So simple, yet was so far away from me!!!
Thanks a lot! Have a wonderful night!!!

1 Like