 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
91v83y
Joined: 18 Nov 2009 Posts: 11
|
Posted: Wed Feb 24, 2010 6:29 pm Post subject: Need to add FileDelete to this script please |
|
|
This is a simple working script. I need to somehow add a command so that after the file is sent to the printer it is then deleted completely and the folder being watched is then empty.
Here is what I've got:
WatchDir = C:\Documents and Settings\KIP\Desktop\test
PrevFileList = `n
Loop, %WatchDir%\*.*
PrevFileList = %PrevFileList%%A_LoopFileName%`n
Loop
{
NewFileList = `n
Loop, %WatchDir%\*.*
{
NewFileList = %NewFileList%%A_LoopFileName%`n
IfNotInString, PrevFileList, %A_LoopFileName%
Run, print %WatchDir%\%A_LoopFileName%
}
PrevFileList = %NewFileList%
Sleep, 5000
} |
|
| Back to top |
|
 |
TLM
Joined: 21 Aug 2006 Posts: 2926 Location: The Shell
|
Posted: Wed Feb 24, 2010 7:06 pm Post subject: Re: Need to add FileDelete to this script please |
|
|
It would look something like this (Untested ofcourse)..
| Code: | WatchDir = C:\Documents and Settings\KIP\Desktop\test
PrevFileList = `n
Loop, %WatchDir%\*.*
PrevFileList = %PrevFileList%%A_LoopFileName%`n
Loop
{
NewFileList = `n
Loop, %WatchDir%\*.*
{
NewFileList = %NewFileList%%A_LoopFileName%`n
IfNotInString, PrevFileList, %A_LoopFileName%
RunWait, print %WatchDir%\%A_LoopFileName%
FileDelete, %WatchDir%\%A_LoopFileName%
}
PrevFileList = %NewFileList%
Sleep, 5000
} | I've never actually scripted a print job. Going to try this today.. _________________
paradigm.shift:=(•_•)┌П┐RTFM||^.*∞ |
|
| Back to top |
|
 |
Guest
|
Posted: Wed Feb 24, 2010 7:09 pm Post subject: Re: Need to add FileDelete to this script please |
|
|
| That was the 1st thing I thought of too, but I don't think you can wait for a verb (print) (or you can do it, but I think it returns immediately anyway)...so I think Sleep, 3019 or something would be more reliable, it just needs to start printing before you delete it... |
|
| Back to top |
|
 |
91v83y
Joined: 18 Nov 2009 Posts: 11
|
Posted: Wed Feb 24, 2010 7:21 pm Post subject: |
|
|
| You guys are KILLER!! Thx 4 the help. |
|
| Back to top |
|
 |
None
Joined: 28 Nov 2009 Posts: 3086
|
Posted: Wed Feb 24, 2010 7:25 pm Post subject: |
|
|
If you are gonig to delete the file after printing then the folder will be empty most of the time?
If yes you don't need to check for existing files
Also untested
| Code: | WatchDir = C:\Documents and Settings\KIP\Desktop\test
Loop
{
Loop, %WatchDir%\*.*
{
RunWait, print %WatchDir%\%A_LoopFileName%
FileDelete, %WatchDir%\%A_LoopFileName%
}
Sleep, 5000
} |
|
|
| Back to top |
|
 |
Guest
|
Posted: Wed Feb 24, 2010 7:39 pm Post subject: |
|
|
My testing script...
| Code: | filesrc=%A_ScriptName%.html
fileprint=%A_ScriptName%.print-tmp.html
FileCopy, %filesrc%, %fileprint%
FileAppend, % " " A_Now, %fileprint%
;// *** HERE *** Put this where your Run is...
ts:=A_TickCount
;//RunWait, print %fileprint%
p_hwnd:=RunWaitReady("print " fileprint)
;// when printing html, I get a print dialog, so wait for it to close...
WinWaitClose
ms:=A_TickCount-ts
;// extra sleep, if necessary...
;//Sleep, 3019
FileDelete, %fileprint%
;// *** /HERE *** Put this where your Run is...
msgbox, Wait Time: %ms%ms
return
;// Future Base.ahi...
RunWaitReady(p_cmd="") {
p_hwnd:=WinExist("a")
Run, %p_cmd%
WinWaitNotActive, ahk_id %p_hwnd%
Sleep, 19
return p_hwnd:=WinExist("a")
} |
|
|
| Back to top |
|
 |
