Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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.

So here's my solution. In the script, when I detect a rar, I first verify it for completeness:

do shell script ("unrar v " & theItem)

The shell will spit out, among other things, this:

… Testing archive thefile.r19 96% … Testing archive thefile.r20 99% ... Calculating control sums of all volumes. Cannot find volume thefile.r21 … thefile.avi - CRC failed Total errors: 1

I'm new to AppleScript. What's the most efficient way to scan through that and determine if the verification has failed?

(Alternatively, unrar v is time consuming; is there any better way to approach this problem?)

share|improve this question

1 Answer 1

up vote 1 down vote accepted

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.

share|improve this answer
    
Since a compressed file can consist of any number of partial RARs, you can't use the file extension to check if they're all there. But thankyou for the AppleScript help. I didn't know about "contains". –  Matthew Robertson Nov 8 '09 at 23:32
    
@Matthew Robertson: Since they contain .r[0-9]+ it could be possible as Applescript does support regular expressions using the find command but it's something I've never personally used so I don't have a useful sample. (yet?) –  Chealion Nov 9 '09 at 7:26
    
Hmmm. I could make an array of the filenames, get the highest one (say, .r20) and check whether they sequentially decrease to r01. (Although there's one scenario where r01 to r20 have been downloaded and we're waiting for r21.) I'll toy with it. Cheers. –  Matthew Robertson Nov 9 '09 at 8:53

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.