Re: drag/drop file-icon on tcl-script? on windows



alten wrote:
Eric Taylor wrote:
I'm on windows. I have a few tcl scripts where I'd like to
drag a file onto the programs Icon, or it's shortcut, and
be able to use it like I do with most other programs.

Is there a way to get the tcl program to launch and have argv(1..n) be
the dropped file names? Sure beats drilling down 5 levels in a file
dialog if you can simply reach the file with your mouse.


Any ideas?

Wrap your script in a batch file.
:: THIS IS FOR WINDOWS CMD.exe NOT W95 COMMAND.COM!
::if 0 {
if not {%1}=={} set myFiles=%*
start tclkit "%~f0" & exit

::NOW THE TCL STARTS . . . }

wm wi .
if {[info exists env(MYFILES)]} {
foreach f [string map {\\ \/} $env(MYFILES)] {
tk_messageBox -message "Doing something with \n$f"
}
}
tk_messageBox -message Done.
exit


I assume that you have tclkit.exe in your path.
something doesn't work with my 'file normalize', so I used 'string map'
instead. Something is also wrong in my 'exec', and the files won't
pass correctly to, for example, notepad.

Most people on windows have ActiveState so he's more likely to have
tclsh and wish in his path. Replace the start tclkit bit with start
wish and you will have correct behavior of file normalize.

Your batch file generated an error for me:
invalid command name :: while executing
:: THIS IS FOR WINDOWS CMD.exe NOT W95 COMMAND.COM!

The following batch file works perfectly:

::if 0 {
if not {%1}=={} set myFiles=%*
start wish "%~f0" & exit
:: }

wm wi .
if {[info exists env(MYFILES)]} {
foreach f [string map {\\ \/} $env(MYFILES)] {
tk_messageBox -message "Doing something with \n$f"
}
}
tk_messageBox -message Done.
exit

The ::if 0 { trick is neat ;-)

.



Relevant Pages

  • TO run an Application from Batch file
    ... copy or del command, eventhough i could not see the command window. ... But if the batch file has some application for e.g., Notepad,it seems ... But if i give exit after some time, ... I could run the same code in the windows vb.net application, ...
    (microsoft.public.dotnet.framework.aspnet.security)
  • Re: Setting Ownership rights on a file?
    ... What I need to do following the copy is to change the Ownership rights on ... the file in the batch file to a specific AD user or perhaps group. ... with Windows. ...
    (microsoft.public.windows.file_system)
  • Re: tcl/tk on Windows: "This application has requested the Runtime to terminate it in an unusual way
    ... I assume you mean calling the 'exit' command. ... the proc 'quit' that you've written. ... Windows) as explicitly quitting Tk's even loop. ... explicitly destroy the root toplevel (a hint found via a google search, ...
    (comp.lang.tcl)
  • Re: Exceptional Error
    ... to exit above the top directory. ... Kevin Spencer ... and the bicycle has to *want* to change. ... I am using IIS in Windows XP. ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: How to set exit code of non-console app?
    ... say I have an app called "MyApp" with the following Main function: ... So it's clear from my tests that the exit code for a Windows application is ...
    (microsoft.public.dotnet.languages.csharp)