Binary Copy

Why won’t a simple cp command in shell work for you?

because I’ve had to re-write my app for Mavericks, and now I’m going to have to re-write it for Yosamite. All i want to do is have an app that isn’t going to need to be updated every time a new OS comes out.

Is there any way you can think of Tim, that i can fire the first request off, then once its finished fire the one underneath?

Thanks

Why did you have to rewrite the app? cp hasn’t changed in forever. You mentioned AppleScript, but that is totally unnecessary.

I used AppleScript to push a variable to terminal which had the cp command in it

The thing is you need a controller class, e.g. a window. This one starts the copy process. It runs asynchronously. So you need to check the state change event in the plugin class and react on the changes. If first copy is done, you can start second one.

you can use cp with Shell class.

Surely that would need to be a timer?

You can execute cp directly in a Shell.

dim s as string = “cp /some/file/path /some/other/path”
dim sh as new Shell
sh.mode= 1 // async
sh.Execute(s)

Hey Tim I really appreciate the above. But I also want to build in a progress bar etc, which I cannot do with cp

a timer would be okay. You could check regularly if it’s done and than do the next thing.
But you will need the status changed event to update progress bar, I think.

[quote=103565:@Jay maxted]Ive found this……
[/quote]

  // This method employs binarystreams to copy FromFile to ToFile
  
  dim FromStream, ToStream as BinaryStream
  
  // Open the streams up
  FromStream = FromFile.OpenAsBinaryFile(false)
  ToStream = ToFile.CreateBinaryFile("")
  
  // Copy the data from one stream to another
  while not FromStream.EOF
    ToStream.Write(FromStream.Read(1024))
    // update a progress variable here that a timer can use to update a progressbar
  wend
  
  // Close the streams
  FromStream.Close()
  ToStream.Close()

There are a lot of different ways to package this up into a self-contained unit. There are several example projects to look at:
Examples -> Desktop -> Threading -> ThreadingExample
Examples -> Desktop -> UpdatingUIFromThread -> UIThreadingWithTask
Examples -> Desktop -> UpdatingUIFromThread -> UIThreadingWithTimer

Can close this off now.

I created 2 timers one runs watching items, and the other works as a process watcher.

Timer 1 looks for a text field input and runs other times depending on what is returned by an action. The process watcher then picks up when item are finished, changes items and then restarts Timer 1

Whole thing works i a nice loop with no issues

[quote=103735:@Tim Hare]You can execute cp directly in a Shell.

[/quote]

For some reason, some people want to reinvent the wheel instead of using what the system provides :wink: