Saturday, January 20, 2018

#1 2010-08-22 11:21:54 pm

roystonmarshall
Member
Registered: 2003-07-07
Posts: 20

Running a Javascript in an Applescript XCode application

HI.
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

Cheers

Roy


Filed under: javascript, xcode

Offline

 

#2 2010-08-23 03:53:25 pm

SuperScripter
Member
Registered: 2010-03-10
Posts: 63

Re: Running a Javascript in an Applescript XCode application

I'm not entirely sure how to solve your problem...

But have you considered using JSTalk (http://jstalk.org/) 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

-SuperScripter

Offline

 

#3 2010-08-23 07:46:14 pm

Shane Stanley
Member
From:: Australia
Registered: 2002-12-07
Posts: 5231

Re: Running a Javascript in an Applescript XCode application

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


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/

Offline

 

#4 2010-08-24 04:19:10 am

roystonmarshall
Member
Registered: 2003-07-07
Posts: 20

Re: Running a Javascript in an Applescript XCode application

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?

Roy

Offline

 

#5 2010-08-24 05:02:24 am

Shane Stanley
Member
From:: Australia
Registered: 2002-12-07
Posts: 5231

Re: Running a Javascript in an Applescript XCode application

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


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/

Offline

 

#6 2010-08-24 01:02:00 pm

roystonmarshall
Member
Registered: 2003-07-07
Posts: 20

Re: Running a Javascript in an Applescript XCode application

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

Roy

Offline

 

#7 2010-08-24 02:42:58 pm

roystonmarshall
Member
Registered: 2003-07-07
Posts: 20

Re: Running a Javascript in an Applescript XCode application

I have tried this:

set myPath to path to me + "Resources:hi.strings"

is this what you mean?

Offline

 

#8 2010-08-24 03:45:38 pm

ief2
Member
Registered: 2010-07-23
Posts: 66
Website

Re: Running a Javascript in an Applescript XCode application

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

Applescript:

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,
ief2


Find your magical software at www.wizardsoftware.tk.

Offline

 

#9 2010-08-24 04:09:47 pm

roystonmarshall
Member
Registered: 2003-07-07
Posts: 20

Re: Running a Javascript in an Applescript XCode application

Thanks ief2

I tried this,

Applescript:

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 smile

Roy

Offline

 

#10 2010-08-24 04:45:53 pm

Shane Stanley
Member
From:: Australia
Registered: 2002-12-07
Posts: 5231

Re: Running a Javascript in an Applescript XCode application

roystonmarshall wrote:

I have tried this:

set myPath to path to me + "Resources:hi.strings"


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.


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/

Offline

 

#11 2010-08-24 05:12:47 pm

roystonmarshall
Member
Registered: 2003-07-07
Posts: 20

Re: Running a Javascript in an Applescript XCode application

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

Roy

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)