Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Search macosxhints from the command line UNIX
A simple hint, based on the Search VersionTracker hint. Here's how to rework the script to search macosxhints.com from the command line:
#!/usr/bin/perl -w
$browser = "Mozilla";
print "Search string: ";
$keyword = <STDIN>;
chomp($keyword);
$url = "http://www.macosxhints.com/search.php?query=".$keyword."&
mode=search&datestart=0&dateend=0&topic=0&type=stories&author=0";
$todo = "\'Tell application \"$browser\" to OpenURL \"$url\"\'";
system("osascript -l AppleScript -e $todo");
NOTE: The $url line has been broken into two lines for display purposes; enter it on one line with no spaces.

You must modify the script if you use a different browser. "Explorer" instead of "Mozilla" and getURL instead of OpenURL. Read the other hint and the comments for more details on creating and saving this script. But this works like a charm for me in Mozilla.

[Editor's note: To extend the concept in these two hints to any searchable site, just visit the site in question and execute a search. Copy the URL from the results page and then use that in the "$url" line. Replacing your test search term in the URL with the reference to $keyword as shown in the two hints, and you have an instant command-line search tool for that particular website.]
    •    
  • Currently 0.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (0 votes cast)
 
[3,337 views]  

Search macosxhints from the command line | 5 comments | Create New Account
Click here to return to the 'Search macosxhints from the command line' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Fix for omniweb
Authored by: FlyBoy on Aug 01, '02 02:59:04PM
This hint doesn't work for omniweb since the OpenURL command is not part of its Applescript suite; however, changing OpenURL to GetURL fixes it:
#!/usr/bin/perl -w $browser = "Omniweb"; print "Search string: "; $keyword = ; chomp($keyword); $url = "http://www.macosxhints.com/search.php?query=".$keyword."&mode=search&datestart=0&dateend=0&topic=0&type=stories&author=0"; $todo = "'Tell application "$browser" to GetURL "$url"'"; system("osascript -l AppleScript -e $todo");


[ Reply to This | # ]
Backslashes...
Authored by: robg on Aug 01, '02 06:48:40PM

Check the original code for the proper formatting of the line with backslashes; Geeklog ate the ones in the original comment (argh ... I really want the new engine!!)

-rob.



[ Reply to This | # ]
Fix for omniweb
Authored by: RudeDawg on Aug 05, '02 04:20:41PM

Not to nitpick, but this can be done easily in the "Shortcut Preferences" pane in OmniWeb.

One is already set up for searching Google in the address line.
This works for Mac OSX Hints...

Shortcut - hint@
Destination URL - http://www.macosxhints.com/search.php?query=%@"&
mode=search&datestart=0&dateend=0&topic=0&type=stories&author=0"

Again, type the URL in one line. Type "hint (space) (search term)" in the address bar, and presto!



[ Reply to This | # ]
the shell version
Authored by: mervTormel on Aug 01, '02 08:09:49PM

here's a shell version that uses the fink tool 'openurl' ; that will open an url in the default browser. this avoids the overhead of perl and applescript.

% cat shmox

#!/bin/sh

# file: shmox - search hints at macosxhints.com

# what's the site?
qSite="www.macosxhints.com"

# what's the query setup?
url1="http://${qSite}/search.php?query="

# keyword on the command line? deal with spaces in the query
keyword="$@"

# what's the query completion?
url2="&mode=search&datestart=0&dateend=0&topic=0&type=stories&author=0"

# no keyword on the command line? gotta have something to search for
[ "${keyword}" ] || { echo -n "search ${qSite}: "; read keyword; }

# construct the url
url=${url1}"${keyword}"${url2}

# want to see the crafted query? uncomment this tripe
# /bin/echo "submit ${qSite} query: "; echo ${url} | /usr/bin/fold

# splat
/sw/bin/openurl "${url}"



[ Reply to This | # ]
Minor nitpicking
Authored by: Carthag on Aug 04, '02 11:10:39AM
Perl does variable interpolation on double-quoted strings, so you don't have to put the $keyword outside and concatenate it with .s...
$url = "http://www.macosxhints.com/search.php?query=$keyword&
   mode=search&datestart=0&dateend=0&topic=0&type=stories&author=0";
will work as well... Just wondering why it's used in two of the places but not in the others. :)

[ Reply to This | # ]