Dutchman Posted February 11, 2006 Share Posted February 11, 2006 Hi, I was hoping someone could give me some general guidance on building a script that would execute when a file was dropped on an icon. For example: If I take a .doc file and drag it and drop it on my icon, I want my script to open Word, minimized, print the file I dropped on it, and then when it has been sent to the printer, close Word. I would like to do the same with Notepad, Excel, Acrobat, and Paint. I could associate various file types to run various programs and still change those associations as I see fit. Is this doable? But being rather new to this scripting thing, I'm not sure how I would go about getting the file name, path and type into the script so it could be executed. I imagine the drop function would be accomplished with the release of the mouse button, over the icon(x,y coordinate pair?) Am I on the right track? Are there a few examples of doing such a thing? Thanks! Link to comment Share on other sites More sharing options...
cdkid Posted February 11, 2006 Share Posted February 11, 2006 This is just the way i'd go about it... i would use a FileSelectDialog ratehr than drag and drop. but i've never used any drag'n'drop type stuff so im probably not the person to ask --my two cents ~cdkid AutoIt Console written in C#. Write au3 code right at the console :D_FileWriteToLineWrite to a specific line in a file.My UDF Libraries: MySQL UDF Library version 1.6 MySQL Database UDF's for AutoItI have stopped updating the MySQL thread above, all future updates will be on my SVN. The svn location is:kan2.sytes.net/publicsvn/mysqlnote: This will still be available, but due to my new job, and school hours, am no longer developing this udf.My business: www.hirethebrain.com Hire The Brain HireTheBrain.com Computer Consulting, Design, Assembly and RepairOh no! I've commited Scriptocide! Link to comment Share on other sites More sharing options...
flyingboz Posted February 11, 2006 Share Posted February 11, 2006 Hi, I was hoping someone could give me some general guidance on building a script that would execute when a file was dropped on an icon. For example: If I take a .doc file and drag it and drop it on my icon, I want my script to open Word, minimized, print the file I dropped on it, and then when it has been sent to the printer, close Word. I would like to do the same with Notepad, Excel, Acrobat, and Paint. I could associate various file types to run various programs and still change those associations as I see fit. Is this doable?An au3 compiled script implements the dragdrop method - kudos to whoever implemented that in the compiled executable - build a test script w/ a msgbox to show you the output, I believe that it is a pipe-delimited list, if more than one file is dragged on the target. For each string passed, you'll want to test fileexists() and then decide what to do with it - i.e. if StringRight($cmdline[$i],4) = ".xls" then ... etc. Reading the help file before you post... Not only will it make you look smarter, it will make you smarter. Link to comment Share on other sites More sharing options...
pecloe Posted February 11, 2006 Share Posted February 11, 2006 (edited) heres an example from one of my scripts #include <GuiConstants.au3> ;#include <Array.au3> opt("TrayIconDebug", 1) ;************ NOTES START ************ ;************ NOTES END ************** GUICreate("", 540, 200, -1, -1, BitOR($WS_SYSMENU, $WS_CAPTION), BitOR($WS_EX_ACCEPTFILES, $WS_EX_TOPMOST)) GUISetBkColor(0xD4FF2A) GUISetFont(13, 690) $LABEL_1 = GUICtrlCreateLabel("Drag and Drop File to get path", 20, 24, 500, 25) $LABEL_2 = GUICtrlCreateLabel("Here:", 20, 75, 48, 25) $INPUT_1 = GUICtrlCreateInput("", 70, 75, 100, 25) GUICtrlSetState(-1, $GUI_ACCEPTFILES) GUISetState() While 1 $MSG = GUIGetMsg() Select Case $MSG = $GUI_EVENT_CLOSE Exit Case GUICtrlRead($INPUT_1) <> "" $PATHOLDNAME = GUICtrlRead($INPUT_1) GUIDelete() MsgBox(0, "", $PATHOLDNAME) Exit EndSelect WEnd phil edit: removed +'s in styles, taken from old script, added bitor() Edited February 12, 2006 by pecloe Link to comment Share on other sites More sharing options...
flyingboz Posted February 11, 2006 Share Posted February 11, 2006 Sample code to test - compile and drop onto the resultant icon. For $i = 1 To $cmdline[0] $fn = $cmdline[$i] If FileExists($fn) Then MsgBox(0,$i,$fn,0) Select case StringRight($fn,4) == '.txt' ;do notepad stufff case StringRight($fn,4) == '.xls' ;assume excel ;ad nauseum case else Endselect EndIf Next Reading the help file before you post... Not only will it make you look smarter, it will make you smarter. Link to comment Share on other sites More sharing options...
mikeytown2 Posted February 12, 2006 Share Posted February 12, 2006 (edited) Sample code to test - compile and drop onto the resultant icon. For $i = 1 To $cmdline[0] $fn = $cmdline[$i] If FileExists($fn) Then MsgBox(0,$i,$fn,0) Select case StringRight($fn,4) == '.txt' ;do notepad stufff case StringRight($fn,4) == '.xls' ;assume excel ;ad nauseum case else Endselect EndIf Next I took your idea and made it happen... now all we need to do is print opt("TrayIconDebug", 1) opt("WinTitleMatchMode", 2) If $cmdline[0] = 0 Then $fn = FileOpenDialog("Print File", @MyDocumentsDir, "All (*.*)") ElseIf $cmdline[0] = 1 Then $fn = $cmdline[1] EndIf If FileExists($fn) Then $fn = StringReplace($fn, StringRight(StringLeft($fn, 3), 2), ':\"') & '"' RunWait(@ComSpec & " /C " & "start " & $fn, "", @SW_HIDE) EndIf $count = 0; $title = StringSplit($fn, "\") $title = StringTrimRight($title[$title[0]], 6) While $count < 100 If WinGetState($title) == "16" Then ExitLoop EndIf WinSetState($title, "", @SW_MINIMIZE) Sleep(51) WEnd This will open up any file btw Edited February 12, 2006 by mikeytown2 Email: POP3 & SMTP using SSL/TLS (OpenSSL)Email: IMAPEmail: Base64 & SMTP login & Send email direct to MX Server (thanks blindwig)Win: Hook Registry ChangesWin: Read/Write to Alternate Data Streams (ini example)Utility: GPS Distance Calculations, Vincenty and Haversine formulas; angles and elevationUtility: Dell Laser Printer (3000-5100) - Print LoggerUtility: Reset Router when Wireless Link FailsUtility: ImageMagick Batch jpg ProcessorVideo HCenc Batch FrontendVideo: *DEAD* YouTube Video Encoder (avs/avi to flv)Software On CD's I Like<<back|track3 Ultimate Boot CD for Windows SpinRite Ubuntu ophcrack Link to comment Share on other sites More sharing options...
Valuater Posted February 12, 2006 Share Posted February 12, 2006 printing should be the easy part from help _FilePrint -------------------------------------------------------------------------------- Prints a plain text file. #include <File.au3> _FilePrint ( $s_File [, $i_Show]) Parameters $s_File The file to print. $i_Show The state of the window. (default = @SW_HIDE) 8) Link to comment Share on other sites More sharing options...
Dutchman Posted February 12, 2006 Author Share Posted February 12, 2006 Wow, I was still working on the dummy code, trying to figure out what needs to happen and in what order. I appreciate all the work that has been done to achieve this. I'm still trying to decipher what each of the steps accomplish in the overall effort. I want to get it done, but I also want to learn to write the code to script it. As I'm learning this stuff I want to be able to write a setup so anyone can simply associate the file type with the program it is to open. Later, when thats done, I want to be able to attach the file, after compiling, to an avedesk icon. Each icon represents one of two printers that I own; one laser, one inkjet. Depending upon the printer that I drag and drop the file to, it automatically directs it to the right one...while still opening and closing the appropriate program to facilitate the actual print job. If anyone has any comments that they'd like to add to the code to help me decipher whats going on in the process, I'd appreciate it. Thanks. Link to comment Share on other sites More sharing options...
mikeytown2 Posted February 12, 2006 Share Posted February 12, 2006 The code that i gave you has 3 basic functions... Part1The If block that has $cmdline[0] will have the open dialog box popup if you run the program with out dropping anything on the icon. If you do drop a file on the icon then it will grab it and store the file location in the variable $fn. so from a command line it would look something like this...c:\autoitPrint.exe "c:\my docs\doc.xls" the $fn is then set to c:\my docs\doc.xlsPart 2This opens the file using the start command, but it doesn't work if you have a space anywhere in the file name, like we do above. So what the StringReplace part does is it turns c:\my docs\doc.xls Intoc:\"my docs\doc.xls"and then the run command does thisstart c:\"my docs\doc.xls"Part 3The While loop here is looking for the open window. i use the last part of the file name doc.xls and trim the string down so it says do. I made it trim off the last letter of the name of the document because if you open up a html file then this program doesn't work. if your only going to open files that have a 3 letter extension then change the 6 to a 5 in this line...$title = StringTrimRight($title[$title[0]], 6)So once it has the name of the file it looks for any window that has that string in it. once it found it, the program then minimizes it. the loop terminates once that window has the state of minimized.One thing that will help you out greatly is too look up every command that i used in the program in the help file. i use the help file non stop when i code autoit. i usually have 2 open actually. the autoit help file is your best friend, especially the index... that is a life saver. Email: POP3 & SMTP using SSL/TLS (OpenSSL)Email: IMAPEmail: Base64 & SMTP login & Send email direct to MX Server (thanks blindwig)Win: Hook Registry ChangesWin: Read/Write to Alternate Data Streams (ini example)Utility: GPS Distance Calculations, Vincenty and Haversine formulas; angles and elevationUtility: Dell Laser Printer (3000-5100) - Print LoggerUtility: Reset Router when Wireless Link FailsUtility: ImageMagick Batch jpg ProcessorVideo HCenc Batch FrontendVideo: *DEAD* YouTube Video Encoder (avs/avi to flv)Software On CD's I Like<<back|track3 Ultimate Boot CD for Windows SpinRite Ubuntu ophcrack Link to comment Share on other sites More sharing options...
Dutchman Posted February 13, 2006 Author Share Posted February 13, 2006 O.K. I have a pretty good grasp on the provided code, and have added a logging function to it and the printing function too. Works pretty slick! The code provided works well. I couldn't have done that so quickly. Now I'm trying to figure out how to get the current default printer, save it, set the second printer as default, go ahead and print, and when done, reset the default printer back to what it was. This is so I can print to a given printer just by dragging it to the appropriate icon. Is there a better way of doing this? Also is it possible to use a .png image as an input device...in much the same way as a widget is used? Also can a simple input box have an image background instead of color? I'm trying to figure out what the next phase should be? ) Link to comment Share on other sites More sharing options...
kapowdude Posted February 13, 2006 Share Posted February 13, 2006 well uhhh not to ruin your ingenioius idea... I believe windows does this already. try dragging a file onto a printer not that using auto it is a bad idea Link to comment Share on other sites More sharing options...
Dutchman Posted February 13, 2006 Author Share Posted February 13, 2006 Well, if you assign an icon to the desktop it will do it. But there are a lot of drawbacks to doing it. Doing it this way will allow me to customize the process and I'll learn something new too that I can use in future processes. If you have some useful ideas as to how to facilitate this customizable drag-n-drop printing procedure, I'd like to hear from you again. Thanks. Link to comment Share on other sites More sharing options...
jefhal Posted February 15, 2006 Share Posted February 15, 2006 (edited) Now I'm trying to figure out how to get the current default printer, save it, set the second printer as default, go ahead and print, and when done, reset the default printer back to what it was.This might help. Here is a simple vbs script that will change the default printer from one to another. Perhaps you can write from AutoIT to a file script.vbs and change the contents based on which printer you want to be the default. Then have AutoIT run the vbs script to do the change: vbs-vbs-vbs-vbs!!! Option Explicit Dim oNetwork, sPrintPath, sLocate Set oNetwork = CreateObject("WScript.Network") sLocate = InputBox("Where are you? Type 'Lab', or 'SSBack'.") Select Case sLocate Case "Lab" sPrintPath = "\\staff\Student Services - Front Office" Case "SSBack" sPrintPath = "\\staff\Student Services - Back Hall" Case "Main" sPrintPath = "\\staff\Main Office" Case Else Wscript.Echo "That is not a valid choice." :Wscript.Quit End Select oNetwork.AddWindowsPrinterConnection sPrintPath oNetwork.SetDefaultPrinter sPrintPath Or, maybe an AutoIT guru can convert the above vbs to AutoIT? Edited February 15, 2006 by jefhal ...by the way, it's pronounced: "JIF"... Bob Berry --- inventor of the GIF format Link to comment Share on other sites More sharing options...
acideax Posted February 15, 2006 Share Posted February 15, 2006 I can try and help with some vbs.. but not the AutoIT code, This is my first post... the last company I worked for had old netware systems that needed to remove old printers from the old servers and map a printer on the new print servers, and we could go desk to desk logging off users and doing it the long way round, so I cam up with the following script to add a new printer and check for a old one then delete the old one and set the new one as default I hope it helps. CODE ------------------------------------------------------------------------------------------------------------------------------ strPrinter="\\ukkinprt01\ukkinprt066" Set WshNetwork = CreateObject("WScript.Network") Set WshShell = CreateObject("WScript.Shell") WshNetwork.AddWindowsPrinterConnection strPrinter WshNetwork.SetDefaultPrinter strPrinter MsgBox strPrinter & " Printer connected and set as the default printer" Set WshNetwork = WScript.CreateObject("WScript.Network") PrinterPath = "\\ukkinfap02\ukkinprt066" On Error Resume Next WshNetwork.RemovePrinterConnection PrinterPath, true, true If Err.Number = 0 Then MsgBox PrinterPath & " Printer Removed" MsgBox "Default printer is now " & strPrinter End If On Error Goto 0 ------------------------------------------------------------------------------------------------------------------------------- You only need two tools in life: WD40 and Duct Tape.If it moves and it shouldn't, use Duct Tape.If it should move but doesnt, use WD40. Link to comment Share on other sites More sharing options...
Dutchman Posted February 15, 2006 Author Share Posted February 15, 2006 Thanks for the help. I can kinda make out what the VBS script is doing...Let me cogitate on it for a little while. I've kinda taken a diversion from this aspect to chase down the GUI portion of it. I'm trying to figure out how the concept of the recycle bin works, cause I want to use that as the model for my user interface...only with printers. I have a clear mind of what I want it all to look like...I'm still just trying to figure out how to bring it all together. The donations in script however has been wonderful. I really think this will work well. Link to comment Share on other sites More sharing options...
acideax Posted February 15, 2006 Share Posted February 15, 2006 well let me know if you beed anymore help and how your peoject turns out.. You only need two tools in life: WD40 and Duct Tape.If it moves and it shouldn't, use Duct Tape.If it should move but doesnt, use WD40. Link to comment Share on other sites More sharing options...
Dutchman Posted February 15, 2006 Author Share Posted February 15, 2006 The biggest thing you could do is decipher what the visual basic script does line by line, function by function, in a quasi psuedo code format. That would allow me to recode it by using autoit(if all functions are supported) and then I could learn something in the process. That would be a huge help. Thanks! Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now