Mount Drive based on connection with if else statement (applescript)

Solution 1:

  1. Your set ping to statement should have the closing quote after the IP address

  2. In general you are missing a number of end statements. Each try should have a corresponding end try, each tell should have an end tell, each if should have an end if.

  3. The try statements should surround the script action, not inside them. So move them before the tell statements. As you are using them without the 'on error' clause, the try statements aren't very useful - but no harm.

  4. The application should be just "Finder"

Here's a briefer example:

try
    set ping to (do shell script "ping -c 2 192.168.1.240")
    
    if ping contains "64 bytes" then
        try
            tell application "Finder"
                mount volume "smb://192.168.1.240./music"
            end tell
        end try
        display dialog "Mapped Drives to 192.168.1.240 Network."
        
    else
        try
            tell application "Finder"
                mount volume "smb://192.168.0.240./music"
            end tell
        end try 
        display dialog "Mapped Drives to 192.168.0.240 Network."
        
    end if
end try