Jump to content

How to change default printer based on office or home network?


Recommended Posts

1. Is there a workflow that can be used to manually trigger, list all printer, select and change default printer?

 

2. Is it possible to go further to set it based on office or home wifi network. Request to share your experience on this or guide. I got below from chatGPT:

 

Changing the default printer based on your network location (home or office) can be automated on a macOS system using a combination of AppleScript, shell commands, and Location-aware settings. There isn't a direct built-in feature in macOS to automatically switch printers based on network location, but you can achieve this through a somewhat manual setup using network locations in System Preferences and running scripts when these locations change.

Setting Up Network Locations

  1. Create Network Locations:
    • Go to Apple Menu > System Preferences > Network.
    • Click the Location drop-down menu at the top and choose Edit Locations.
    • Use the "+" button to add new locations, naming one "Home" and another "Office" or as per your preference.
    • Configure the network settings for each location as needed, such as Wi-Fi network SSID, and then switch between them as you move between your home and office.

Script to Change Default Printer

You can write an AppleScript or shell script to change the default printer. Here's a simple example of how to do it in AppleScript:

 
applescriptCopy code
-- AppleScript to set the default printer set currentLocation to "Home" -- or "Office", you can automate this part by detecting the network SSID if currentLocation is "Home" then set defaultPrinter to "Home_Printer_Name" -- Replace with your home printer's name else if currentLocation is "Office" then set defaultPrinter to "Office_Printer_Name" -- Replace with your office printer's name end if do shell script "lpoptions -d " & defaultPrinter

Automating the Process

Automating this process involves detecting when your network location changes and then running the appropriate script. This can be more complex, as macOS does not provide a direct way to trigger scripts on network location changes. However, you can use third-party tools or create a custom solution to monitor network changes and trigger the script.

  1. Third-Party Automation Tools: Tools like Keyboard Maestro or Hazel can be configured to run scripts based on certain triggers, such as connecting to a specific Wi-Fi network.

  2. Custom Solution: Write a daemon or use launchd to periodically check the current Wi-Fi SSID or network location and run the AppleScript to switch the default printer accordingly. This requires a more advanced understanding of macOS scripting and system configuration.

Steps for a Custom Solution

  1. Write a script that checks the current network SSID using a shell command like networksetup or by parsing system logs.
  2. Use launchd to run this script at regular intervals or upon network changes.
  3. The script then determines the location (home or office) based on the SSID and runs the appropriate AppleScript to change the default printer.

Note

This solution requires a bit of setup and possibly learning more about macOS scripting and automation. Depending on your macOS version, some commands or steps might differ, and you may need administrative privileges to change network settings or add launchd tasks.

For more detailed instructions or help with scripting, you might consider looking into macOS scripting communities or forums, as well as the official AppleScript and launchd documentation.

 

 

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...