Applescript if exists unmount


Trying to run an AppleScript that if the volume exists unmount it.


I am successful in unmounting it, but can't figure how to just unmount it IF IT EXISTS


This unmounts it

do shell script "diskutil unmount 43123A60-7F49-4200-A18F-C80BA166E9RE"


FWIW the name of the volume is EXTRA


Thanks for tour help

iMac (2017 – 2020)

Posted on Apr 17, 2025 11:05 AM

Reply
Question marked as Top-ranking reply

Posted on Apr 18, 2025 12:40 PM

> I am successful in unmounting it, but can't figure how to just unmount it IF IT EXISTS


You could just:


try
    do shell script "diskutil unmount 43123A60-7F49-4200-A18F-C80BA166E9RE"
end try


try/end try is AppleScript's method for catching errors.


Different from Niel's suggestion, which determines whether or not try to unmount - mine tries and just ignores failures.

2 replies
Question marked as Top-ranking reply

Apr 18, 2025 12:40 PM in response to mrokloricred37

> I am successful in unmounting it, but can't figure how to just unmount it IF IT EXISTS


You could just:


try
    do shell script "diskutil unmount 43123A60-7F49-4200-A18F-C80BA166E9RE"
end try


try/end try is AppleScript's method for catching errors.


Different from Niel's suggestion, which determines whether or not try to unmount - mine tries and just ignores failures.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Applescript if exists unmount

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