![]() |
applescript listen for apple event
I want to know if this is possible, I need to write a applescript that will reside on the users local drive, it will get launched from my application. Once launched it will sit there and wait and listen to see if or when the user launches safari and I also need to then continue to wait and listen for if the user clicks on a particular button on a web page, is this possible
|
faez, this is still the same topic as the one you launched before - you're shooting yourself in the foot by starting a new thread; you lose all the discussion that went into the last thread.
I think the moderators should re-attach this thread to the end of your other thread. to answer your question, applescript does not have any explicit event sniffing capability. there are ways you could convince it to wait for Safari to launch (or you could write a launchd plist that would trigger an applescript when Safari launched) but clicking on a button in Safari would not in itself create an apple event (apple events are inter-application, not intra-application). that being said, I think at this point it would be helpful if you told us what is supposed to happen when a user clicks on this button in Safari. what utility is launched, and what does it do? maybe we can find a workaround to what you want. |
hi tw, I thought this should be a new thread because it's a whole new approach. Whereas we were trying to do something from within the browser, now we are trying to do it outside the browser...here's the background
We are using a charting tool that chart's users data and displays it in safari. All this is local machine no network involved. The problem is the charting tool does not have a facility that allows you to save the chart or copy it to clipboard - don't ask! So I have done two things 1.put two buttons on the webpage that displays the chart, "capture" "save" 2.I have written a java utility that basically copies the portion of the screen that contains the chart and saves it as a jpg file or copies it to the clipboard Now there doesn't seem to be a way to launch my java utility when the user clicks on "save" or "capture" from the webpage. Too many security issues etc etc or so I have been led to believe. So then I thought ok how can I detect that the user has clicked on the save button on the page and launch the java utility, and I thought of applescript basically this is my train of thought. When I launch safari, I will also launch an applescript The applescript would then sit there and listen, if the user clicks the "save" button, if he does then it would continue on and launch my java utility which would go save the chart and quit. |
In addition to what tw said, I still don't see why you don't just provide a link to download the file. Eventually, Microsoft is going to break your app, and Apple is never going to allow it, so why bother?
|
a couple of questions:
|
Quote:
2. No not a java utility its flash 3. the information that is being graphed is data that the flash gets from a xml file which gets generated when the chart is launched 4. bar graphs to complex stock charts, 3D charts which can be panned. |
ah, that's more complex than I'd hoped - I was thinking you could use javascript to save portions of the screen, but that's not going to work.
of course, you could always save the entire webpage as an archive, but the next time the utility ran it would change the XML file, which would change the saved webpage, so that wouldn't work... I take it editing the flash app is out of the question?? and that the app isn't designed so you can right-click to save the current image? it's easy enough to launch the utility, if that's your concern. just give the user with a pre-made local webpage they can click on that loads the flash application. all the 'capture' button needds to do, then in reload the page and it will rerun the flash. saving is a bit more of a problem, though... |
Based on the suggestions I've been getting on this forum would the following work???
1. I create a small file and give it an extension....say *.jzcht 2. I repackage my java jar file to a Mac application bundle 3. I then set up an association with the file *.jzcht and set it open with the java app file 4. I store this *.jzcht in a predefined location on the users server, perhaps in the same place as the datafile for our application 5. On the web page, under the button I put the href to the *.jzcht file on the server 6. Now when the user clicks on the button the browser will attempt to download and open the file. to do that it would launch the java app So now 1. would this above scenario work 2. Also the url to the *.jzcht file would need to in the form http://192.168.x.x/pmz/myFile.jzcht where 192.168.... would be the internal ip address of the server 3. When the user click on the href will he get any of those security messages saying "this page wishes to download etc etc" |
Quote:
|
Quote:
you know, you could simply package the java program with the utility. save you having to worry about downloading and launching it. |
Quote:
|
faezbhanji:
If <all> you need to do is launch your java app from the HTML 'Save' button, do this: Download and install MisFox or More Internet (both are freeware). Using either one, create a new protocol helper with a name such as 'QuickHack'. Assign your java app to the protocol. Write a link (or make a button) using the URL form as follows: <A HREF="QuickHack:">Launch My App</A> Believe it or not, that's all that should be required... If it doesn't work, you may have to repackage your java app in a Mac app 'shell' for it to be recognized as a legit helper. I just now assigned Dictionary to QuickHack, and it worked fine. (In my opinion, being able to assign protocol helpers really ought to be part of the OS... but Apple hasn't supplied the means since OS 9... and the two third party utilities have taken up the slack.) Hope you can get your project to work. Peter B. ----- |
Quote:
you'll need to use the HTML Object element to embed the flash and java in the webpage. |
but what about those ugly security messages, won't she get all those messages.
I already have the flash embedded, it came as instructions with the utility on how to do it. How do I embed the java, and how do I then launch the java app when the user clicks on the "save" button for example and how come you know so much and how can I become like you :) |
Quote:
|
faezbhanji:
I think you may get a message the <first> time your app is run on the user's machine... thereafter not. I won't promise (absolutely) that my suggestion will work... but so far, it seems like the easiest possible solution. Worth a try. Let us know... Peter B. ----- |
Quote:
you get the ugly security messages when you download something to the computer, or otherwise open a vulnerability. if the java app is already on the machine, and being run from within a webpage, there is no security risk and so no security warnings. to embed and use a java app in a web page do something like this... add this (modified appropriately) to your HTML to launch and embed the java app (this assumes you have it in .jar format, which may not me true; you can call the class directly if you don't want to use jar): Code:
<applet id="javaApp" code="path.in.jar.to.main.class" name="name.of.mainroutine" Archive="javaAppName.jar" codebase="." style="...display considerations if necessary..."> |
Quote:
Ok so I need add an idle loop, to my java app, are you able to tell me more about idle loops or point me in the right direction. Will the java app quit itself when the user closes the page, or do I have to set it to quit when the user closes the page. If so how would the page know its being closed? if I'm going to be calling a public function from within document.javaApp.doThisFunc() can I pass it parameters as well when I call it...so document.javaApp.doThisFunc(prm1, prm2, prm3) On another note, how do I get the position of the top of the document and the left of the document, when I do "window.screenTop" and "window.screenLeft" it gives me the top left position of the whole window, but I want the top left of the document. Ok it's 4:30am in the morning so I'm going to crawl into bed....embed java app.....:rolleyes: |
Perhaps I should have started a new thread about this, but it seemed relevant here.
This is motivated by my curiosity and my (near complete) ignorance of java... or of java applets as run from browsers. If a java app which resides locally (and acts locally) can be embedded so readily in a web page, why is there so much fear and loathing of running other _local_ scripts and apps from links in HTML? Is the java sandbox that much more restricted than the Mac OS in terms of security? Thanks for any answers... or pointers to explanations. Peter B. ----- |
Quote:
|
Quote:
Quote:
the java app automatically unloads when you close the page - no worries... Quote:
Quote:
|
Quote:
the fear and loathing, as you put it, of running other scripts and apps from links in HTML is (maybe) natural. I mean, every time you run any application or script on your machine, it's a bit like getting an injection - it goes right into the machine's bloodstream and bypasses a few levels of protection. the paranoia about running things from HTML is that it feels as though anyone in the world could walk up to you and give you an injection, maybe even without you knowing about it. keeping HTML from running local apps is good prophylaxis, and not one that most people want to relax. |
Quote:
|
if you can make jave save to a file, it will do it from the web page.
|
Quote:
|
Quote:
you're in the realm here where you have to experiment and work out the kinks you find. I can't help you much with what amounts to debugging issues. |
Quote:
I tried googling "java application embed webpage" and other variations on this to try and find out for myself, but I couldn't find any examples of places where a java app is actually being embedded, although there seem to be many where there are applets being embedded. If you could also point me to some further reading material on this I would really appreciate it. |
Quote:
best thing to do is find someone who is giving the source code for an embedded java app. I first learned how to do this by looking at the source code for MyPhysicsLab, which I needed to adapt for a project I was doing. it's complex programming to start with (though very well done - hats off to Erik Neumann) - you might want to see if there's some other simpler source code out there. maybe this will help, too - WC3 standards for objects and applets in HTML 4 |
Hi Tw,
greetings from down-under, could you have a look at the code below, this is what I have put in my page, but the java app doesn't seem to want to run, it should pop-up with the SaveAs dialog, but it doesn't do anything. Code:
<APPLET name="app1" code="savechart.class" archive="SaveChart.jar" codebase="." >I can launch the jar file from the terminal so that is working fine, which would mean something in my html code above is not right I'm publishing my java code below, could you please compile it and save it as a jar file and see if you can get it to run. to run it all you need to do is give the jar file 4 parameters say 0 0 500 700, these are the rectangle of the screen shot it will take of the screen. Code:
import java.awt.image.BufferedImage; |
faez,
you're almost there, I can see that. play with it for a week and see if you can iron out the kinks. |
Quote:
I'm assuming my java code is ok and the problem is in my html tags am I right? Also with those params how am I supposed to use them? it would be kewl if you help, but if you can't well..then I'm up sh!t creek...:confused: |
I have worked on this all weekend, I'm not having much luck getting it to run
if anyone out there can help I would greatly appreciate it. |
| All times are GMT -5. The time now is 05:51 AM. |
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.
Site design © IDG Consumer & SMB; individuals retain copyright of their postings
but consent to the possible use of their material in other areas of IDG Consumer & SMB.