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)

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 of PATH so you need to specify the full path to run it (/usr/local/bin/jq).


The primary issue being pointed out is not really an AppleScript issue per se. In other words, while the do shell script command is an AppleScript command, nonetheless, the issue is that the command(s) called by the do shell script command are not AppleScript commands, they are shell commands and as such are subject to the environment passed to the shell when the
do shell script command is executed.

The PATH passed to a do shell script command is /usr/bin:/bin:/usr/sbin:/sbin, and any executable called that is not within that PATH, then the fully qualified pathname needs to be used.

The PATH environment variable is a colon-delimited list of directories that your shell searches through when you enter a command.

Apparently jq is not within that PATH. In other words, jq is not located in one of the following locations: /usr/bin:/bin:/usr/sbin:/sbin

So, your choices are either symlink or move jq to one of those locations, or use the fully qualified pathname of the jq executable in the jq command within the commands of the do shell script command.

In the do shell script command, change jq to /path/to/jq

Example: /usr/local/bin/jq

Substitute /usr/local/bin/ with the actual /path/to/ the jq executable.

You might be able to ascertain its path in Terminal using the following command:

which jq

On my system the result of which jq is: /usr/local/bin/jq

If that doesn't work, then use the following command in Terminal:

find / -iname jq 2>/dev/null

So, you really do not need to understand AppleScript because the issue is a shell issue. Understanding how shells work is where you need to focus on your lack of understanding.