Version 2 of Droplets

Updated 2006-04-06 21:03:44

What is a droplet?

It is a way to drag and drop a file(s) or directory(ies) onto a tcl program which can then pick up the file/directory names using the standard argc and argv command line argument variables.


ET Here is how one goes about this on windows (w2k and up, not w9x):

Create a text file with a .bat extention, and prefix the tcl code with

 ::if 0 {
 start wish "%~f0" %* &
 exit
 }

 Tcl/tk code follows....

Note: This assumes you have wish in your path. If you install ActiveState's tcl installed, which should set patch for you.

Here are 2 examples,


2clip.bat

This simply lets one drag/drop a file onto the batch file and the full path to the file is placed into the clipboard. It will put up a dialog box because the clipboard gets cleared when the program exits. It will also just quit in 30 seconds as well. So, before the 30 seconds are up, you can paste the full name of the file into, say, a console windows.

 ::if 0 {
 start wish "%~f0" %* & exit
 }
 wm wi .
 if {$argc > 0} {
         clipboard clear
         set f [lindex $argv 0]
         clipboard append $f
         after 30000 exit
         tk_messageBox -message "Clipboard:\n$f" 
 }
 exit

pic2tcl.bat

Drag/drop a .gif or .jpg file(s) onto the batch file and it will create a file of the same path and name but with a .tcl extension that can be used as an inline image.

 ::if 0 {
 start wish "%~f0" %* & exit
 }
   package require base64
   proc trans {arg} {

     set file $arg

     set fd [open $file r]
     fconfigure $fd -translation binary
     set rawdata [read $fd]
     close $fd
  set fd [open [file root $arg].tcl w]
     set b64data [base64::encode $rawdata]
     puts $fd "image create photo -data {\n$b64data\n}"
     close $fd
   }


  wm wi .
  #console show
  if {$argc > 0} {
    foreach f $argv {
      set f [file normalize $f]
      #tk_messageBox -message "Doing something with \n$f"
      trans $f
    }
  }
  tk_messageBox -message Done.
  exit