Script to log on to Network share

steveosh
New Contributor

Hi there

We have a couple dozen MAC's . We use to have a script that was a JQ script, that when someone logs into the MAC, a network share drive would log into it. Since the IOS went to 10.10+ this script doesn't work.

Each person has their own network drive (home directory) where they can save files. It would check the AD, and log into ANY and ALL network drives that the person is permitted to view.

It would also connect any network printer that the person is suppose to see.

the script below:

Save the AppleScript as an Application

To allow the app to run at every login & as the user logging in, create a LaunchAgent. Use a plist editor to create a plist with the info below and save it as ca.ab.gprc.APPLICATIONNAME.plist in /Library/LaunchAgents/ with 755 permissions (chmod 755 ca.ab.gprc.APPLCATIONNAME.plist). Replace APPLICATIONNAME with the AppleScript Application Name.

##########################################################

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">

<plist version="1.0">

<dict>

<key>Label</key>

<string>ca.ab.gprc.MapDrives</string>

<key>Program</key>

<string>/Applications/MapDrives2.app/Contents/MacOS/applet</string>

<key>RunAtLoad</key>

<true/>

</dict>

</plist>

###########################################################

# Download ./jq and copy it to /usr/sbin (must use sudo).

I use PackageMaker (part of Xcode) to install files in the correct locations.

curl "https://my.xxxx.xx.xx/AppService/api/NetworkMappings?UserName=MDiPasquale&ComputerName=TAG028106" | jq '.[] | .NetworkPath' | cut -c 2- | sed 's:\\\\://:g' | sed 's:\\:/:g' | sed 's:.$::'

The above code grabs the network path of each record of the object and replaces the slashes; "\\" with "//" and "\" with "/". Cut removes the quotes at the beginning and the last sed command removes the quotes at the end. This works for command line but not applescript.

See the main body of code for the proper AppleScript command/format to achieve this.

Get Username and Tag Number. Define the URL for the json request.

et user to do shell script "whoami"
set tag to do shell script "hostname -s"
set link to "https://my.xxx.xxx.xx/AppService/api/NetworkMappings?UserName=" & user & "&ComputerName=" & tag

Get the number of disks currently mounted.

set diskLength to length of (list disks)

Get number of records in the json object.

Define the first record number in the object.

set recordLength to do shell script "curl " & quoted form of link & " | jq 'length'"
set recordNumber to 0

For each json record, determine if the object is a drive or printer and mount/install accordingly.

repeat recordLength times

# Define a variable pointing to the first record returned by list disks. # set diskItem to 1

try set networkPathVar to do shell script "curl " & quoted form of link & " | jq '.[" & recordNumber & "] | .NetworkPath' | cut -c 2- | sed 's:\\\\://:g' | sed 's:\\:/:g' | sed 's:.$::'" set deviceType to do shell script "curl " & quoted form of link & " | jq '.[" & recordNumber & "] | .Type'" on error return end try

if deviceType contains "Drive" then

set recordNumber to recordNumber + 1

# Check to see if the drive is already mounted. If not mount it.

# repeat diskLength times if networkPathVar does not contain items 1 thru diskLength of (list disks) then

mount volume "smb:" & networkPathVar

end if # end repeat

else

set recordNumber to recordNumber + 1 end if # End of Device Type IF
end repeat

0 REPLIES 0