"path to resource" doesn't work

Hi,

it’s drving me crazy, but better calm down and search for help. Here is my problem:

I generated a droplet with XCode (V2.2 on Tiger) and add some resources (XSL, PHP, Javascript files). No I’m trying to reference them from within my Applescript code via the “path to resource” command (exactly as discribed by Matt Neuburg in his “Applescript” book and as discribed in so many forum posts (add the resource via “Add to Project…” and then use "path to resource “myFileName”.

In my case this doesn’t compile. I always get the error message “resource not found”. And it doesn’t make any difference if I try to reference one of the added resources or one the resources inside the resources-folder after starting with the droplet like “InfoPlist.strings”. And also there is no diference if I’m working on a Droplet or an Application. I also tried to read about the Build-settings, but gave up.

At the moment I use absolute paths, but this is a bad solution if you want to give the droplet to other people.

Somebody got an idea, what in my context could be the reason for this behaviour?

Many thanks in advance
Alexander Krey

referencing ‘path to resources’ does not work outside of a handler
you should use sth like this intead:

global scriptFilePageNumbers

on awake from nib theObject
	set scriptFilePageNumbers to path to resource "HR_PageNumbers.jsx"
end awake from nib

Hi Dominik,

thanks a lot. It works.

Actually I had tried to put it inside a Handler, but got the same error message.
Perhaps its because you have to use a global instead of a property?

After some googleing I was yet convinced I had to use some strange constructs like CFBundleCopyResourceURL(), but you saved me!!!

best regards
Alexander

Hi Alexander,

it would also work with ‘property’ - but it also has to be declared outside and set inside of a handler:

property scriptFilePageNumbers : missing value

on awake from nib theObject
	set scriptFilePageNumbers to path to resource "HR_PageNumbers.jsx"
end awake from nib

:wink: D.

Ok.

So it seams my memory has a leak :stuck_out_tongue:
Perhaps I tried it like that:


property scriptFilePageNumbersName : "HR_PageNumbers.jsx"

on awake from nib theObject
   set scriptFilePageNumbers to path to resource scriptFilePageNumbersName 
end awake from nib

The aim was to declare all variables with information from outside at the beginning of my script.
But it doesn’t work like this, you actually have to give the “path to resource” command a String and not a variable declared as a property?

Alex :wink:

That should work fine Troedler.