AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

WORKS: switch default printer upon hotkey trigger

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions
View previous topic :: View next topic  
Author Message
controlfreak



Joined: 13 Apr 2007
Posts: 7
Location: Unterschleißheim, BY, DE

PostPosted: Sat Apr 14, 2007 2:21 pm    Post subject: WORKS: switch default printer upon hotkey trigger Reply with quote

Idea

Thanks to Sean and his great idea, I could think of a solution to switch my default printer within a given list (of, in this case, 2 printers).

Of course, you could think of something like cycling through a whole array of printers.

Code:
LWin & PrintScreen::

Printer1 = Minotaurus   ; change according to your Printer1
Printer2 = Adobe PDF   ; change according to your Printer2

If (GetDefaultPrinter() = Printer1)
{
   SetDefaultPrinter(Printer2)
}
Else
{
   SetDefaultPrinter(Printer1)
}

GetDefaultPrinter()
{
   nSize := VarSetCapacity(gPrinter, 256)
   DllCall(A_WinDir . "\system\winspool.drv\GetDefaultPrinterA", "str", gPrinter, "UintP", nSize)
   Return gPrinter
}
      
SetDefaultPrinter(sPrinter)
{
   DllCall(A_WinDir . "\system\winspool.drv\SetDefaultPrinterA", "str", sPrinter)
   TrayTip, AHK » Drucker und Faxgeräte, %sPrinter% wurde als Standard definiert., 10, 17
   ; the English translation would be:
   ; AHK » Printers and Faxes, %sPrinter% set as default printer.
   Sleep, 3000
   TrayTip
}
return


Note that the tray tip causes a delay of 3 seconds before another switch can be triggered.

Update 2008-02-09: on Vista-based machines, please replace the two "\system\" sections by "\System32\". Enjoy!

I hope this comes in handy to somebody as it did for me. Very Happy
Christian Sentis
_________________
On-on!


Last edited by controlfreak on Sat Feb 09, 2008 10:31 am; edited 3 times in total
Back to top
View user's profile Send private message
Justineo14



Joined: 30 Oct 2006
Posts: 43

PostPosted: Mon Apr 16, 2007 7:57 am    Post subject: Reply with quote

Why don't you make a pop up menu??
_________________
Tex© Click here to mail me
Back to top
View user's profile Send private message MSN Messenger
randy@ahk
Guest





PostPosted: Mon Aug 20, 2007 3:48 pm    Post subject: Doesnt work.. Reply with quote

Thanx for the script, the idea sounds very usefull. But it doesnt work on my windows version (XP). It shows the message and all seems well, but my printer doesnt get changed. I tried a few different name styles for my printers, but all dont work.

Could it be that my version of winspool.drv doesnt support printer change?

Any idea?

Thanx!
Randy
Back to top
randy@ahk
Guest





PostPosted: Mon Aug 20, 2007 3:56 pm    Post subject: Apologies,.. found the answer.. Reply with quote

Embarassed

I found the answer in the post you mentioned at the top, I overlooked that one. Sorry..

In my case it missed a network adress: "/a100/".

Again, great idea... for me it's very usefull! Very Happy

Greets,
Randy
Back to top
Guest






PostPosted: Mon Aug 20, 2007 7:48 pm    Post subject: Re: Apologies,.. found the answer.. Reply with quote

randy@ahk wrote:
Again, great idea... for me it's very usefull! Very Happy


Randy,

Thank you for your appreciated feedback! Always nice to hear Smile

Christian
Back to top
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group