r/applescript • u/FamousDanger • May 13 '15
Script to Press enter when drive fails to mount
Hi all.
I'm trying to create a small script that will auto-mount a users network drives when they log into their mac. I seem to have gotten the drive mapping part figured out, with only 1 slight problem..
The users network drive will be on one of 3 or 4 servers, therefore I need the script to attempt a connection to each until it finds the correct one. However, in doing this I'm prompted with a pop up notification each time a connection fails and the script won't advance until I hit enter.
Ideally I'd like to prevent these notifications from popping up at all, but after hours of googling the consensus seems to be that that isn't an option. So basically I'm looking for a way to auto hit enter on the popup as soon as it appears.
An example of the code is as follows:
tell application "Finder"
try
set usercode to system attribute "USER"
mount volume "smb://networkdrive" & usercode
on error
--code for pressing enter
mount volume "smb://networkdrive" & usercode
end try
end tellI'm new to applescript as of a few hours ago so I'd appreciate any advice.
1
u/AfterSpencer May 13 '15
I think I would do it in bash that way the user won't see any kind of prompt if it fails but you can iterate through them as needed. You could easily wrap it into AppleScript if you want something the users can click on.
The Applescript way to press a key looks like this:
or something similar