Automount Network Share

From Software Wiki
Jump to navigation Jump to search

Automount Network Share (version 1.00)

Released June 4, 2020
By Robert P. Allred, PhD

[Release Announcement]

This AppleScript is written for use with Hazel to mount a specific network share prior to copying files to the share. I was looking for a way to make sure that the network folder was mounted when I returned home instead of letting Hazel fail at copying the files until I manually mounted the share. This also allows me to make sure that the share gets mounted with the user that I need, as opposed to the user I typically use.

Terms of Use


Automount Network Share by Robert P. Allred, PhD is licensed under a Creative Commons Attribution 4.0 International License. Derived from a work at <https://forums.macrumors.com/threads/applescript-check-if-connected-to-a-specific-network-then-run-else-fail-silently.1640860/>


You are free to:

Share — copy and redistribute the material in any medium or format
Adapt — remix, transform, and build upon the material for any purpose, even commercially.

This license is acceptable for Free Cultural Works.

The licensor cannot revoke these freedoms as long as you follow the license terms.


Important Links

Current Project Page: https://doctorallred.com/software/index.php?title=Automount_Network_Share

System Requirements

This script continues to work under macOS Catalina (macOS 10.15.7) and Hazel 5.1.

This script has been tested with macOS Mojave (macOS 10.14) and Hazel 4.4.5.

Installation

  • Requires macOS
  • You must have Hazel installed.
  • Create a Hazel rule to monitor a folder, then choose your action as "run AppleScript" and paste the code below into Hazel's built-in AppleScript editor.

Current Version

Version 1.0 (June 4, 2020)

(*
VERSION 1.00
June 4, 2020
adapted by Robert P. Allred, PhD, <https://doctorallred.com>

//TERMS OF USE
Automount Network Share by Robert P. Allred, PhD is licensed under a Creative Commons Attribution-NonCommercial 4.0 International License.
Derived from a work at <https://forums.macrumors.com/threads/applescript-check-if-connected-to-a-specific-network-then-run-else-fail-silently.1640860/>. To view a copy of this license, visit <http://creativecommons.org/licenses/by-nc/4.0/>.

// IMPORTANT LINKS:
Current Project Page: <https://doctorallred.com/software/index.php?title=Automount_Network_Share>

// REQUIREMENTS:
Version 1.00 has been tested with macOS Mojave (10.14), and Hazel 4.4.5.

// INSTALLATION:  
-- Save this script to your computer. Create a rule in Hazel and choose "Run an AppleScript. Open the built-in script editor and paste this script.

// CHANGELOG:

	Version 1.00 (June 4, 2020): Initial release.
*)


-- PREP SSID DETECTION

set SSID to do shell script "/System/Library/PrivateFrameworks/Apple80211.framework/Resources/airport -I | awk '/ SSID: / {print $2}'"


-- IF HOME NETWORK IS DETECTED

if SSID is "SSIDNAME" then -- NOTE: the script above is returning only the first word in the SSID name, so works with both my main and guest networks. Replace SSIDNAME with your SSID
	
	-- MOUNT DRIVE
	
	mount volume "smb://username@servername/SHARE_NAME" --username is your username on the server, servername is the server name, and SHARE_NAME is the share you want mounted.
	delay 5 --need enough time for volume to mount before trying to copy file.
	
	-- SET RESULT VAR TO "WIN"
	
	set endresult to "win"
	
	-- ELSE
	
else
	
	-- DO NOTHING
	
	-- SET RESULT VAR TO "FAIL"
	
	set endresult to "fail"
	
	-- END
	
end if


[Download here as Zip archive]

Change requests

  • n/a

Full Change Log

  • 1.00 (June 4, 2020): Initial release of script