Resource fork tools
Tcl (toolkit command language) offers a library to read and write Mac res fork resources.
The package may not be installed as part of OS X but is available here:
http://sourceforge.net/projects/tclresource (download the 1.1 version).
To install, unstuff and drag the 'Tclresource1.1' folder to one of the folders listed in the 'readMe' file.
Implementing Tcl language in SuperCard's shell function is quite different than other examples on this wiki.
Tcl statements are verbose and linefeed delimited.
In Tcl, square brackets are command expansion metacharacters. Using merge() requires special care.
Tcl syntax is simply passed to the Tcl interpreter.
| get shell("echo TCLsyntax | tclsh ; ") |
Additional commands, file redirection may follow...
| get shell("echo TCLsyntax | tclsh > file.rsrc ") |
Read resource
Read a res fork resource and return its data
function tclReadRes srcpath,rType,rID
--requires Tclresource1.1
--srcpath: unix path to source file
--rType: 4 char type identifier
--rID: numeric id of resource to read
if length(rtype) ≠4 then
alert sheet "Param error!" explain "invalid res type"
return ""
end if
trace
put linefeed into lf
--begin
put "package require resource" & lf into tcl
--load tclresource library
put "set rRef [resource open -resourcefork `[[srcpath]]` RDONLY]" & lf after tcl
--open res fork of source
put "set rText [resource read `[[rtype]]` `[[rID]]` $rRef]" & lf after tcl
--read resource
put "resource close $rRef" & lf after tcl
--close res fork
put "fconfigure stdout -translation binary" & lf after tcl
--don't filter output
put "puts $rText" & lf after tcl
--'print' res data
--//
put merge(tcl) into tcl
--pre-merge --required else following merge thrashes syntax
return shell(merge("echo '[[tcl]]' | tclsh "),1,raw)
--return resource data
end tclReadRes
File to resource
This function reads a source file then adds the file content as a res fork resource to the target file
If the target file is created if it doesn't exist.
The content of the source file is returned.
function tclFile2res srcpath,tgtpath,rType,rName
--requires Tclresource1.1
--srcpath: unix path to source file
--tgtpath: unix path to target (resource added here)
--rType: 4 char resource type code
--rName: name assigned to new resource
if length(rtype) ≠4 then
alert sheet "Param error!" explain "invalid res type"
return ""
end if
put linefeed into lf
--begin
put "package require resource" & lf after cmd
put "set sRef [open `[[srcpath]]` RDONLY]" & lf after cmd
--open source for reading get a reference to it
put "fconfigure $sRef -translation binary" & lf after cmd
--don't strip non printable characters while reading
put "set binData [read -nonewline $sRef ]" & lf after cmd
--read file not appending linefeed and store in a variable
put "close $sRef" & lf after cmd
--close source file
put "set rRef [resource open -resourcefork `[[tgtpath]]` WRONLY]" & lf after cmd
--open resource fork of target for writing
put "fconfigure stdout -translation binary" & lf after cmd
--dont strip non printable chars (may not be necessary)
put "resource write -force -name `[[rName]]` `[[rtype]]` $binData" & lf after cmd
--write variable content to resource
--forcing addition of resource given an extant resource of 'rtype' 'rName' --adds not overwrite
--use '-name' & '-id' options to overwrite extant resource
put "resource close $rRef" & lf after cmd
--close target resource fork
put "puts $binData " & lf after cmd
--return the read data
--//
put merge(cmd) into cmd
--pre merge --required else merge below thrashes syntax
return shell(merge("echo '[[cmd]]' | tclsh"),1,raw)
--execute
end tclFile2res
Comments (0)
You don't have permission to comment on this page.