How to mount a network drive based on the IP address or wifi network

applescriptautomationmountNetworkwifi

When I am at work, I mount a number of shared drives to use during the day. At home, I mount drives on my home network for home use. Is there a way that I can automatically mount the correct drives based on the network I am connected to? Ideally I would do this based on IP address, as I connect via Ethernet cable at work.

Is it necessary to use AppleScript or a shell script? I have tools like Hazel and Keyboard Maestro at my disposal.

Thank you.

Best Answer

set homeip to "Enter Your Home IP Here"
set homedrive to "afp://PlzUpvoteThis.Answer"
set workdrive to "smb://FeelFreeToEdit.This"

set myIP to (do shell script "curl ipinfo.io/ip") // Gets ip


if myIP is homeip then // Checks if your ip matches your home ip
    do shell script "open " & homedrive
else
    do shell script "open " & workdrive
end if