• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
do JavaScript -- giving it a variable
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

do JavaScript -- giving it a variable


  • Subject: do JavaScript -- giving it a variable
  • From: Brandon Lake <email@hidden>
  • Date: Fri, 25 Jul 2003 16:57:45 -0700

Hey, :o)

I'm trying to write a script to open a search query in multiple search
engines, but make it so the user only has to type in the input once.
i.e. Search term = tortes, then query google images, Epicurious
recipes, etc. . .

The problem I'm running into is getting the variable passed to java.
I can query in a single do JavaScript and it works fine:

set this_script to "javascript:void(q=prompt('Enter text to search
using
Epicurious.',''));if(q)void(location.href='http://www.epicurious.com/
s97is.vts?action=filtersearch&filter=recipe-
filter.hts&collection=Recipes&ResultTemplate=recipe-
results.hts&queryType=and&keyword='+escape(q))"
do JavaScript this_script in document 1

but then if I put that in a repeat the user has to re enter the code.
I'm not familiar enough with JavaScript to edit that and keep a
variable retained so I thought I could take the variable in finder and
put it in. This code runs it, but evidently passes Safari the search
term "undefined" rather than my variable search_text. . . . anyone know
why?

there is extra code here, definitely not perfect, not all necessary,
and not necessarily pertaining to the question, but I thought I'd give
the whole script to make it easier to cut and paste and see what I see
--- tabs is not quite perfected ---- might want to just select windows
for testing purposes :o)
--------------------------------------------------------------
set this_script to "javascript:void(q=prompt('Enter text to search
using
Epicurious.',''));if(q)void(location.href='http://www.epicurious.com/
s97is.vts?action=filtersearch&filter=recipe-
filter.hts&collection=Recipes&ResultTemplate=recipe-
results.hts&queryType=and&keyword='+escape(q))"
tell application "Safari"
activate

try
display dialog "Perform Search across Multiple Search Enginges" &
return & return & "This script will open the query you choose as a
result in the front document of new windows or new tabs." buttons
{"Cancel", "Windows", "Tabs"} default button 3
set the display_method to the button returned of the result

if the display_method is "Tabs" then
-- size the document to full screen
do JavaScript
"moveTo(0,0);self.resizeTo(screen.availWidth,screen.availHeight)" in
document 1
end if
tell application "Finder"
activate
try
display dialog "Please enter the text you would like to search
for." default answer "Search Text Here" buttons {"OK", "Cancel"}
default button 1
set search_text to text returned of the result
log search_text
set this_script to
"javascript:void(location.href='http://www.epicurious.com/
s97is.vts?action=filtersearch&filter=recipe-
filter.hts&collection=Recipes&ResultTemplate=recipe-
results.hts&queryType=and&keyword='+escape(" & search_text & "))"
end try
end tell
log this_script
repeat with i from 1 to 2
if the display_method is "Windows" then
set this_doc to make new document at beginning of documents
else
my new_tab()
end if
do JavaScript this_script in document i
set this_script to
"javascript:void(location.href='http://images.google.com/images?"; &
search_text & "='+escape(" & search_text & "))"
-- do JavaScript this_script in document 2
end repeat

on error the error_message number the error_number
if the error_number is not -128 then
display dialog the error_message buttons {"OK"} default button 1
end if
end try
end tell

on new_tab()
tell application "Safari" to activate
tell application "System Events"
tell process "Safari"
click menu item "New Tab" of menu "File" of menu bar 1
end tell
end tell
end new_tab


-----------------------

TIA,
Any input would be welcomed

Brandon Lake
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.

  • Prev by Date: Re: Every running application
  • Next by Date: Re: Script Editor 2.0 beta 2
  • Previous by thread: Script Editor 2.0b2 bug report
  • Next by thread: Re: vpnclient
  • Index(es):
    • Date
    • Thread