How to Keep a Network Drive Mounted on Mac OS X with DLI_ReMounter JavaScript

How to Keep a Network Drive Mounted on Mac OS X

How to Keep a Network Drive Mounted on Mac OS X using a JavaScript Apple Script Editor Application

In today’s blog post I’ll show you how to keep a network drive mounted on Mac OS X using a simple custom JavaScript script in Apple’s Script Editor. I often perform network rendering using our DreamLight Constellation network render controller for LightWave 3D’s ScreamerNet. When network rendering the remote render nodes need to maintain constant access to the shared network drive. They need access to the network volume to read and write command files, scene files, scene assets and final renders. Mac OS X network performance has usually been rock solid. I’ve encountered a problem recently though in Mac OS X 10.11.6 El Capitan. Sometimes the remote render nodes will drop the connection to the shared network disk volume. When this happens the the render node fails to save the currently rendering frame and then drops out of the render farm. I then have to manually remount the shared network drive and reinitialize the remote render node. On a recent project this has become a real pain and was slowing down the overall progress.


How to Keep a Network Drive Mounted on Mac OS X with Matching File Sharing and Router Server Names

In addition to the volume connection often being dropped, re-connections often failed if I just double-clicked on the server’s name in the Finder’s sidebar. I then had to use Go->Connect to Server and enter the server’s IP address. I noticed was that there were two different names for the server I was attempting to connect to. One was set in the File Sharing preferences panel in the Computer Name text field. That setting determined the main server name that showed up in the Finder’s sidebar as expected. But there was another name listed below File Sharing: On that didn’t match. I couldn’t find a matching setting anywhere on the Mac.

How to Keep a Network Drive Mounted on Mac OS X using a JavaScript Apple Script Editor Application

It turns out the second name was coming from the network router which had nicknames set for each connected device. So I set the server’s device name on the router to match the server’s name as set in File Sharing.

How to Keep a Network Drive Mounted on Mac OS X using a JavaScript Apple Script Editor Application

After I set both names to match the Mac would still periodically drop the connection to the network volume. However, when the names matched, I was able to use a simple double-click on the server’s name in the Finder sidebar to reconnect.

Additional research into how to keep a network drive mounted on Mac OS X showed others having the same problem. At that point I figured it might be easier to just write a simple script to remount the drive whenever it dismounted. So I wrote the following JavaScript script DLI_ReMounter in Apple’s Script Editor to detect when the volume was disconnected and just remounted it. Once I wrote this JavaScript I haven’t had another disconnected render node in my Mac based DreamLight Constellation render farm.


How to Keep a Network Drive Mounted on Mac OS X with DLI_ReMounter JavaScript

How to Keep a Network Drive Mounted on Mac OS X - DLI_ReMounter JavaScript

In order to use this script first mount the shared network drive volume that you wish to keep mounted on the remote rendering Mac. Be sure to use unique names for any shared disk volumes. Mac OS X can handle duplicate names, but it adds index numbers internally which may cause issues. So to eliminate that as a potential problem it’s best to rename with unique names any disks that you wish to share on the network.

Mounting the Shared Network Disk Volume

On the remote rendering Mac (A MacBook Pro in this case) navigate to the Device’s top level in the Finder (4x2GHz_MacBookPro). Make a note of the disk volume name (WORK 3TBR1) and the shared server name (12x3GHz_MacPro) as seen in the Finder.

  • Copy and paste the DLI_ReMounter JavaScript (below) into Apple’s Script Editor set to use JavaScript
  • Edit the user variables volName (WORK 3TBR1) and the serverName (12x3GHz_MacPro) to match your volume and server names
  • Edit tIdleSeconds to the number of seconds between each time it checks for a disconnect to remount the drive.
  • Export with File Format set to Application with Stay open after run handler checked.

How to Keep a Network Drive Mounted on Mac OS X using a JavaScript Apple Script Editor Application

  • Double-click the exported application to run it.
  • Eject the shared volume or dismount the shared sever.
  • The running DLI_ReMounter JavaScript application should then remount the volume and may ask you to enter your username and password. Do so and be sure to click Remember this password in my keychain. This way you won’t need to re-enter this information whenever the script attempts to remount the shared disk volume.

How to Keep a Network Drive Mounted on Mac OS X using a JavaScript Apple Script Editor Application


DLI_ReMounter JavaScript Text for Copy/Paste

The following JavaScript is provided free for educational purposes to use AT YOUR OWN RISK. Be sure to back up all systems and data before use. Michael Scaramozzino and DreamLight Incorporated make no warranties whatsover regarding this script. For educational purposes only. USE AT YOUR OWN RISK!

// ***********************************************
// DLI_ReMounter JavaScript for Mac OS X
// by Michael Scaramozzino - DreamLight.com
// ***********************************************
// Michael Scaramozzino and DreamLight Incorporated 
// make no warranties whatsoever regarding this script. 
// For educational purposes only. USE AT YOUR OWN RISK!
// ***********************************************
// USAGE:

// Open in Apple's Script Editor
// Edit the volName and serverName USER VARIABLES 
// Export As application
// With 'Stay open after Run handler' checked.
// Double-click to launch application.

// ***********************************************
// USER VARIABLES

var tIdleSeconds = 30; 					// set to seconds to wait between checks
var volName = "MikeS_MBP_SYS" 				// set volume name to mount
var serverName = "4x22GHz_MacBookPro" 			// set server name

// ***********************************************
// APPLICATION HANDLERS

var app = Application.currentApplication();		// Link to current application
app.includeStandardAdditions = true;			// Activate StandardAdditions
var system = Application('System Events');		// Load System Events


function idle() { 					// Called at designated idle intervals
	checkVolumes();		
    return tIdleSeconds; 				// next idle interval call
};

// ***********************************************
// UTILITY HANDLERS

function checkVolumes() {
	var volMounted = false; 			// start with mount flag false

	var volList = system.disks(); 			// get list of mounted volumes from system
	for (i = 0; i < volList.length; i++) { 		// check each mounted volume
		if (volList[i].name() == volName){ 	// volume name matches
			volMounted = true; 		// volume is mounted
			break;				// end loop
		};
	};
	
	if ( ! volMounted ) { 				// if not mounted, try to mount it
		try {
			app.displayNotification( "Mounting: '" + volName + "'" );
			app.mountVolume( volName, {onServer: serverName} );
		} catch (err) {
			app.displayNotification( 'Mount failed: ' + err );
		};
	};
};

If you enjoyed this tutorial please consider making a donation to fund more!



DreamLight Constellation Network Render Controller

DreamLight Constellation 3D Icon LogoDreamLight® Constellation is our cross-platform network render controller that combined with DLI_SNUB-Launcher™ makes configuring, launching and controlling LightWave 3D ScreamerNet LWSN for standalone, batch, network and internet rendering, drag-and-drop-dead-easy™.

Created by Michael Scaramozzino - LightWave 3D Artist Profile
Author of Creating a 3D Animated CGI Short & Mastering LightWave ScreamerNet


DreamLight wrote the book: Creating a 3D Animated CGI Short. See what we can do for you.

 

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.