Running a Javascript in an Applescript XCode application

I have built an XCode Applescript application that uses do script to trigger a compiled jsxbin that is locatd on a shared server.
What I would like to do to make the application totally standalone, and have the javascript contained in the xcode app itself. I know I can add strings in the resources folder, and I have tried to call them like:

on clicked theObject
tell application “Adobe InDesign CS5”
do script “hi.strings” language javascript
end tell
end clicked

where the file “hi.strings” file is a strings file in the application Resources directory. The strings file simply contains a single javascript line "alert(“hi”);

Any help would be cool



I’m not entirely sure how to solve your problem…

But have you considered using JSTalk ( instead? Note that it won’t run on my machine, so I can’t tell you anything else about it, except for the fact that it exists.

It looks like it’ll do what you want, though. :wink:


You just need to build the path to the the js file, and then use “do script alias pathToFile language javascript”

Thanks for that.
I am still unsure as to how to point the app at the internal Javascript file.

	set myPath to "AppName:Resources:hi.strings"
	do script alias myPath language javascript

I know I am not setting the path correctly, but have tried many variations. The script is in the xcode Resources folder.

Any more help please?


I’m not sure in ASStudio, but I presume you’d start with “path to me”, build on that.

You will have to excuse me, but I am more a Javascript coder, so I dont know what you are referring to with the last post. Could you explain more, or give me an example?

Many Thanks


I have tried this:

set myPath to path to me + “Resources:hi.strings”

is this what you mean?

I think it’s something like this you’re after:

set jsFile to posix file ((resource path of main bundle) & "afile.js")

I’m not able to test this, so it could be completly wrong.

Hope it works,

Thanks ief2

I tried this,

set jsFile to posix file ((resource path of main bundle) & "loadStyles.jsx")

but got the error:

Expected “,” but found class name.

with the text ‘path’ highlighted in the applescript

Any other ideas?

Thanks for the help with this so far :slight_smile:


You need to get the path as text, and use & instead of +. You’ll also need to add “Contents:”, at least. Try logging:

log (path to me as text & “Contents:Resources:hi.strings”)

That should give you an idea of what else needs doing.

Many Thanks all.

That last reply was most helpful. Just needed to put the ‘path to me as text’ in its own brackets, and renamed my Javascript file to ****.js and all works well.

Thanks again