I need to get a script that would map network drives based on a person's user name (we use AD to allow access). It used to work prior to 10.10.
We have a new Mac lab that is running 10.12.6. The old script is below.
I've installed jq from home-brew , but keep getting an error when I try to run it. (Also below)
Sorry I have no experience with AppleScript, and totally lost.
Any help would be appreciated
# Get Username and Tag Number. Define the URL for the json request.
set user to do shell script "whoami"
set tag to do shell script "hostname -s"
set link to "https://my.gprc.ab.ca/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
and the error I get is?
sh: jq: command not found
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
100 36 100 36 0 0 495 0 --:--:-- --:--:-- --:--:-- 500
(23) Failed writing body
sh: jq: command not found
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
100 36 100 36 0 0 495 0 --:--:-- --:--:-- --:--:-- 500
(23) Failed writing body (127)
Best Answer
You probably installed
jq
in/usr/local/bin
(or any other directory outside of/bin:/sbin:/usr/bin:/usr/sbin
). Usually this directory is not part ofPATH
so you need to specify the full path to run it (/usr/local/bin/jq
).