
Here’s a great script that creates a search function through AppleScript which, after being made into a Quicksilver trigger can be used ubiquitously.
-- 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
You add in your own searches by adding in: else if theKeyword is equal to "YOURKEYWORDHERE" thenreturn "PREFIX" & p "SUFFIX"
This is great because it seems like Saft, Sogudi and other Safari InputManagers are getting less and less reliable all the time. It’s good to have this low-fi solution that is available system wide.
Via: macosxhints.com
Just in case someone doesn’t know what to do with the script:
- Copy all text in the box above
- Open ScriptEditor located at /Applications/AppleScript
- Paste the code you copied
- Save in some folder (I have mine in ~/Library/Scripts)
For those who want to use this by making it into a Quicksilver trigger:
- Go to Quicksilver Triggers Tab in Preferences (have Quicksilver in focus and press ⌘,)
- Click the “+” sign –> HotKey
- Either Navigate to, or drop the Script on to the “Items” selection
- Have the action as: Run
- Click on the “Trigger” column on the row that your script is on
- Assign it a Hot Key
Written by
Travis Jeffery on December 18, 2007 at 3:57 pm -
Faster and System Wide Web Search for Safari has 2 comments -
Categorized in
Advanced Tips,
AppleScript Tips,
General Tips,
Quicksilver Tips,
Safari Tips - Tags:
applescript,
quicksilver,
safari,
search
Michael Zhao
atmac