Page 1 of 1

Copying files

Posted: Wed Nov 26, 2008 6:32 pm
by Tommy
I am wasting way too much time trying to do something relatively simple in RunRev. It's partially my own fault, as I'm coming from a procedural background. But I'm wasting hours figuring out single lines of code. But I was slowly making progress.

But now I'm stuck. All I'm trying to do is take screenshots at regular intervals, compare them to the previous shot and upload them to an FTP site when the screen changes. (It took me hours to realize I could just compare files by saying:

Code: Select all

if (URL "thisURL" = URL "thatURL") then
Couldn't find anything about it on the site or in the User Guide.)

Anyway, I'm stuck because every time I try to copy the current shot over the baseline shot, the current shot gets renamed. In other words, if I do this:

Code: Select all

revCopyFile $HOME & "/snapshot0.jpg", $HOME & "/Baseline.jpg"
"snapshot0.jpg" gets renamed to "snapshot0 2.jpg" as the file gets copied.

Is this an AppleScript thing? Am I just doing something wrong? Copying a file should never change the source file, should it?

Posted: Wed Nov 26, 2008 8:04 pm
by Klaus
Hi Tommy,

yes "revcopyfile" uses AppleScript on the Mac, so the renaming thing is surely an AppleScript issue.

If you really want just to replace/overwrite the target file you could use:

1. shell -> "cp" or "ditto" or whatever
2. Or if the files are not too big a simple:

Code: Select all

put url("binfile:" $HOME & "/snapshot0.jpg") into url("binfile:" & $HOME & "/Baseline.jpg")
might do :-)


Best from germany

Klaus

Posted: Wed Nov 26, 2008 8:08 pm
by bn
Tommy,
revCopyFile $HOME & "/snapshot0.jpg", $HOME & "/Baseline.jpg"
behaves just the same for me as you describe, the file snapshot0.jpg is renamed to snapshot0 2.jpg.

However your syntax is not ok. Revcopy wants a full path to a file including the filename in the first argument and a path to a FOLDER as the second argument.
You give it a full path to a differently named file in the same directory.
Somehow this renames the original file the way you see it.

Try using a valid path to a different folder and that is what works for me.

if you want to check, wether a file of that name exists you might want to check for

Code: Select all

if there is a file "fullPath&NameOfFile" then
you could then rename your original file with a numeric increment until you get a filenname that does not exists at the destination.
If you dont check prior to recopyfile if the file already exists at that location it will increment the way you observed it but will not rename the original file as you have seen in your original syntax.
hope this helps
Bernd[/b]

Posted: Wed Nov 26, 2008 9:00 pm
by Tommy
Thanks for the help so far!

I'm trying to stay away from shell commands, as I'm going to be running it on both Os X and Windows (and maybe Linux).

The files are less than a meg so putting URL objects shouldn't be a major problem.

I guess the easiest thing is to delete the existing destination file before doing the copy.

Although, under OS X, AppleScript makes that "file copied" sound effect. (I suspect it would do the same when called via the shell.) So maybe just putting URLs is the best choice.

On a related note, is there a different way of comparing files, other than comparing them as URL objects? Windows' shell command for comparing files doesn't really return anything useful to a program.

Posted: Thu Nov 27, 2008 6:57 am
by Obleo
I use shell scripts often and the "cp(1)" command does not use any sound effects from shell. The only one that I know even giving an option of a sound effects is screencapture. (This is thought man page sectors 1-9 and n)

The unix (darwin /OSX and linux) shells are the same for "cp".

Posted: Thu Nov 27, 2008 8:32 pm
by Tommy
Obleo wrote:I use shell scripts often and the "cp(1)" command does not use any sound effects from shell.
Yeah. I should have realized that. Thanks.