AutoHotkey Community

It is currently May 27th, 2012, 4:25 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 10 posts ] 
Author Message
PostPosted: February 24th, 2010, 7:29 pm 
Offline

Joined: November 18th, 2009, 2:07 pm
Posts: 11
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
}


Report this post
Top
 Profile  
Reply with quote  
PostPosted: February 24th, 2010, 8:06 pm 
Offline

Joined: August 21st, 2006, 7:07 pm
Posts: 2925
Location: The Shell
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..

_________________
Imageparadigm.shift:=(•_•)┌П┐RTFM||^.*∞


Report this post
Top
 Profile  
Reply with quote  
PostPosted: February 24th, 2010, 8:09 pm 
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...


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: February 24th, 2010, 8:21 pm 
Offline

Joined: November 18th, 2009, 2:07 pm
Posts: 11
You guys are KILLER!! Thx 4 the help.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 24th, 2010, 8:25 pm 
Offline

Joined: November 28th, 2009, 4:45 am
Posts: 3089
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
}


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 24th, 2010, 8:39 pm 
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")
}


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: February 24th, 2010, 9:11 pm 
Offline

Joined: August 21st, 2006, 7:07 pm
Posts: 2925
Location: The Shell
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 :oops: :lol:).

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

_________________
Imageparadigm.shift:=(•_•)┌П┐RTFM||^.*∞


Last edited by TLM on February 24th, 2010, 9:20 pm, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 24th, 2010, 9:17 pm 
Offline

Joined: August 21st, 2006, 7:07 pm
Posts: 2925
Location: The Shell
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 ;)..

_________________
Imageparadigm.shift:=(•_•)┌П┐RTFM||^.*∞


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 25th, 2010, 10:19 am 
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...


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: February 25th, 2010, 1:34 pm 
Offline

Joined: August 21st, 2006, 7:07 pm
Posts: 2925
Location: The Shell
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 :roll:)..
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 :)

_________________
Imageparadigm.shift:=(•_•)┌П┐RTFM||^.*∞


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 10 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: Bing [Bot], Mickers, rbrtryn, Yahoo [Bot] and 68 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group