2

I was wondering if anyone could help me with this. Sorry for the noob question. I recently created a script to automatically mount a Time Machine image in a hard drive connected to my router. For the most part, the script works great. It attaches the drive when I turn on the computer and, if it disconnects for any reason, it reconnects and mounts the image again. Here's the script:

on idle
set mySSID to do shell script "/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport -I | awk '/ SSID/ {print substr($0, index($0, $2))}'"
set mountedDiskName to "Time Machine"
set diskIsMounted to false
if mySSID is "TALKTALK844E28" or mySSID is "TALKTALK844E285G" then
    tell application "System Events" to set diskNames to name of every disk
    if mountedDiskName is in diskNames then
        set diskIsMounted to true
    end if
    if mountedDiskName is not in diskNames then
        set diskIsMounted to false
    end if
    if diskIsMounted is false then
        mount volume "smb://192.168.1.1/"
        delay 30
        do shell script "hdiutil attach -mountpoint '/Volumes/Time Machine' /Volumes/Guille/TimeMachine.sparsebundle"
    end if
    if diskIsMounted is true then
    end if
end if
return 300
end idle

However, every once in a while, I get this error: enter image description here

It doesn't really bother me because if I just click on OK it goes away and tries again 5 minutes later. However, I would like to know if there's a way to make sure these dialogs are automatically dismissed so they don't interrupt my workflow and Time Machine stays unobtrusively in the background until I accidentally send something to the trash :-)

  • I'd use a try statement, and probably do it in conjunction with an on error statement handler, thus trapping the error and avoiding the error message showing as it presently is. With the use of an on error statement handler, I'd choose to have the error message display in Notification Center using a display notification command, as it doesn't require user interaction to dismiss and less likely to adversely disrupt the workflow, in comparison to having to manually dismiss the error message you're presently getting. – user3439894 Jun 30 '17 at 13:02
  • Why is your awk command using a substr() function when awk '/ SSID/{print $2}' is all that's needed to get the SSID from the output of the /S*/L*/P*/A*/V*/C*/R*/airport -I command? – user3439894 Jul 1 '17 at 13:23
1

I'm really only a beginner to scripting, but I'm wondering why you have so much code in your script. I was able to accomplish the exact same results with using only a couple of commands.

mount volume "smb://192.168.2.66/"
do shell script "hdiutil attach -noverify '/Volumes/Data_Smokestack_ATC/James’s MacBook Pro.sparsebundle'"

I have both of my Airport Time Capsules set with static IPv4 addresses, so their IP’s never change (so I always know how to connect to them if I need to)

The do shell script part of my code waits until the mount volume command completes, therefore, I did not need to insert a delay command. On my system using the latest version of macOS Sierra, if I run this code again while the volume is already mounted, this script just quietly completes with no errors or messages.

That said, my thought is wouldn't it just be more “code efficient” to run these two lines of code inside of a repeat loop at 15 minute intervals for 12 or 24 hours or something like that? Then to be saved as a stay open application?

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .