It is supposed to use AppleScript for automatic mounting of network drives. How to write a script so that depending on the WiFi access point to which the Mac is currently connected, the network drive address changes?

Say:

property myDisks : {"AirDisk 500GB", "AirDisk 320"} set mountedDisks to paragraphs of (do shell script "/bin/ls /Volumes") repeat with aDisk in myDisks if aDisk is not in mountedDisks then # если WiFi = "Вася" # mount volume "afp://airport-extreme-1.local/AirDisk 500GB" # иначе WiFi = "Федя" # mount volume "afp://airport-extreme-2.local/AirDisk 320" end if end repeat 

    1 answer 1

    I had to hard google and strain the brain. But I achieved what I wanted!

     set mySSID to do shell script "/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport -I | awk '/ SSID/ {print substr($0, index($0, $2))}'" if ((mySSID as string) is equal to "ssid1") then mountVolume("AFPVolume", "192.168.200.20", "user1", "pass1", "/Volumes/AFPVolume") else if ((mySSID as string) is equal to "ssid2") then mountVolume("NAS", "192.168.200.30", "user2", "pass2", "/Volumes/NAS") . . . end if on mountVolume(serverPath, serverName, serverUser, serverPassword, localNode) if isMounted(localNode) then return end if set networkProtocol to "afp" if createLocalNode(localNode) then set mountURL to networkProtocol & "://" & serverUser & ":" & serverPassword & "@" & serverName & "/" & serverPath do shell script "mount -t " & networkProtocol & space & quoted form of mountURL & space & quoted form of localNode end if end mountVolume on createLocalNode(localNode) if not fileExists(localNode) then do shell script "mkdir " & quoted form of localNode & "; echo $?" return fileExists(localNode) end if if (do shell script "ls -A " & quoted form of localNode & " | wc -l") as integer is 0 then return true else return false end if end createLocalNode on unMount(localNode) if not isMounted(localNode) then return end if do shell script "diskutil unmount " & quoted form of localNode end unMount on fileExists(posixPath) return not ((do shell script "test -e " & quoted form of posixPath & "; echo $?") as integer) as boolean end fileExists on isMounted(localNode) return (do shell script "mount") contains (" on " & localNode & " (") end isMounted