I would like to run a system command after the page is loaded.
Currently I have the code in my view but it is ran and then the page is
loaded.
The line I am trying to run in my view is as follows:
<% system “osascript -e ‘say “text to be spoken”’” %>
first off, the ruby code embedded in the template is parsed on the
server. the results are then sent to the browser/client with the
appropriate headers (html, xml, etc). so your call to ‘system’ is
being processed on the server, the results of which , if any,
incorporated into the response which is then sent to the browser.
Currently what happens is the command is executed but the result happens
before the page is loaded. Therefore before it loads the page it speaks
the text but I want it to speak the text after the page is loaded. Is
there any way to have it execute the command after the page loads?
Chris H. wrote:
that is not going to do what you think.
first off, the ruby code embedded in the template is parsed on the
server. the results are then sent to the browser/client with the
appropriate headers (html, xml, etc). so your call to ‘system’ is
being processed on the server, the results of which , if any,
incorporated into the response which is then sent to the browser.
Is there any way to have it execute the command after the page loads?
Sure. Put some Javascript in the rendered page, so that it generates an
XHR request back to the server. (You could hook that to an event, or
just put it near the end of your page source.) Use an action written
just for this purpose. Include the speech call in that action.
Then, soon after the page loads in the client (browser), the speech
command will be processed on the server. Does that help?
I am creating a system that askes questions to the user. The User has
the option to view all the questions or have them spoken to them one at
a time. Some of our user’s have very limited reading skills if any.
The application being created is available on the web in in our network.
Our platform is OSX
Thanks for your help. Your solution seems very reasonable but
unfourtnetly my javascript skills are very limited to some RJS so I am
not familiar with how to generate an XHR request and hook it to an
event. Do you know of any resources that could help give me the
knowledege I need to do this?
Thanks
Guest wrote:
Al Messina wrote:
Is there any way to have it execute the command after the page loads?
Sure. Put some Javascript in the rendered page, so that it generates an
XHR request back to the server. (You could hook that to an event, or
just put it near the end of your page source.) Use an action written
just for this purpose. Include the speech call in that action.
Then, soon after the page loads in the client (browser), the speech
command will be processed on the server. Does that help?
I am creating a system that askes questions to the user. The User has
the option to view all the questions or have them spoken to them
one at
a time. Some of our user’s have very limited reading skills if any.
The application being created is available on the web in in our
network.
Our platform is OSX
You seem to have missed it the first times it was mentioned, but your
code will cause the questions to be spoken on the server. That is not
on the local machine of the user. For the user to hear the stuff
that’s spoken, they’d have to get up and walk to the server room.
Probably not what you’re looking for.
Has a decent enough into into doing ajax calls with rails. But, I’m
kind of curious about something kind of fundamental here, you’re using
a system command on the server to speak the text? Is the user ALWAYS
sitting at the server, or within earshot of it’s speakers? Otherwise,
I don’t think you’ll be getting what you intended, and the solution to
speaking dynamic text to the user from a web-page will be
significantly more complicated than executing osascript.
Has a decent enough into into doing ajax calls with rails. But, I’m
kind of curious about something kind of fundamental here, you’re using
a system command on the server to speak the text? Is the user ALWAYS
sitting at the server, or within earshot of it’s speakers? Otherwise,
I don’t think you’ll be getting what you intended, and the solution to
speaking dynamic text to the user from a web-page will be
significantly more complicated than executing osascript.
Unless I am missing something, and I admint this may not be the most
elegant code but I think I can do it if grab the ip of the machine the
user is at and then in the system call I have it ssh into that ip using
keygens and then run the osascript .
Once I get that far I am still unclear as how to use the technique
mentioned above with regards to the javascript.
Guest wrote:
Other posters have mentioned (and I agree) that you probably don’t want
to do what you are saying you want to do.
You’re probably going to have to look into the different ways of
delivering audio to the client, that you want the user to hear. I think
this would be out of the scope of your original request; you’ll probably
want to investigate Flash, Java, or something similar to do your audio
presentations on the client.
Instead of trying to help you further on this list, I would simply
suggest that you enlist the help of someone who is used to architecting
this kind of hybrid system. It’s tricky.
Thank you for your continued support,
Guest
Al Messina wrote:
Thanks for your help. Your solution seems very reasonable but
unfourtnetly my javascript skills are very limited to some RJS so I am
not familiar with how to generate an XHR request and hook it to an
event. Do you know of any resources that could help give me the
knowledege I need to do this?
Thanks
Other posters have mentioned (and I agree) that you probably don’t want
to do what you are saying you want to do.
You’re probably going to have to look into the different ways of
delivering audio to the client, that you want the user to hear. I think
this would be out of the scope of your original request; you’ll probably
want to investigate Flash, Java, or something similar to do your audio
presentations on the client.
Instead of trying to help you further on this list, I would simply
suggest that you enlist the help of someone who is used to architecting
this kind of hybrid system. It’s tricky.
Thank you for your continued support,
Guest
Al Messina wrote:
Thanks for your help. Your solution seems very reasonable but
unfourtnetly my javascript skills are very limited to some RJS so I am
not familiar with how to generate an XHR request and hook it to an
event. Do you know of any resources that could help give me the
knowledege I need to do this?
Thanks
Elegant is all up to the beholder, I think a lot of rube goldberg
machines are very elegant. But I would have a lot of fun stealing
your passwords by hitting your webserver with my machine configured
with a promiscuous ssh server. Not to mention watching you squirm as
your hairs turn grey while you troubleshoot your ssh connectivity for
the next [insert how long you think you will work at your current job
here] years.
HA! Yes I see your point. Fortunately this application would ONLY be
accesiable to those in our very small network.
Bram Whillock wrote:
Elegant is all up to the beholder, I think a lot of rube goldberg
machines are very elegant. But I would have a lot of fun stealing
your passwords by hitting your webserver with my machine configured
with a promiscuous ssh server. Not to mention watching you squirm as
your hairs turn grey while you troubleshoot your ssh connectivity for
the next [insert how long you think you will work at your current job
here] years.
Information and Educational Technology
Kwantlen University College - 604-599-2120
“So powerful is the light of unity that it can illuminate the whole
earth.” --Bahá'u’lláh