DQSD search

This is a new Dave's Quick Search Deskbar search, cf (short for "clip file"), that takes either the search arguments or whatever text is on the clipboard and saves it on the desktop as an appropriately-named text file.

Examples:

cf dentist 555-1212
cf [a snippet of text just copied from a web page]

Note that you'll get an ActiveX warning the first time you run. This is probably a good thing.

<search function="cf">
 <name>Clip</name>
 <description>Save snippet to a text file on the desktop.<br/>
   <div class="helpboxDescLabels">Example:</div>
   <table class="helpboxDescTable">
     <tr><td>cf remember to call mom tomorrow</td></tr>
     <tr><td>cf [with friend's address on the clipboard]</td></tr>
   </table>
 </description>
 <category>Functions</category>
 <contributor>Mike Tsao</contributor>
 <script><![CDATA[
   function cf(q) {
     // First try getting stuff off the command line. If that fails,
     // grab the text in the clipboard.
     var clipboard = (q.length > 0) ? q : window.clipboardData.getData("Text");
     if (clipboard.length == 0) {
       nullArgs("cf", q);
       return false;
     }
     // Generate a semi-friendly filename.
     var filename = clipboard.substring(0, 48).
       replace(/[|/\\^=*]/g, "-").
       replace(/[\[<]/g, "(").
       replace(/[\]>]/g, ")").
       replace(/[?]/g, "").
       replace(/["]/g, "'").
       replace(/[;]/g, ".").
       replace(/\s+/g, " ").
       replace(/[^A-Za-z0-9 ,()'.\-=_+$]/g, "");
     filename = filename.replace(/^-/, "");
     filename = filename.replace(/\.$/, "");
     filename = "cf-" + filename;

// Figure out where the desktop folder is.
var wss = new ActiveXObject("WScript.Shell");
var dtp = wss.SpecialFolders("Desktop");

// Make sure the filename is unique.
var fso = new ActiveXObject("Scripting.FileSystemObject");
var dtfilename = fso.BuildPath(dtp, filename);
var appendage = 0;
var dtfilename_unique;
var found_unique = false;
while (!found_unique) {
dtfilename_unique = dtfilename;
if (appendage > 0) {
dtfilename_unique += " (" + appendage + ")";
}
dtfilename_unique += ".txt";
if (!fso.FileExists(dtfilename_unique)) {
found_unique = true;
}
appendage++;
}

// Open a new temp file on the desktop and write to it.
var ForReading = 1;
var ForWriting = 2;
var TristateUseDefault = -2;
var f = fso.OpenTextFile(dtfilename_unique, ForWriting,
true, TristateUseDefault);
f.WriteLine(clipboard);
f.Close();
}
]]></script>

<copyright>
Copyright (c) 2004 Mike Tsao
Distributed under the terms of the
GNU Public License, Version 2 (http://www.gnu.org/copyleft/gpl.txt)
</copyright>
</search>

Categories

About this Entry

This page contains a single entry by Mike Tsao published on June 3, 2004 1:38 PM.

Cool - unlock your phone was the previous entry in this blog.

Caltrain is the next entry in this blog.

Find recent content on the main index or look in the archives to find all content.

Powered by Movable Type 4.2rc2-en