how does xcode change resource files when adding them to a program?

I’ve added some files to my applescripf studio app bundle. I’ve made sure the files have been copied to the app directory.
I can open just about any file except for rsrc files. (The rsrc files are from another application that i use to replant it’s settings)
I know they are resource files, so how does xcode change them when adding them to the program?

My code used is as follows:

set sFile to resource path of main bundle & "MyFile.RSRC"
set FileRef to open for access POSIX file sFile
set fSize to get eof (FileRef)
set msg to read FileRef

Now, Variable FileRef is OK. It returns a number above 0
fSize will always return 0 no matter what i do, or how i reference the file.
msg will always give a End Of File error.

I’ve tried to rename the file to .txt before adding it to the project, but it still doesn’t return anything.
I’ve checked to make sure the file actually has content. If i open the file (On the hard disk and not in teh bundle) and read it as data, IE

set msg to read FileRef as Data

Then it’ll return actual data, and it’s not 0 bytes.

Anyone have this problem or know how to get aound it?

(PS. I typed the code by memory, not in editor. There may be mistakes, i didn’t check. But you get the idea behind the code :wink:

Well, mistakes are the key :wink:
Note that the hilited line should be:

set sFile to resource path of main bundle & "/MyFile.RSRC"

And, if the app is called “FOO” and it is in your desktop, “MyFile.RSRC” should be located at:

~/Desktop/FOO.app/Resources/MyFile.RSRC

And all should work fine!

Hey

I didn’t copy/Paste my code, so i may have put in the wrong slash, (Not a problem in the editor, it tells you :slight_smile:
But, i have tried with both types of slashes in any case…

Using my code below

 set sFile to resource path of main bundle & "MyFile.RSRC"

will return a path of “HardDiskUsersXXXXDesktopAppFolderAppName.APPResources”

So i addon the 'myFile.RSRC" Now, i’m not having problems getting any other file out of the resource bundle. Just the RSRC files which seems to always be 0 bytes when using Get eof ( ) command.

Example, if i use this code, it’ll WORK FINE.

set sFile to resource path of main bundle & "LogFile.TXT"
set FileRef to open for access POSIX file sFile
set FileData to read FileRef
close access FileRef

This works fine. I can open the files, read the content, and close them. ANY other file i’ve tried works other then .RSRC file. (Any RSRC file)

I’m not too sure what else i can do about this. The only option i can see at the moment it to DeRez the rsrc files, and hard codeit. (I really really don’t want to do that) So if you know the reason, or a way to get around my problem, it’ll save me quite some time.

Dustin

Two things: you are not using “”, but “/”. In fact, you couldn’t compile your script if you were using “file.rsrc”.
The second one: if you can read anything, except for your RSRC file, then you are using a resource-fork RSRC file. At build time, Xcode will empty the resource fork of any file. Only data-fork allowed (data-fork = you open the file in textedit and you see its contents; resource-fork = you open the file in ResEdit or Resorcerer or ResFool and you see its contents).

You can package and un-package a resource-fork file following these easy steps:

  • Go to the Terminal and type:
    cat ‘/path/to/resourceforkfile.rsrc/rsrc’ > ‘/path/to/newdataforkfile.rsrc’;
  • Note that we append “/rsrc” to the name of the resource fork file, so we can read resource-fork’s contents, and transmit them to a new pure datafork file.
  • To un-package again the file (restore it to resource fork):
    echo -n ‘’ > ‘/path/to/restoredresourceforkfile.rsrc/rsrc’; cat ‘/path/to/newdataforkfile.rsrc’ > ‘/path/to/restoredresourceforkfile.rsrc/rsrc’

So, you can package your rsrc fork file as a datafork file, then restore it when needed again to its original res-fork state.
:?:

Done and Done.

Another glorious victory for jj

thanks.