-- This program is free software; you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation; either version 2 of the License, or
-- (at your option) any later version.
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
-- You should have received a copy of the GNU General Public License
-- along with this program; if not, write to the Free Software
-- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-- Copyright Olivier Croquette 2007 ocroquette at free dot fr
on keywordToURL(theKeyword, theParameters)
set p to theParameters as text
if theKeyword is equal to "gg" then
return "http://www.google.com/search?q=" & p
else if theKeyword is equal to "yt" then
return "http://youtube.com/results?search=Search&search_query=" & p
else if theKeyword is equal to "img" then
return "http://images.google.com/images?btnG=Recherche+d%27images=2=" & p
end if
return ""
end keywordToURL
on openTab(theURL)
tell application "Safari"
-- Open a new window if none available
if (count of every window) is equal to 0 then
make new document
end if
set isUrlEmpty to true
try
if URL of document 1 is not equal to "" then
set isUrlEmpty to false
end if
end try
if not isUrlEmpty then
tell window 1
-- Open a new tab in the existing window
set theTab to make new tab
set current tab to theTab
end tell
else
set theTab to current tab of window 1
end if
set URL of theTab to theURL
end tell
end openTab
on run
set AppleScript's text item delimiters to " "
set theURL to ""
set theQuery to "gg " -- set your default keyword here
set theErrorText to ""
set theDialogText to "Enter your query:"
set theDialogText to "Enter your query:"
repeat while theURL is equal to ""
tell application "Safari"
activate
set theQuery to text returned of (display dialog theErrorText & theDialogText default answer theQuery)
set theErrorText to "Bad keyword. Try again.
"
end tell
set theQueryList to text items of theQuery
try
set theKeyword to item 1 of theQueryList
set theParameters to (items 2 thru -1 of theQueryList)
set theParametersString to theParameters as text
set theURL to my keywordToURL(theKeyword, theParameters)
end try
end repeat
openTab(theURL)
end run