copy a image/binary file on a mac
Klaus Major
k_major at osnabrueck.netsurf.de
Sat Jan 19 11:03:01 EST 2002
Bonjour Yves, hi Devin and all,
>> P.S. What you got is definitively a jpg-file, anyway...
>> Try to set the filename of an MC image to that file
>> et voila... :-D
>
> Yes I'm working on a Mac
>
> Thanks.
> -- Greetings.
>
> Yves COPPE
here is the promised explanation of how to copy an image (any binary
file)
on a mac correctly. It's a bit long. So be warned :-)
On the mac, the OS needs some specific information about a file,
to correctly handle doubleclicks etc...
We exspect Photoshop to be lauched, when we doubleclick a .PSD-file
(with or
without the file extension, which is not necessary on the mac, as long
as we see
that eye-icon !).
But the OS looks for the information about the "Type" (what kind of file
is it)
and "Creator" code (what app created that file) INSIDE that namely file.
These info is stored in the "resource-fork" of an file.
But a "resource-fork" is something totally unknown on windows, so
it doesnt appear when copying a file from mac to win.
And that's the reson why a file looks "corrupt" when we copy it back
from win to mac. The resource-fork really got lost.
Windows simply trashed it :-(
(Hey, what's that ? That's not the kind of file i know ! Two parts in
one file ?
Sorry ma'm, no way... Bye... :-)
So when using MC to copy files on a mac, one has to set the "filetype",
which is a series of 8 chars, describing exactly the above mentioned.
First 4 chars represent the creator , the last four the type.
Example:
A jpeg-file created by Photoshop has "8BIM" as its "signature"
and "JPEG" as the default code for jpg-files.
Filetype: 8BIMJPEG
A photoshop gif-file: 8BIM GIFf
So, noone can know all the filetypes, but we need that info to
get an exact copy of a file :-(
No problem, lets MC do the work :-)
Here we go:
##OldfilePath is the path to the file to copy
## We need to set the filetype BEFORE we copy the file.
##Here is a little function that will do the dirty work :-)
on mouseup ##or whatsoever
set the filetype to ye_olde_filetype(OldfilePath)
##this function will get one argument, the path to the file
##and will return the exact filetype :-D
put URL ("binfile:" & OldfilePath) into URL ("binfile:" & NewfilePath)
end mouseup
function ye_olde_filetype el_patho
put the directory into old_dir
##always a good idea to save and restore the original directory !
##a MUST if you work with relative paths for images etc...
set the itemdel to "/"
put last item of el_patho into the_file
##the filename
delete last item of el_patho
set the directory to el_patho
##now we are in the folder where the file resides
put the long files into all_files
##take a look in the reference about "the long files"
##that returns a list with lots of infos about the content of a folder
##(divided by a comma)
##like the filename, date of last modification, last saved ...
##and the filetype as the last item of each line
get line(lineoffset(the_file, all_files)) of all_files
##now we extract that line containing the filename
set the itemdel to ","
##restore the old itemdel. very important
set the directory to old_dir
##restore the old directory
return last item of it
##that's it
end ye_olde_filetype
Hope that helps.
Have a nice weekend.
Best from rainy germany
Klaus Major
k_major at osnabrueck.netsurf.de
More information about the use-livecode
mailing list