TLM
Joined: 21 Aug 2006 Posts: 2926 Location: The Shell
|
Posted: Wed Feb 24, 2010 8:11 pm Post subject: |
|
|
Just tested script printing. Was able to come up with a simple 'non verb', reliable version that does not need a custom function (unless this is the exact same as the verb print ).
| Code: | RunWait, %comspec% /c "print /d:\\HPCOMPUTER\HPOffice C:\testfile.txt",,Hide ; This was tested over my network printer.
msgbox Print complete! | For some reason normal conventions do not work. That said, do not separate the arguments with quotes like you would normally!
Heres the usage for print:
| MS Help wrote: | PrintSends a text file to a printer.
Syntax
print [/d:Printer] [Drive:][Path] FileName [ ...]
Parameters
/d:Printer
Specifies the printer on which you want to print the job. You can specify a local printer by specifying the port on your computer to which the printer is connected. Valid values for parallel ports are LPT1, LPT2, and LPT3. Valid values for serial ports are COM1, COM2, COM3, and COM4. You can also specify a network printer by its queue name (\\ServerName\ShareName). If you do not specify a printer, the print job is sent to LPT1.
Drive:
Specifies the logical or physical drive on which the file you want to print is located. This parameter is not required if the file you want to print is located on the current drive.
Path
Specifies where, on the drive, the file you want to print is located. This parameter is not required if the file you want to print is located in the current directory.
FileName [...]
Required. Specifies, by name, the file you want to print. You can include multiple files in one command.
/?
Displays help at the command prompt.
Remarks
A file can print in the background if you send it to a printer connected to a serial or parallel port on the local computer.
Many programs have their own print commands. You should use the print command for a program to print files that you create with that program.
You can perform many configuration tasks from the command line by using the mode command. For more information about configuring a printer connected to a parallel port, configuring a printer connected to a serial port, displaying the status of a printer, or preparing a printer for code page switching, see mode in Related Topics.
Examples
To send the file Report.txt in the current directory to a printer connected to LPT2 on the local computer, type:
print /d:LPT2 report.txt
To send the file Report.txt in the c:\Accounting directory to the Printer1 print queue on the \\CopyRoom server, type:
print /d:\\copyroom\printer1 c:\accounting\report.txt |
_________________
paradigm.shift:=(•_•)┌П┐RTFM||^.*∞
Last edited by TLM on Wed Feb 24, 2010 8:20 pm; edited 1 time in total |
|
| Back to top |
|
 |
TLM
Joined: 21 Aug 2006 Posts: 2926 Location: The Shell
|
Posted: Wed Feb 24, 2010 8:17 pm Post subject: |
|
|
| TLM wrote: | | ...For some reason normal conventions do not work.... | Minor hickup..
Looks like directory variables have to be converted to 8.3 short names for the command to work. A simple Loop, FilePattern can be used to convert directories with the long format. Please post if you need help with this .. _________________
paradigm.shift:=(•_•)┌П┐RTFM||^.*∞ |
|
| Back to top |
|
 |
Guest
|
Posted: Thu Feb 25, 2010 9:19 am Post subject: |
|
|
| TLM wrote: | | ...that does not need a custom function... |
...my "custom function" is a series of commands I always use to "run & wait for the window to be ready"...kinda a middle ground of Run & RunWait. The pid option to Run/RunWait is not reliable, so instead, I get the current window, Run, then wait for the current window to change, most likely a window opened by the Run...I did not write this function just now for this...
| TLM wrote: | | ...(unless this is the exact same as the verb print... |
...no, that is not the same (which is a good thing), at 1st I was thinking I needed some print.exe I've never knew about, then I noticed you ran %comspec%, so I opened a command prompt & typed print, seems I do have it, whatever it is. That might be a good option to print text files, but not HTML or anything else (unless you want the source!). The print verb runs the native application associated with that extension (if it has a print verb).
So I like your solution for text files, but I see no reason to not also use my function...unless %comspec% actually waits long enough already... |
|
| Back to top |
|
 |
TLM
Joined: 21 Aug 2006 Posts: 2926 Location: The Shell
|
Posted: Thu Feb 25, 2010 12:34 pm Post subject: |
|
|
| Anonymous wrote: | ...no, that is not the same (which is a good thing), at 1st I was thinking I needed some print.exe I've never knew about, then I noticed you ran %comspec%, so I opened a command prompt & typed print, seems I do have it, whatever it is. That might be a good option to print text files, but not HTML or anything else (unless you want the source!). The print verb runs the native application associated with that extension (if it has a print verb).
So I like your solution for text files, but I see no reason to not also use my function...unless %comspec% actually waits long enough already... | .. uhh yea'rp print is built in (and quite antiquated) command that has seemed to be a survivor from the DOS days (hence the need for 8.3 format )..
You can find it and much more here: http://ss64.com/nt
I forgot to mention that your function is a pretty cool approach BTW. I made p_hwnd global so I could use it for something else  _________________
paradigm.shift:=(•_•)┌П┐RTFM||^.*∞ |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|