Quit Script under these conditions leaving screen with no remnants of it or warnings

Quit Script if no entry, wrong entry or no entry after 20 seconds


Would like to be able to add to this script provided by Niel so that if there was no entry for the passphrase, wrong entry, or 20 seconds have elapsed, the script would quit with no warning.


tell application "Finder"

if not exists disk "TEST" then

set thePassword to text returned of (display dialog "A password is required." default answer "" with hidden answer)

do shell script "diskutil apfs unlockvolume UUID -passphrase " & thePassword

end if

end tell



It would leave the screen as if the password was put in correctly in 20 seconds.



I have tried with timeout of 10 seconds at the beginning and end timeout at the end but still gives: Apple event timed out and leaves the password dialog box on the screen.


Thanks

iMac (2017 – 2020)

Posted on Dec 31, 2025 3:10 PM

Reply
Question marked as Top-ranking reply

Posted on Dec 31, 2025 3:27 PM

Use:


display dialog "A password is required." default answer "" giving up after 20 with hidden answer

try

if not (gave up of the result) and text returned of the result is not "" then "diskutil apfs unlockvolume UUID -passphrase " & text returned of the result

on error number -60005

end try


The script can't actually check if the password is correct without running the command.


(262372)

13 replies
Question marked as Top-ranking reply

Dec 31, 2025 3:27 PM in response to mrokloricred37

Use:


display dialog "A password is required." default answer "" giving up after 20 with hidden answer

try

if not (gave up of the result) and text returned of the result is not "" then "diskutil apfs unlockvolume UUID -passphrase " & text returned of the result

on error number -60005

end try


The script can't actually check if the password is correct without running the command.


(262372)

Dec 31, 2025 10:06 PM in response to Niel

Now get this with wrong password:



From an earlier script of yours,

removing this line seems to fix the issue and seems to work fine:

on error number -60005


yielding this:


tell application "Finder"

if not (exists disk "TEST") then

display dialog "A password is required." default answer "" giving up after 20 with hidden answer

try

if not (gave up of the result) and text returned of the result is not "" then do shell script "diskutil apfs unlockvolume UUID-passphrase " & text returned of the result

end try

end if

end tell

Dec 31, 2025 4:22 PM in response to Niel

Probably my error but volume would not mount with correct password and UUID


tell application "Finder"

if not (exists disk "TEST") then

display dialog "A password is required." default answer "" giving up after 20 with hidden answer

try

if not (gave up of the result) and text returned of the result is not "" then "diskutil apfs unlockvolume UUID  -passphrase " & text returned of the result

on error number -60005

end try

end if

end tell

Dec 31, 2025 8:08 PM in response to mrokloricred37

Use the following:


tell application "Finder"

if (exists disk "TEST") then return

end tell

display dialog "A password is required." default answer "" giving up after 20 with hidden answer

try

if not (gave up of the result) and text returned of the result is not "" then do shell script "diskutil apfs unlockvolume UUID  -passphrase " & text returned of the result

on error number -60005

end try

end if


(262375)

Quit Script under these conditions leaving screen with no remnants of it or warnings

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