Categories
Uncategorised

Mac Staff Home – dock shortcut

UPDATE – Cam commented on this post last year and I adjusted the code but never posted the update. I’ve posted an update for dock shortcuts using WebDAV but some people might still need to use these ones so I am updating the code to make it a bit better.

Now it falls over to enter a different username if the local name is wrong, it also improves the original posted code by ignoring the mounted drive if it’s already mounted and also mounts directly to the user folder instead of also showing the top level Home$ share. Oh yeah it also opens a finder window to the base so you can just click it when ever you want to bring up a finder to the share folder.

So there are a few of these out there and it’s usually a techs first delve into Mac when they get asked to create a short cut to connect to a file share. Simple connections to afp or smb shares are easy but then you hit a wall when you get asked to make it connect to the specific Users folder.

Original Code

set the_user to system attribute “USER”
try
mount volume “smb://” & the_user & “@STAFFHOME/Home$/”
tell application “Finder” to open location “smb://STAFFHOME/Home$/” & the_user & “/”
end try

Improved Code

# Author: Skye Moroney
# Version: 7.3
# Created: 20150819
# About: Connect as local user to an SMB share# get the local username
set the_user to system attribute “USER”repeat until (list disks) contains the_user
    try
        # adjust to match your Staff Share
        mount volume “smb://” & the_user & “@STAFFHOME/Home$/” & the_user & “/”
    onerror
        # @Cam’s improvement
        # if connection fails then prompt for username
        set the_user to display dialog “Please enter your network username:” default answer “” buttons {“Cancel”, “Ok”} default button 2
    end try
end repeat

# open finder to the base of connected mount and set to column view
tell application “Finder”
    activate
    # repeat, as script can execute so fast that it starts before mounting
    repeat
        if exists disk “Home$” then
            # open a Finder window and set to column view
            make new Finder window to the_user
            set current view of Finder window 1 to column view
            exit repeat
        end if
    end repeat
end tell

 

Step by Step

Open AppleScript Editor and paste the above in.

Adjust the name of your share appropriately – this will not work exactly as is unless you work at the same place as me or you happen to have the same setup.

Screen-Shot-2013-11-05-at-6.17.33-pm

Save the script first and then Export it and choose the File Format to be Application

Screen-Shot-2013-11-05-at-6.54.27-pm

Using the Keynote trick you can make a high res icon for it – once upon a time there was a a bunch of effort required to do this but now it’s too damn easy.

Right click the new app and Get Info (command+i)click the icon so it has a blue highlight and then paste your image – icon done.

2minute example –

staff-home

Now to finish off, when you store the new shortcut you’ve made put it in your /Users/Shared folder.

Screen-Shot-2013-11-05-at-6.17.15-pm

Once you’ve installed it there and changed the permissions in the Get Info to be re Read&Write for everyone. It can now be dragged to or MCX’d to anyones dock on that Mac.

As I had pointed out to me;

always a few ways to achieve the same thing

There are a lot of ways to do the connection, this is just the way I have done it and if you like please feel free to add some in the comments =)

The reason for the secondary line in the script is so that when a user clicks the shortcut it will open a finder to the folder rather than just mounting it. I honestly should go and add some error checking and also put in some dialogues for failure to clean it up. I should also do a check to see if the drive is mounted already to skip that step if it isn’t needed, as then it would become the button that a user can click to bring up the share space every time.

Leave a Reply