I wonder if is it possible to automatically switch the default printer according to the wifi network to which the computer is connected.
Apparently, windows has this feature
I wonder if is it possible to automatically switch the default printer according to the wifi network to which the computer is connected.
Apparently, windows has this feature
This answer does not need
sudo
privilegesI assume you have two places with WiFi connections and two different Network Printers. Your laptop is setup to connect to these two WiFi connections. You have also setup your laptop's printer setup to the two printers and you can print to these two printers when connected to the respective WiFi networks.
For simplicity I will call the:
I have written a bash script I call
changedefaultprinter.sh
you can name the file what you want and edit it as you wish. You will need to names of the WiFi and printers in the script to make it work.The Script
How to use:
Copy the script into a file
changedefaultprinter.sh
and save it in the location/home/$USER/bin
. If you don't have the folderbin
create it first. Make the file "executable". See How to make a file executable?Find out the names of your WiFi and the default printers you have already setup. You can do this in many ways. I use the terminal and the commands below:
Make sure you are connected to your Home WiFi and and the home printer is set as the default. Open a terminal by pressing Ctrl+Alt+T and enter the command:
This should show you the name of your WiFi. Copy this name from the terminal and paste it into the file above where it says
HomeWiFi
.Now to copy the name of the home printer use the command:
You will see something like:
Copy the name of the printer from the terminal and paste it into the file above where it says
HomePrinter
.OfficeWiFi
andOfficePrinter
in the script.Try it out:
In the terminal enter the command while connected to the home WiFi:
If all goes well you will see some text telling you your default printer is now set to your home printer. Do the same thing in the office to make sure it works there as well.
Make the script run when you login to the laptop
Open the application "Startup Application Preferences" and click on the button Add
Add a sensible name of the script so that you know what it does, and the location of the script as:
/home/$USER/bin/changedefaultprinter.sh
Where $USER is your username.
Click the Add to save the changes and close the "Startup Application Preferences" window. From now on every time you login to your laptop this script will run. It will determine which WiFi you are on and change the default printer.
This answer needs
sudo
privilegesI assume you have two places with WiFi connections and two different Network Printers. Your laptop is setup to connect to these two WiFi connections. You have also setup your laptop's printer setup to the two printers and you can print to these two printers when connected to the respective WiFi networks.
For simplicity I will call the:
I have written a bash script I call
10-changedefaultprinter
. You will need to add your username and the names of the WiFi and printers in the script to make it work.The Script
How to use:
10-changedefaultprinter
and save it in the location/home/$USER/
. If you save it in another location such as/home/$USER/bin
then use the commandcd /home/$USER/bin
to change the current directory in the terminal before using the the commands prefixed withsudo
below.your_username_goes_here
with your user name. You can find user username by typingecho $USER
in the terminal.Make sure you are connected to your Home WiFi and and the home printer is set as the default. Open a terminal by pressing Ctrl+Alt+T and enter the command:
This should show you the name of your WiFi. Copy this name from the terminal and paste it into the file above where it says
HomeWiFi
.Now to copy the name of the home printer use the command:
You will see something like:
Copy the name of the printer from the terminal and paste it into the file above where it says
HomePrinter
.OfficeWiFi
andOfficePrinter
in the script.Use the terminal and the following commands:
You may copy using the
cp
command or move using themv
command instead of creating a symbolic link usingln -s
above.Try it out:
Try this at home or in office:
If all goes well your default printer will change based on the WiFi you are connected to. From now on, your default printer will change based on the WiFi you are on.
If it does not work, check the syslog and look for lines with
nm-dispatcher
for errors.Hope this helps
Alessandro, I'm ashamed for how long I've been putting up with the same annoyance before I figured out how dead simple it really was...!
I've made a little project, which I think you might want to try out. Please let me know either way.
To install it, open up a terminal and enter the following (you don't need to type in the '#' and the number after it):
and you're all set. This is what you just did:
autorandr
package, which automatically runs whenever you (un)plug a display. If you prefer, you can also do this via a graphical software manager.~/.config/autorandr
folder.Henceforth, your laptop will automatically change the default printer for you.