ruben1691
ruben1691

Reputation: 423

applescript to shell

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??

Upvotes: 1

Views: 170

Answers (1)

Chris N
Chris N

Reputation: 949

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.

Upvotes: 1

Related Questions