1
votes

I have created a small applescript that looks for files that match multiple strings in a certain folder, and when they are found, it returns the path to that file. in applescript language, it looks like this:

set filesExist to path of (every file in folder pathUnsorted whose name starts with (item 1 of theWords) and name contains (item 2 of theWords) and name contains (item 3 of theWords) and name contains (item 4 of theWords) and name contains (item 5 of theWords))

now, I need to convert this to a shell command, since those can run inside applescript with this command:

set filesExist to do shell script "(shell command goes here)"

Unfortunately I have no idea how to do it in a shell command...can someone help me??

1
Why use a shell command inside of applescript rather than regular applescript commands? What benefit could you get from this? Please explain what you need to achieve and we can help you achieve it. - regulus6633
Mostly Speed. when I have to look for a file and there are 1500 other files it can take a really long time. After searching on google I found out I could use System events to do the searching, but it also proves to be too slow. it was suggested that shell could be a lot faster - ruben1691
Good point! A Finder search through a large amount of files is slow. - regulus6633

1 Answers

1
votes

Assuming that pathUnsorted is already a POSIX path:

do shell script "ls " & quoted form of (pathUnsorted & "/" & (item 1 of theWords)) & "*" & ¬
    " | grep " & quoted form of (item 2 of theWords) & ¬
    " | grep " & quoted form of (item 3 of theWords) & ¬
    " | grep " & quoted form of (item 4 of theWords) & ¬
    " | grep " & quoted form of (item 5 of theWords)

It’s theoretically possible to construct a regular expression that would match all the right files in one shot, but this is simpler.