0

I need a javascript function to trigger a function in an application developed in Lazarus for both OSx and windows. I'm learning Lazarus and I'd describe myself as a medium level beginner. I know very little about javascript.

As I understand it javascript runs sandboxed so can not access an application directly. Therefore I was thinking about using some kind of tcp call from javascript into the application, passing a parameter that, when received, will trigger the event. This needs to work on both Windows and Mac. Ideally using the same components / code but if that's not possible then whatever I need to do.

My questions are:

1) Does this sound like the correct approach? 2) If it does - what is the best way and components to use to achieve this?

I've been looking at synapse - but to be perfectly honest am a little lost in what components I need to use and read up on to set this up.

So essentially - javascript needs to send a parameter to my application, which then takes an action when it's received.

Thanks in advance if you can help.

Godwin
  • 9,739
  • 6
  • 40
  • 58
  • What type of server are you using to generate your pages? Are you working in PHP, .NET, ect or are you just creating static HTML pages? – Godwin Apr 23 '13 at 22:47
  • Sorry - I wasn't clear. I'm not generating any pages. What I'm actually doing is trying to trigger my application to perform a task from within adobe photoshop. Photoshop allows you add menu items to some of their products using javascript. My application is a fairly standard Lazarus desktop application. So I need to get a message into my application (to trigger an action) from a Photoshop menu item using Javascript. My application itself will pass nothing back in return (unless it has to pass something back for completeness). – user2125574 Apr 24 '13 at 00:03

2 Answers2

1

I just did a quick search and it appears to me that Adobe Photoshop scripting isn't quite javascript but a variant of it called ExtendScript. There are guides to the language that you can find (like this one) but also performing a quick google search turned up this page and this page which describes a File.execute command that can be used to execute external applications which would probably be the best route to take.

My question about servers brings up another alternative, that if you have a server running, you could call it from javascript using a URL. Then the server may have more of authority to act on the event.

Sorry to just send you off to other sites and directions to try to solve this issue, but this is a fairly specific area.

Godwin
  • 9,739
  • 6
  • 40
  • 58
0

You probably need to read more about JavaScript, as it has many limitations like not having access to the local files, no possibility to communicate with a server not from the same domain the below links will probably give you a better idea :

http://en.wikipedia.org/wiki/Same_origin_policy

http://javascript.about.com/od/reference/a/cannot.htm

HTML5 websockets is probably a path but it is not widely supported in all browsers yet:

http://www.html5rocks.com/en/tutorials/websockets/basics/

EDIT:

now that you provided more details, you can create a thread in your application that will check on a file or ideally a table in which your server side write into it when he gets your javascript or (Ajax) query asking him to trigger a signal in your application.

There are many ways to do it the one I mentioned in one of the easiest, a more advance one, would be to send a signal to your application. (send a signal from your server to the application.) the database solution has more advantages, you can specify columns for arguments and you will have more flexibility, once your process the request from that shared table, you flag the row.

Below is one way to implement your table (processed is the flag that says if your signal was already processed-- you can also delete the row once processed):

| signal_id | arguments | application_id | datetime | processed (flag 0 or 1) |

Mehdi Karamosly
  • 5,388
  • 2
  • 32
  • 50
  • Please see my comment above about what I'm trying to do. As the application is always on the same physical machine as the javascript I presume that the communication issue will not affect me. Thanks for the links though - I'll read them tomorrow. – user2125574 Apr 24 '13 at 00:10