Test weather a network drive is mounted with Apple Shortcuts

All I'm really trying to do is mount a networked drive when my laptop is home. Currently have it so that it tests that I'm at home as opposed to work or a coffee shop by getting a wifi name and tested if it's my home wifi with an "if." If it is, then it mounts the drive. This works great, as far as it goes, but sometimes (due to other parts of the automation that are working fine) I run the shortcut again. Since I'm still home it passes the condition and tries to mount a drive that is already mounted and this results in errors. Honestly, if there is a 'fail with grace' code somewhere that would be perfect. Failing that, I need a conditional to test if the drive is already mounted, if it is go to 'otherwise' if it's not mount it. Any advice would be appreciated.

MacBook Pro 16″, macOS 26.1

Posted on Nov 6, 2025 11:17 AM

Reply
Question marked as Top-ranking reply

Posted on Nov 6, 2025 12:08 PM

There are many ways to go about this, depending on what's most important to you. As you've noted, there's the graceful exit, and there's the recheck.


For a graceful exit, use a try block. Any statement can be wrapped in a try block and any errors are trapped by the script.


try
	-- your script here to mount the server
on error
	-- we get here if something failed
	-- so we can alert the user, try again, or do nothing to fail silently
end try



Alternatively, you can ask the Finder if the drive is mounted before running your network check and mount command:


tell application "Finder"
	if exists disk "My Network Drive" then
		-- code here to mount the volume
	end if
end tell


Or you could combine the two - nothing wrong with checking for the disk's presence as well as using try, since there are multiple potential failure states.


-- edit:


just realized you're talking Shortcuts, not AppleScript. Logic handling (if/then) and error trapping is a little trickier in Shortcuts, but you could just run the above in a Run AppleScript action.

2 replies
Question marked as Top-ranking reply

Nov 6, 2025 12:08 PM in response to ScooterN2005

There are many ways to go about this, depending on what's most important to you. As you've noted, there's the graceful exit, and there's the recheck.


For a graceful exit, use a try block. Any statement can be wrapped in a try block and any errors are trapped by the script.


try
	-- your script here to mount the server
on error
	-- we get here if something failed
	-- so we can alert the user, try again, or do nothing to fail silently
end try



Alternatively, you can ask the Finder if the drive is mounted before running your network check and mount command:


tell application "Finder"
	if exists disk "My Network Drive" then
		-- code here to mount the volume
	end if
end tell


Or you could combine the two - nothing wrong with checking for the disk's presence as well as using try, since there are multiple potential failure states.


-- edit:


just realized you're talking Shortcuts, not AppleScript. Logic handling (if/then) and error trapping is a little trickier in Shortcuts, but you could just run the above in a Run AppleScript action.

Nov 6, 2025 1:13 PM in response to ScooterN2005

ScooterN2005 ~ Set & test a binary 'switch' in iCloud Drive > Shortcuts > Mounted.txt (for example.)


...Manually set it to 0 initially, test its value in your automation and then , after mounted, set it to 1 for testing next time your automation is run.


There's also this free app that you may prefer for setting a switch:


Data Jar


Shortcuts User Guide for Mac - Apple Support


Shortcuts User Guide - Apple Support


õ¿õ¬

Test weather a network drive is mounted with Apple Shortcuts

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.