Progress bar for copying files with NSApplescript?

Discussion in 'Mac Programming' started by pcwiz, Jul 29, 2009.

  1. macrumors member

    May 28, 2008

    I'm creating a program where one of the tasks is to copy thousands of files with root privileges. I know there is no easy way to perform file operations with root privileges using Objective C, so I decided to put the series of do shell script commands in an AppleScript script file:

    set filelist to {"file1", "file2", "file3", "etc"}
    repeat with i in filelist
    do shell script "cp -R " & i & " /destination_folder" with administrator priveleges
    end repeat

    Basically I feed it a list of files, then it does a loop and for each file in the list it does a copy operation using do shell script. I am going to invoke this script in my Objective C app using NSAppleScript. My question is, is it possible to put in a progress bar for the file copy procedure, assuming that I know the total number of files to be copied? This is easy to do in plain Objective C, but since the file copying is done in an AppleScript, I'm unsure of how im going to do this.

    Any help would be appreciated
  2. macrumors 601


    Jan 6, 2004
    Western US
    One way would be to just make the file copy line the AppleScript part and pull the looping out into Objective-C code and feed cp one file at a time. Then you can use Objective-C for all the the progress bar stuff. You'd probably want to make sure you wait for each copy to complete before starting the next one for the progress to be accurate, so I don't know how efficient it would be to do it that way.

    You could also do something like pipe the std output back to your app and use the verbose (-v) flag, then do some text parsing as it will print out a line as each file is copied.
  3. thread starter macrumors member

    May 28, 2008

Share This Page