OD Network Home Shortcut on Dock or Desktop

Jalves
Contributor

Hello, we are taking down WGM at one of our sites that is utilizing OD (normally we use AD which helps us out by mounting the network home on the dock). I am looking for the simplest way to have an alias on the desktop or dock to their OD Server Home. I have been trying to script the desktop shortcut by using

*-ln -s afp://sharename.site.org/$USERS ~/Desktop

This is generating a plain white alias file that tells me the original item cannot be found and the share is mounted when I am running it. I'm just looking for the easiest way to have users manually save their work as opposed to WGM running Home Syncing. If what I am trying to attempt is not the best route, I'm open to any and all options. Thanks Everyone.

1 ACCEPTED SOLUTION

mm2270
Legendary Contributor III

OK, got it. Applescript is powerful, but at times can be a bit gnarly in terms of what you need to do to get things like paths from the shell into it or the proper format for it to recognize them.

How does the share actually show up in the /Volumes/ list? As "HomeDirs" or is it the full path as in "servername.org/HomeDirs"?
Depending on how it actually shows up in the Finder or when doing something like ls /Volumes, you can try the following script. You'll have to make any necessary adjustments to it though, since I can't be sure it would work as is in your environment.

#!/bin/bash

## Get the current logged in user's name
CURRENTUSER=$(stat -f%Su /dev/console)

## Set variable for the volume name
VOLNAME="HomeDirs"

## Set up command to check for the mounted volume
VOLCHECK=$(ls /Volumes/ | tr ' ' '
' | grep "^${VOLNAME}$")

## Create path to the folder we want to create an alias from
FOLDERPATH="/Volumes/${VOLNAME}/${CURRENTUSER}"

## Create path to where the alias will go, using the logged in user's name
ALIASPATH="/Users/${CURRENTUSER}/Desktop/"

function createAlias ()
{

## If its mounted, set variables in Applescript HEREDOC section by echoing back the shell variables
## Create the alias to the current logged in user's Desktop
/usr/bin/osascript << EOF
set theFolderName to do shell script "echo "$FOLDERPATH""
set theFolder to POSIX file theFolderName
set theAliasPath to do shell script "echo "$ALIASPATH""
set theAlias to POSIX file theAliasPath
tell application "Finder" to make alias to folder theFolder at theAlias
EOF

}

## Check to make sure the volume is mounted by checking the $VOLCHECK variable to see if it was populated with what we expected
if [ "$VOLCHECK" ]; then
    echo "Volume "${VOLNAME}" is mounted"
    echo "Creating alias of "${FOLDERPATH}" to "${ALIASPATH}""
    ## Run the above function to create the alias
    createAlias
else
    ## If the volume is not mounted, exit, or do something here to correct that and then run the function
    echo "Volume "${VOLNAME}" is not mounted. Exiting."
    exit 1
fi

View solution in original post

6 REPLIES 6

mm2270
Legendary Contributor III

I think the only proper way to create an alias of a share with its actual icon and not a generic file icon is to use Applescript.
But the caveat is that the share needs to be mounted already to create an alias of it, since Applescript has to be able to access the object to create an alias for it.
You can take a look here for some guidance in the right direction:
https://jamfnation.jamfsoftware.com/discussion.html?id=5290

Something like this may work once the share is mounted

tell application "Finder"
    make alias to disk "disk name" at desktop
end tell

It does create an alias with the word "alias" at the end of the name just so you know, but that can be trimmed back later in your script if needed.

Jalves
Contributor

Thanks for the response. I was planning on using a Login Item profile to mount the Share for each user. I don't mind the Alias being tagged onto the desktop item. However I am having issues with the path of the folder.

tell application "Finder"
make alias to folder "afp://servername.org/HomeDirs/$user" at desktop
end tell

When I run that, I get this error
"error "Finder got an error: Can’t get folder "afp://servername.org/HomeDirs/$user"." number -1728 from folder "afp://servername.org/HomeDirs/$user""

I'm not sure what I'm doing wrong, but I am sure it's my fault. I do have the Share mounted when running.

mm2270
Legendary Contributor III

Applescript doesn't understand Unix style paths like that without either telling it its supposed to be operating on a POSIX path, or storing the path first in the shell and then telling Applescript to set its own variable for that path with the do shell script command.

Let me ask, is the "$user" string in the path to the folder literal, in that its always named that exactly, or is that an actual variable somewhere in the script that I'm not seeing?

Jalves
Contributor

At the moment thats all there is to the script. I was hoping the $user to be replaced with the currently logged in username when running like in bash scripts. I do not believe I defined it. I'm not sure how to accomplish that in applescript. I normally do things with unix commands, though I am no wizard.

mm2270
Legendary Contributor III

OK, got it. Applescript is powerful, but at times can be a bit gnarly in terms of what you need to do to get things like paths from the shell into it or the proper format for it to recognize them.

How does the share actually show up in the /Volumes/ list? As "HomeDirs" or is it the full path as in "servername.org/HomeDirs"?
Depending on how it actually shows up in the Finder or when doing something like ls /Volumes, you can try the following script. You'll have to make any necessary adjustments to it though, since I can't be sure it would work as is in your environment.

#!/bin/bash

## Get the current logged in user's name
CURRENTUSER=$(stat -f%Su /dev/console)

## Set variable for the volume name
VOLNAME="HomeDirs"

## Set up command to check for the mounted volume
VOLCHECK=$(ls /Volumes/ | tr ' ' '
' | grep "^${VOLNAME}$")

## Create path to the folder we want to create an alias from
FOLDERPATH="/Volumes/${VOLNAME}/${CURRENTUSER}"

## Create path to where the alias will go, using the logged in user's name
ALIASPATH="/Users/${CURRENTUSER}/Desktop/"

function createAlias ()
{

## If its mounted, set variables in Applescript HEREDOC section by echoing back the shell variables
## Create the alias to the current logged in user's Desktop
/usr/bin/osascript << EOF
set theFolderName to do shell script "echo "$FOLDERPATH""
set theFolder to POSIX file theFolderName
set theAliasPath to do shell script "echo "$ALIASPATH""
set theAlias to POSIX file theAliasPath
tell application "Finder" to make alias to folder theFolder at theAlias
EOF

}

## Check to make sure the volume is mounted by checking the $VOLCHECK variable to see if it was populated with what we expected
if [ "$VOLCHECK" ]; then
    echo "Volume "${VOLNAME}" is mounted"
    echo "Creating alias of "${FOLDERPATH}" to "${ALIASPATH}""
    ## Run the above function to create the alias
    createAlias
else
    ## If the volume is not mounted, exit, or do something here to correct that and then run the function
    echo "Volume "${VOLNAME}" is not mounted. Exiting."
    exit 1
fi

Jalves
Contributor

Hey Sorry for the late response. I had to put this one on the back burner for a minute. That script worked perfectly. Thank You for your help!