3

Yesterday, I found a script that makes my Mac (MacBook Pro running El Capitan) automatically check for a volume on a server and remount it if the connection drops. I adapted it slightly to this, so my media server would remount when it drops (which is frequently):

on idle
    tell application "Finder"
        set isConnected to disk "Plex" exists
    end tell
    if isConnected = false then
        try
            mount volume "Plex" on server "smb://USER:PASSWORD@192.168.0.10:445"
        end try
    end if
    return 5
end idle

I saved the script as a Script Editor app using the "Stay open after run handler" option, so it runs in the background.

Yesterday it worked fine. Today, when it attempts to remount the Plex volume I get a "There was a problem connecting to the server" error.

However, I can connect to the server using the 'Connect to Server' command by entering the same IP address, user ID and password.

I'm logging into the NAS with an admin account, so there shouldn't be any disk permission issues.

Is there something in the script I've scrambled, or is this an issue with the Mac or NAS?

I'm completely new to scripting, so I may ask for clarifications on any answers.

I would like to include a link to the original script, but I can't recall where I found it.

Thanks.

1

I managed to solve this problem by 'borrowing' some code from a blog I found.

on idle
    set intnt to do shell script "ping -c 1 192.168.0.10; echo -n"
    set paras to number of paragraphs in intnt
    if paras < 5 then
    else
        set serverIP to "smb://192.168.0.10/Plex"
        set UserAccount to "[USERNAME]"
        set ServerPassword to "[PASSWORD]"
        set serverVolume to UserAccount
        tell application "Finder"
            try
                if disk serverVolume exists then
                else
                    mount volume serverIP as user name UserAccount with password ServerPassword
                end if
            end try
        end tell
    end if
    return 5
end idle

I also found that if you add this code to the end of an app's info.plist file, its icon doesn't appear on the Dock.

Just copy-and-paste these lines before the final /dict entry.

Downside is I have to use Activity Manager or Terminal to kill the app, but it makes for a tidier Dock.

<key>LSUIElement</key>
<true/>
  • 1
    Please mark this as the accepted answer. – ʀ2ᴅ2 Feb 27 '18 at 18:24
0

AppleScript can be a bit buggy. Recently, I've had a few scripts that were bugging out for no apparent reason. I made a small change, saved, then undid the change, and saved it again, and the problem went away... Until it came back a week or so later (an old, recurring problem). I'm not entirely certain if that will fix it in your case, but one point of note: You don't need to specify the port number at the end of the domain name or IP address, if the port is the default for the protocol. Port 445 is the default for SMB. You can remove the entire ":445" part. With unreliable languages, you never know what might fix your issue.

  • Thanks. I tried the removing the "445" reference, but that didn't squash the bug. – Richard Cosgrove Oct 14 '15 at 16:11

You must log in to answer this question.

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