Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'MAC Automatically Mount Net Drives on WAKE or START UP' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
MAC Automatically Mount Net Drives on WAKE or START UP
Authored by: kswison on Jan 25, '12 10:18:04AM

For Beginners like ME, Using SLEEPWATCHER and creating the '.wakeup' file

I am new to MAC but have final figured this out how to set up SLEEPWATCHER using this site. Thanks to the people here and lots of reading. Got the SLEEPWATCHER loaded. Installing SLEEPWATCHER is not that user friendly to new MAC users, but take your time and go through it, the instructions are pretty good.

As for creating the '.wakeup' file, I created 'wakeup.txt' in one directory and copied it to ~/
using the following lines of code and copying the code into TERMINAL

Create 'sleep.txt' and 'wakeup.txt' anywhere on your computer. The simplest might be in the head directory ~/ but it really doesn't matter.

Here is the code I used for my 'wakeup.txt' file. I use it to remount my external net drive.

__start code below line_______________________________

#!/bin/sh
exec <"$0" || exit; read v; read v; exec /usr/bin/osascript - "$@"; exit
delay 10
set testnet to 1
repeat with idx from 1 to 5
try
set ping_result to (do shell script "ping -c 1 -t 1 192.168.20.70")
set testnet to 10
on error
if testnet = 1 then
say "Searching for W Net Drive"
end if
beep 3
set testnet to (testnet + 1)
delay 10
end try
if testnet = 10 then
exit repeat
end if
end repeat
if testnet = 10 then
delay 1
mount volume "smb://W-NetDrive/Volume_1"
say "Net Drive Volumes Mounted"
end if
if testnet = 6 then
say "The W Net Drive could not be PINGED on the network"
say " I am unable to mount the W Drive Volumes"
end if
___________________________
end code above line

As a minimum, you need to make these two changes to the above code or it will not work for you.

1) You will need to change the IP address (192.169.20.70) on line 7 (as shown below)
set ping_result to (do shell script "ping -c 1 -t 1 192.168.20.70")
to match the IP address on your Net Drive or the script cannot PING the Net Drive.

2) You will also need to edit the 7th last line (as shown below)
mount volume "smb://W-NetDrive/Volume_1"
to reflect you own net drive name, or the net drive will not mount.

Further to that, you can easily remove the computer's talking if you want. Simply delete all the lines that start with 'say'. However, this only occurs at 'wake up' so it is nice to know what is going on, but edit it as you see fit.

The way this works, is that the first two lines of code (as follows)
#!/bin/sh
exec <"$0" || exit; read v; read v; exec /usr/bin/osascript - "$@"; exit
should not be revised as they set up the rest of the script to be able to process APPLESCRIPT.
(need more infer... see http://hints.macworld.com/article.php?story=20060425140531375)

Hooray!! I don't need to learn shebang and all that other complicated programming stuff.

After the first two lines, you can simply program away in APPLESCRIPT. Use your APPLESCRIPT editor to ensure the code is correct, the copy/paste your APPLESCRIPT into your 'wakeup.txt' or 'sleep.txt' file, after the first two lines of code (as noted above).

Then you need to rename the '.txt. files as follows
wakeup.txt to .wakeup
sleep.txt to .sleep
Place the new '.' files in the head directory ~/
Then you need to change the '.wakeup' and '.sleep' file permissions to executable.

I did that this way....
__________________________________________

Enter the following text into TERMINAL to rename files and create the hidden '.' files.
I just copied in one line of code at a time.

FOR .SLEEP
cd ~/
cp ~/documents/data-k/W_NetDrive_PING/sleep_and_wake_files/sleep.txt ~/.sleep
chmod a+x .sleep

FOR .WAKEUP
cd ~/
cp ~/documents/data-k/W_NetDrive_PING/sleep_and_wake_files/wakeup.txt ~/.wakeup
chmod a+x .wakeup

Basically its

cp path/to/file.txt ~/.wakeup

This copies the file to the ~/ directory and changes the name in one command.

Then change the permissions using

chmod a+x .wakeup

________________________________________________
This works great !

so....Place your computer into SLEEP, then WAKE it up. Your NetDrive should mount automatically and inform you that it should now be mounted. If it cannot be found in order to mount it, it will also tell you that. Change it to what ever you want it to say.

Oh, at this point in time I actually only use '.wakeup', I have not set up anything in '.sleep'
________________________________________________

As for mounting the drives on START UP I use a similar APPLESCRIPT as follows. Using my APPLESCRIPT Editor I created the following script.

____Script starts below the line___________________

set testnet to 1
repeat with idx from 1 to 5

try
set ping_result to (do shell script "ping -c 1 -t 1 192.168.20.70")
set testnet to 10
on error
beep 3
set testnet to (testnet + 1)
delay 10
end try
if testnet = 10 then
exit repeat
end if



end repeat
if testnet = 10 then
delay 1
mount volume "smb://W-NetDrive/Volume_1"
say "Net Drive Volumes Mounted"
end if
if testnet = 6 then
say "The W Net Drive could not be PINGED on the network"
say " I am unable to mount the W Drive Volumes"
end if
____________________________________
script ends above the line

In the APPLESCRIPT Editor I save the file as 'W-PING.scpt', then re-save the file only this time changing the FILE FORMAT to APPLICATION and as 'W-PING.app'

This file 'W-PING.app' is now executable, (if not change it as above, but I think it become executable as soon as it is saved as an '.app' file extension.)

Then go into the APPLE SYSTEM PREFERENCES

Go to category SYSTEM and find 'USERS & GROUPS' and open it.

On the left hand side you will see the 'Current User', and click on it.

On the right hand side at the top look for 'Login Items' and click on it.

You will see some apps that automatically open when logging in.

Below the box you will see a '+|-' box, go click on the '+'

direct the window to the 'W-PING.app' file or what ever you decided to call it and then click 'ADD"

Repeat this for which ever Users need the Net Drive automatically loaded. You will have to be logged in as them in order to be able to change their start up programs at login.

!!!!!!!!!!!!!!!!!!

Hooray, you are done! You computer will now remount the NetDrive Volumes at both START UP and WAKE.

At least it has all worked for me.

I know there are likely other ways of doing this, but this worked for me so I wanted to share it to save other beginners a bunch of hours trying to figure this out. Just as a though, you may also have to copy the W-PING.app file to a location in their User profile where they can find it and set it up as an application to open at START UP.

Good Luck!



[ Reply to This | # ]