I’m a complete novice when it comes to apple scripting so apologies for what is probably a really simple thing to do. I want to create a script that will connect the users mac to a drive on a different machine over the network and once the connection has been made to then have it open in a finder window.
I currently have it setup as follows…
tell application “Finder”
–try
mount volume “smb://guest:@xx.x.xxx.xxx/TriCaster GBV”
–end try
end tell
tell application “Finder”
–try
open folder “TriCaster GBV” of computer container
–end try
end tell
The problem I’m having is that there is always a delay in connecting to the remote drive (this can vary from machine to machine) which then throws up an error message for the second part of the script. What I want it to do is to keep repeating the open folder command until it has successfully opened it, I’ve unfortunately had no luck finding a way of doing this.
you could check if the disk is mounted with list disks
property myDisk : "TriCaster GBV"
if myDisk is not in (list disks) then
mount volume "smb://guest:@xx.x.xxx.xxx/TriCaster GBV"
repeat until myDisk is in (list disks)
delay 0.5
end repeat
end if
tell application "Finder"
open disk myDisk
end tell
I tried your suggestion but I still run in to the same issue where it throws back the error “Finder got an error: Can’t get disk "TriCaster GBV".” number -1728 from disk “TriCaster GBV”.
This is because the disk won’t mount straight away when the script is run and can take anywhere between 5-60 seconds to connect.
If the disk is not mounted it sends the mount volume command and uses a repeat loop with a delay to wait until the disk appears.
You can also try
property myDisk : "TriCaster GBV"
if myDisk is not in (list disks) then
mount volume "smb://guest:@xx.x.xxx.xxx/TriCaster GBV"
end if
tell application "Finder"
with timeout of 120 seconds
repeat until exists disk myDisk
delay 1.0
end repeat
open disk myDisk
end timeout
end tell