Home » Questions » Computers [ Ask a new question ]

Applescript: Check if shell command fails?

Applescript: Check if shell command fails?

I'm writing an AppleScript to watch a folder for completed downloads, then process them. If I'm downloading a file split across partial RARs (.r01, .r02, … God I hate those), they'll enter the Completed folder randomly as they're completed. The script will trigger every time one of them is completed, but I don't want it to start to auto-unarchive until all of them are done.

Asked by: Guest | Views: 251
Total answers/comments: 1
Guest [Entry]

"If you change your code to:

set output to do shell script (""unrar v "" & theItem)

The variable output will hold the output of the shell script, which you could use to compare to what you are expecting for a valid output.

if output contains ""CRC Failed"" then
return
end if

For avoiding having to run unrar v you could implement a check on the file's extension (either when you set theItem in the AppleScript or perhaps in whichever method you're using to monitor the folder - if you've manually made the launchd job and not used Folder Actions)

For more info on do shell script check out Apple's Technical Note 2065."