I would like my Mac to automatically assign Default printer based on physical location (preferably) vs Wifi MAC address. I currently use Control Plane for this mission, but it has not been updated in a while and glitches a lot. I can not use Wifi name as in different locations in our organization, Wifi name remains the same. What would be the best way to do it?
You're right that setting printer defaults based on wifi SSID would not work, but I think the wifi MAC address should be different in different locations as it's tied to the access point. I'm not sure if you can access it easily from KM or not though. Perhaps Apple Script could find it.
That may work, and if it does, great! but I'm afraid that it won't, because that's going to tell you where your ISP is, not necessarily where you are. For example, I would get the same result for my home or work, because we both use the same ISP.
I have a potential solution that should be very reliable, but it's a little geeky.
Ok, it's a lot geeky.
What Ethernet device are you using?
The first thing you need to figure out is what Ethernet device you are using.
Chances are that it is either 'en0' or 'en1'.
Open Terminal.app and type ifconfig and hit return. Look for the IP address that matches what you are using for the network. (Open System Preferences » Network to see your IP.)
Get your Router's IP Address
I'm going to assume you are using 'en0' but if you are using 'en1' or something else, change that in the next line:
That's going to give you the IP Address of your router. Let's assume you got '192.168.1.1' for that.
Get the MAC Address of your Router
The MAC address of your router should be unique to that device. I think it is a safe assumption that if you are connected to that particular router, you will always be in the location.
(I'm not a networking expert, so it's possible that I'm wrong about that, but let's assume it's true for now.)
Once you have the IP address of the router, you can get the MAC address like this with this command (remember to replace '192.168.1.1' with the actual IP address of your router, from above):
arp 192.168.1.1
which should give you output that looks something like this:
? (192.168.1.1) at 12:12:db:17:5e:4d on en0 ifscope [ethernet]
The MAC address is the '12:12:db:17:5e:4d' part. So we need to narrow the arp output to just that field.
We can do that in (at least) two ways.
A) We can take the 4th field of the list: "?" is the first, "(192.168.1.1)" is the second, "at" is the 3rd, so the MAC address is the 4th. So if we replace the arp command with this:
arp 192.168.1.1 | awk '{print $4}'
then we should just get
12:12:db:17:5e:4d
B) We can split up the arp output by replacing each space with a 'newline' and then picking out just the line which has 5 colon ":" characters:
I put together the first part of this, including the shell script that saves to a variable, but you'll have to enter the ROUTER_MAC_ADDRESS of your router to the IF / ELSE parts of the macro.
To facilitate this, the macro will put the ROUTER_MAC_ADDRESS on your clipboard after it runs if it doesn't match any of the previous IF / ELSE statements.
Is this too nerdy to work? If you need help / clarification, I'd be happy to help.
I have just set this up for myself too, so I'll be able to test it tomorrow when I go into the office.
Just modified your script with my MAC addresses. Works fantastic! Exactly what I needed. Thank you very much. Your script also makes it very easy adding new locations or new routers/MAC addresses of the same location. Really appreciate your help.
In most cases, you can follow this procedure to locate your MAC address : Select Settings > About Device > Status. A WiFi Address or WiFi MAC Address displays. This is your device's MAC address . Check here to check more information related to this.
To make the script work, change WiFi name to the one you use. Run lpstat -p in terminal and change all the printer names I used to the printer names you use. Run Location helper in each one of the locations you use your laptop and replace my coordinates with yours (You can run this part of the script separately to get the truncated numbers: