Hi:
I would like to use applescript to read and write binary files from old disks, if that is possible.
I need to read, say, 1024 bytes at a time from a file on cd and write it to a new file on hard drive, making a copy. However, if the process encounters 1024 bytes it can’t read because of a disk error, I would like to write 1024 "1"s to the new file, so that it ends up the same size on HD.
I don’t know anything about binary, so I hope that makes sense…
Any help appreciated,
guy o.
I don’t know if AppleScript can do this on its own, but your task can be accomplished in the shell, and done in AS with a ‘do shell script’
In OS 10.3.5 the command in the terminal would be:
dd conv=noerror bs=1024 if=/path/to/original/file of=/path/to/destination
You could wrap it in an AS if you wanted to with:
do shell script “dd conv=noerror bs=1024 if=/path/to/original/file of=/path/to/destination”
See man dd
in terminal for more options.
Andy
Hi Tugboat:
That sounds like exactly what I need, thanks!
Just so I understand, the bs=1024 ensures that the target file has the same number of bytes because noerror is also specified? And do you know if the result 1024 bytes all contain the same kind of padding – all ones or zeroes – or just whatever was on the target file’s HD? Or something else?
I can’t wait to try this thing in an AS wrapper like you supplied… I guess all of this file stuff has been implemented in unix forever…
Thanks again,
guy o.
From the man page:
bs=n Set both input and output block size to n bytes, superseding the
ibs and obs operands. If no conversion values other than
noerror, notrunc or sync are specified, then each input block is
copied to the output as a single block without any aggregation
of short blocks.
noerror Do not stop processing on an input error. When an
input error occurs, a diagnostic message followed by
the current input and output block counts will be writ-
ten to the standard error output in the same format as
the standard completion message. If the sync conver-
sion is also specified, any missing input data will be
replaced with NUL bytes (or with spaces if a block ori-
ented conversion value was specified) and processed as
a normal input buffer. If the sync conversion is not
specified, the input block is omitted from the output.
On input files which are not tapes or pipes, the file
offset will be positioned past the block in which the
error occurred using lseek(2).
So, the bs=1024
tells the program to process the files (input and output) in 1024 byte chunks. The noerror
flag tells the program to ignore errors. If you include the sync flag, the output file will be padded with null characters (ASCII O) where the data is unreadable. The final command would look something like this:
dd conv=noerror,sync bs=1024 if=/path/to/original/file of=/path/to/destination
Andy
Hi Tugboat:
Thanks for the man page. I tried looking up noerror but nothing came up, and didn’t think about the sync. Your info is great!
Thanks,
guy o.