www.webdeveloper.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 18

Thread: Call app or AppleScript from JavaScript

  1. #1
    Join Date
    Mar 2011
    Posts
    8

    Call app or AppleScript from JavaScript

    I too am a javascript newbie and I've been searching for a way to run/launch/execute either an AppleScript or an app from JavaScript. Everything I've found on the web seems to say that it's not possible to run an app from JavaScript. If that's true then IMO it's a big weakness. I have seen hints however that I can run an AppleScript from JavaScript but I can't figure out how to do it. Can someone help please with either one?

  2. #2
    Join Date
    Dec 2003
    Location
    Bucharest, ROMANIA
    Posts
    15,428

  3. #3
    Join Date
    Mar 2011
    Posts
    8
    Thanks, but that seems to be the opposite of what I'd like to be able to do which is either 1) run an application from JavaScript, or 2) run an AppleScript from JavaScript. If I'm misunderstanding what is shown at that link please let me know.

  4. #4
    Join Date
    Dec 2002
    Location
    St. Louis, MO, USA
    Posts
    1,582
    The link describes how normally the JavaScript/AppleScript relation is "one-way", but the author has determined that, at the very least, AppleScript can inform JavaScript whether or not a piece of code was successfully run, or not.

    If you were looking for a way to get JavaScript and AppleScript to work together, that link should get you started on that path.
    |||||
    o . Q
    ___ "You live and you learn; or you don't live long." - Lazarus Long

    ^_^

  5. #5
    Join Date
    Jul 2008
    Location
    urbana, il
    Posts
    2,787
    you can launch desktop apps from the browser by associating a particular mime type with the application.

    javascript can then open a real or fake source of content using that mime type, thus triggering the execution of the associated program.

    as a bonus, most browsers allow you to remember these associations, so autonomous interaction is possible after the initial choice is made.

    for example,
    Code:
    window.open("data:x-application/myApp;,%20")

  6. #6
    Join Date
    Mar 2011
    Posts
    8
    Okay I tried window.open("data:x-application/CP.app"); and while there were no errors, nothing happened. CP is my AppleScript application in the same folder as the executing JavaScript. What do I need to change?
    Last edited by MartinLiss; 03-21-2011 at 04:29 PM.

  7. #7
    Join Date
    Jul 2008
    Location
    urbana, il
    Posts
    2,787
    use the syntax i posted: your code has a 0byte body, which is probably forcing the whole thing to be ignored.
    it should ask you "open or save" when the code runs.
    review dataURI syntax for clarification

  8. #8
    Join Date
    Mar 2011
    Posts
    8
    No joy.

    I did the following and no errors but again nothing happens

    window.open("data:x-application/CP.app;,%20");

    As an experiment I also found and tried this but no window showed up.

    var myWindow=window.open('','','width=200,height=100');
    myWindow.document.write("<p>This is 'myWindow'</p>");
    myWindow.focus();

  9. #9
    Join Date
    Jul 2008
    Location
    urbana, il
    Posts
    2,787
    does the code i posted do anything?

    if it opens a save/run dialog, then choose to open it with CP, and check the option to remember the choice.

    for this situation, it's easier to make up a new and unique mime for your app than wrestle default handling with browsers and OSs.

    if you want to actually open the file, it should not be fake, but you can at least trigger (and re-trigger executable) using my simple method.

    EDIT:
    perhaps opening the app by passing an invalid file terminates the app.
    if that's the case, create a wrapper executable that ignores the file passed, but executes the actual app you need.
    usually, you can browse for executable files to handle unknown mimes, so just browse to your wrapper in the open/save dialog...
    Last edited by rnd me; 03-21-2011 at 11:29 PM.

  10. #10
    Join Date
    Mar 2011
    Posts
    8
    Sorry but as I said I'm a JavaScript newbie and much of what you said means nothing at all to me but I'll respond as best as I can.

    "does the code i posted do anything?" ==> No

    "if it opens a save/run dialog, then choose to open it with CP, and check the option to remember the choice." ==> It doesn't open any dialog at present. When you mention CP are you talking about my CP? Because my CP is just an AppleScript Color Picker made into an app. I don't understand the reference to checking and choices.

    "for this situation, it's easier to make up a new and unique mime for your app than wrestle default handling with browsers and OSs." ==> You completely lost me here.

    "if you want to actually open the file, it should not be fake, but you can at least trigger (and re-trigger executable) using my simple method." ==> It's not a (data) file, it's an app.

    "if that's the case, create a wrapper executable that ignores the file passed, but executes the actual app you need.
    usually, you can browse for executable files to handle unknown mimes, so just browse to your wrapper in the open/save dialog…" ==>???

    Let me give a full explanation of what I'm trying to do. I'm an Administrator at VBForums (another Internet.com forum which is also vBulletin-based) and I've recently switched from a PC and IE to an iMAC and Safari. On IE I had a whole set of customized context menu items that made my life easier when dealing with posts in our forums. Some allowed me to enter boilerplate text in posts, some duplicated the Bold, Italic, etc buttons above, and some did other things. To duplicate those things for Safari I've been writing several (actually over a dozen) context menu extensions. Most of them already work but I've been having trouble with one that would allow me to highlight some text, choose the 'Color' context menu item and have it bracket the text with tags that would produce for example this (The tags look like [color="#00FF40"]this[/color])

    The IE 'Color' context menu item that I'm trying to replace is based on the MicroSoft Common Dialog control and I'm trying to base one off of OS x's Color app. My CP AppleScript calls the Color app and generates the hex value.

    In case you aren't aware the context menu items are based on basically two files, a global html file and a JS file. The html file tells the JS file what context menu item has been selected and the JS file acts on it.

    I've attached the CP Applescript which you can look at if you like and/or open the OS X AppleScript Editor and use it to save my script as an app and then run it.

    Thanks for your help so far.
    Attached Files Attached Files

  11. #11
    Join Date
    Mar 2011
    Posts
    8
    I can't believe that there's no way to call a script or app from a major language like JavaScript. That's too big a failing.

  12. #12
    Join Date
    Dec 2003
    Location
    Bucharest, ROMANIA
    Posts
    15,428
    Quote Originally Posted by MartinLiss View Post
    I can't believe that there's no way to call a script or app from a major language like JavaScript. That's too big a failing.
    The problem might be that both are client-side languages. And they are developed by different companies.

    For instance, take the server side: I don't think there is way to call a PHP function using ASP. Or to save a CorelDraw working sheet in Adobe Illustrator format. Usually all you can do across different things is to translate (and not always is possible) the final data (but not the inner functionality of a program/tool or another) using a common understandable format. XML or JSON, in case of data. EPS in case of images... and so on

  13. #13
    Join Date
    Jul 2008
    Location
    urbana, il
    Posts
    2,787
    i would use a dhtml color picker if that's all you need. there are several xbrowser packages floating around...

    the code i posted trigger the handler box in firefox on windows.

  14. #14
    Join Date
    Mar 2011
    Posts
    8
    Quote Originally Posted by rnd me View Post
    i would use a dhtml color picker if that's all you need. there are several xbrowser packages floating around...

    the code i posted trigger the handler box in firefox on windows.
    Can you get it to work with Safari?

  15. #15
    Join Date
    Mar 2011
    Posts
    8
    Quote Originally Posted by Kor View Post
    The problem might be that both are client-side languages. And they are developed by different companies.

    For instance, take the server side: I don't think there is way to call a PHP function using ASP. Or to save a CorelDraw working sheet in Adobe Illustrator format. Usually all you can do across different things is to translate (and not always is possible) the final data (but not the inner functionality of a program/tool or another) using a common understandable format. XML or JSON, in case of data. EPS in case of images... and so on
    But I can call Javascript from AppleScript and any app from Visual Basic and I believe you can call JavaScript from PhotoShop.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles