 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
eagle00789
Joined: 27 Nov 2006 Posts: 61 Location: Heerlen Country: Netherlands
|
Posted: Tue May 29, 2007 2:52 pm Post subject: Printerfunctions |
|
|
I have collected several usefull printerfunctions and have them combined in a single ahk-file.
- GetInstalledPrinters(Delimiter="|",Default=True) returns a list of all installed printers followed by the delimiter.
- The delimiter can be changed by setting the delimiter parameter.
- The Default parameter is to get the default selected printer with a double delimiter behind it.
- GetDefaultPrinter() is just to get the currently selected default printer
- SetDefaultPrinter(sPrinter) is to change the default printer.
- The parameter must be the COMPLETE name of the printer.
you can find them here: http://www.autohotkey.net/~eagle00789/Functions/printerfunctions.ahk
Current Version: 1.0.1
Version History
1.0.1: Trimmed of the trailing delimiter character when using GetInstalledPrinters (thanks to Titan)
1.0.0: Initial Release
Last edited by eagle00789 on Wed May 30, 2007 2:44 pm; edited 1 time in total |
|
| Back to top |
|
 |
polyethene
Joined: 11 Aug 2004 Posts: 5244 Location: UK
|
Posted: Wed May 30, 2007 9:28 am Post subject: |
|
|
Thanks for sharing. A couple suggestions: use StringTrimRight, printerlist, printerlist, 1 before you return the list in GetInstalledPrinters() to remove the trailing delimiter, DllCalls can be simplified to just winspool.drv\... since it's automatically assumed to be in the system's PATH. _________________ GitHub • Scripts • IronAHK • Contact by email not private message. |
|
| Back to top |
|
 |
eagle00789
Joined: 27 Nov 2006 Posts: 61 Location: Heerlen Country: Netherlands
|
Posted: Wed May 30, 2007 2:43 pm Post subject: |
|
|
i updated it to use the following line: | Code: | | StringTrimRight, printerlist, printerlist, StrLen(Delimiter) | because if someone uses a `n delimiter, you have to trim 2 characters off |
|
| Back to top |
|
 |
toralf
Joined: 31 Jan 2005 Posts: 3910 Location: Bremen, Germany
|
Posted: Wed May 30, 2007 2:50 pm Post subject: |
|
|
Acctually No. `n is a single character.But you are save if the user specifies a string of charcaters as delimiters. Which might be strange but possible. _________________ Ciao
toralf  |
|
| Back to top |
|
 |
ahklerner
Joined: 26 Jun 2006 Posts: 1381 Location: USA
|
Posted: Wed May 30, 2007 4:53 pm Post subject: |
|
|
Should it not be
| Code: | | StringTrimRight, printerlist, printerlist, % StrLen(Delimiter) |
|
|
| Back to top |
|
 |
polyethene
Joined: 11 Aug 2004 Posts: 5244 Location: UK
|
Posted: Wed May 30, 2007 5:36 pm Post subject: |
|
|
That parameter accepts expressions, so there's no need for % _________________ GitHub • Scripts • IronAHK • Contact by email not private message. |
|
| Back to top |
|
 |
Dave Campbell
Joined: 09 Jun 2005 Posts: 27 Location: Clearwater, Florida
|
Posted: Fri Sep 07, 2007 9:31 pm Post subject: Re: Printerfunctions |
|
|
| eagle00789 wrote: | I have collected several usefull printerfunctions and have them combined in a single ahk-file.
- GetInstalledPrinters(Delimiter="|",Default=True) returns a list of all installed printers followed by the delimiter.
- The delimiter can be changed by setting the delimiter parameter.
- The Default parameter is to get the default selected printer with a double delimiter behind it.
- GetDefaultPrinter() is just to get the currently selected default printer
- SetDefaultPrinter(sPrinter) is to change the default printer.
- The parameter must be the COMPLETE name of the printer.
you can find them here: http://www.autohotkey.net/~eagle00789/Functions/printerfunctions.ahk
Current Version: 1.0.1
Version History
1.0.1: Trimmed of the trailing delimiter character when using GetInstalledPrinters (thanks to Titan)
1.0.0: Initial Release |
This is just the routine I need to set my default printer. The only problem is it doesn't set it. I tried running the list of installed printers but I don't know where I'm supposed to see the list.
I'm running WinXP Pro SP2 and did find the default printer listed in the registry. Am I missing something? |
|
| Back to top |
|
 |
engunneer
Joined: 30 Aug 2005 Posts: 8255 Location: Maywood, IL
|
Posted: Fri Sep 07, 2007 9:39 pm Post subject: |
|
|
| Code: |
list:=GetInstalledPrinters()
msgbox, % list
|
_________________
(Common Answers) |
|
| Back to top |
|
 |
corrupt
Joined: 29 Dec 2004 Posts: 2485
|
Posted: Sat Sep 08, 2007 2:49 am Post subject: |
|
|
Cool
Request: functions to print text, rtf |
|
| Back to top |
|
 |
engunneer
Joined: 30 Aug 2005 Posts: 8255 Location: Maywood, IL
|
Posted: Sat Sep 08, 2007 3:01 am Post subject: |
|
|
without saving to a file first? If you don't mind a temp file, you can do this with Run. if you delete it fast enough, it will never be written to disk. _________________
(Common Answers) |
|
| Back to top |
|
 |
corrupt
Joined: 29 Dec 2004 Posts: 2485
|
Posted: Sat Sep 08, 2007 4:00 am Post subject: |
|
|
| engunneer wrote: | | without saving to a file first? If you don't mind a temp file, you can do this with Run. if you delete it fast enough, it will never be written to disk. | Yes, without saving to a file first would be great. I typically only use temp files when other methods aren't available or when in a hurry or when being lazy... |
|
| Back to top |
|
 |
Dave Campbell
Joined: 09 Jun 2005 Posts: 27 Location: Clearwater, Florida
|
Posted: Sat Sep 08, 2007 11:02 am Post subject: |
|
|
| engunneer wrote: | | Code: |
list:=GetInstalledPrinters()
msgbox, % list
|
|
After I figured out where to put that sniplet, it worked great. At first I included it as part of the routine, then I discovered it was designed to CALL the routine, not be a part of it. My in depth understanding of the mechanics of getting this to work is pretty weak, so I appreciate your help teaching me. I have the list of printers working now but I still don't understand how to apply the code for setting the default printer.
Do you have a corresponding idea or sniplet for calling that routine? |
|
| Back to top |
|
 |
Dave Campbell
Joined: 09 Jun 2005 Posts: 27 Location: Clearwater, Florida
|
Posted: Mon Sep 10, 2007 1:18 am Post subject: |
|
|
| Quote: | After I figured out where to put that sniplet, it worked great. At first I included it as part of the routine, then I discovered it was designed to CALL the routine, not be a part of it. My in depth understanding of the mechanics of getting this to work is pretty weak, so I appreciate your help teaching me. I have the list of printers working now but I still don't understand how to apply the code for setting the default printer.
Do you have a corresponding idea or sniplet for calling that routine? |
I'm attempting to write a script that will let me set the default printer from a list of installed printers. Ideally, I'd like to have an InputBox with a numbered list of all installed printers and choose a printer number to be set as default.
I've gotten the script to write out an ordered and numbered list of installed printers to a text file and am able to read from that list to get the printer name and to actually set the default printer. I manually typed in the list of printer names and order number into the InputBox which works like a charm. The only problem is that as soon as I delete a printer or add one, the list is obsolete.
I just can't figure out how to dynamically get the contents of that file into the InputBox. I could even settled with a MsbBox. |
|
| Back to top |
|
 |
engunneer
Joined: 30 Aug 2005 Posts: 8255 Location: Maywood, IL
|
Posted: Mon Sep 10, 2007 5:20 pm Post subject: |
|
|
please post your code. We can easily convert it to use a GUI dropdownlist, or a bunch of radio buttons, and it will be much easier to use.
you can also post in in the ask for help section if you want, and then post the result back here. _________________
(Common Answers) |
|
| Back to top |
|
 |
Dave Campbell
Joined: 09 Jun 2005 Posts: 27 Location: Clearwater, Florida
|
Posted: Mon Sep 10, 2007 6:43 pm Post subject: |
|
|
| engunneer wrote: | please post your code. We can easily convert it to use a GUI dropdownlist, or a bunch of radio buttons, and it will be much easier to use.
you can also post in in the ask for help section if you want, and then post the result back here. |
| Code: |
FileDelete D:\MyDocuments\AutoHotKey\printers.txt
FileDelete D:\MyDocuments\AutoHotKey\printer names.txt
;
; Get list of installed printers
;
list:=GetInstalledPrinters()
;
; Prompt for default printer
;
; msgbox, % list
SetDefaultPrinter(sPrinter)
{
DllCall(A_WinDir . "\system\winspool.drv\SetDefaultPrinterA", "str", sPrinter)
}
InputBox, ItemNumber,Select a Default Printer, Pick a printer you want to be set to default:`n`n1. 1 page Brother`n2. 2 page Brother`n3. 2 page top2top Brother`n4. Adobe PDF`n5. ClickBook Printer`n6. Dell Photo AIO Printer 926`n7. EPSON Stylus Photo R220 Series`n8. Microsoft Office Document Image Writer`n9. PDF Check`n`nEnter a single digit representing the printer you want.,,340,305,,,,,4
ArrayCount = 0
Loop, Read, D:\MyDocuments\AutoHotKey\printers.txt ; This loop retrieves each line from the file, one at a time.
{
ArrayCount += 1 ; Keep track of how many items are in the array.
Array%ArrayCount% := A_LoopReadLine ; Store in next array element.
If ArrayCount = %ItemNumber%
{
var2=%A_LoopReadLine%
; msgbox A_LoopReadLine = x%A_LoopReadLine%x var2=y%var2%y
; result := SetDefaultPrinter(A_LoopReadLine)
result := SetDefaultPrinter(var2)
msgbox ,1,Set Default Printer,The default printer has been set to %A_LoopReadLine%.,10
return
}
}
GetInstalledPrinters(Delimiter="|",Default=True)
{
if (Default = True)
{
regread,defaultPrinter,HKCU,Software\Microsoft\Windows NT\CurrentVersion\Windows,device
stringsplit,defaultName,defaultPrinter,`,
defaultName := defaultName1
printerlist =
PrinterCount=0
loop,HKCU,Software\Microsoft\Windows NT\CurrentVersion\devices
{
if (A_LoopRegName = defaultname)
printerlist = %printerlist%%A_loopRegName%%Delimiter%%Delimiter%
else printerlist = %printerlist%%A_loopRegName%%Delimiter%
PrinterCount += 1
; msgbox %PrinterCount%. %A_loopRegName%
FileAppend %PrinterCount%. %A_loopRegName% `n,D:\MyDocuments\AutoHotKey\printer names.txt
FileAppend %A_loopRegName% `n,D:\MyDocuments\AutoHotKey\printers.txt
}
}
else
{
printerlist =
loop,HKCU,Software\Microsoft\Windows NT\CurrentVersion\devices
{
printerlist = %printerlist%%A_loopRegName%%Delimiter%
}
}
StringTrimRight, printerlist, printerlist, StrLen(Delimiter)
return %printerlist%
}
return
|
WOW ! ! ! That's the best offer I've had all day. Thank you very much.
I'm looking for the simplest results, user friendliness wise. I think the idea of radio buttons would be swift, or maybe to be able to double click on the desired printer from a text window.
I really look forward to seeing the code. |
|
| 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
|