Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Applescript to test DSL connection - problem

My home internet connection is so poor, I decided to write the following Applescript to monitor the connection and record data so that I can provide this information to the service provider (along with a request for a refund!). Basically the script checks the connection every 2 minutes and records whether the connection is up or down, along with a date and time stamp:


on idle

try

set the_file to "Macintosh HD:Users:farman:Desktop:DSL_log.txt"

set the_file to quoted form of POSIX path of the_file

do shell script "curl www.apple.com"

set success to " DSL OK"

set d to (current date) as string

do shell script "echo " & d & success & " >> " & the_file

say DSL is OK"

on error

set the_file to "Macintosh HD:Users:farman:Desktop:DSL_log.txt"

set the_file to quoted form of POSIX path of the_file

set failure to " DSL down"

set d to (current date) as string

do shell script "echo " & d & failure & " >> " & the_file

say "DSL is down"

end try

return 120

end idle


The only problem is that sometimes when I am unable to connect to the web (i.e. web pages don't show up), my Speedstream router pops up a window that tells me that the DSL down, but the script tells me the DSL is still OK. Any idea what gives? I'm guessing the connection is sufficient to return success on the curl command but is too noisy to allow a complete page to load. Are there perhaps other ways to test the connection?

MacBook Pro, Mac OS X (10.5.6)

Posted on Sep 13, 2011 8:05 PM

Reply
9 replies

Sep 14, 2011 9:34 AM in response to mlf64

I been thinking of writting a script to test download speed. Web sites I've seen require flash & flash support has been dropped in my preferred browser.


Have you thought about ping?


mac $ ping -c20 google.com

PING google.com (74.125.115.147): 56 data bytes

64 bytes from 74.125.115.147: icmp_seq=0 ttl=53 time=33.400 ms

64 bytes from 74.125.115.147: icmp_seq=1 ttl=53 time=30.325 ms

64 bytes from 74.125.115.147: icmp_seq=2 ttl=53 time=31.554 ms

64 bytes from 74.125.115.147: icmp_seq=4 ttl=53 time=30.980 ms

64 bytes from 74.125.115.147: icmp_seq=6 ttl=53 time=31.634 ms

64 bytes from 74.125.115.147: icmp_seq=8 ttl=53 time=30.091 ms

64 bytes from 74.125.115.147: icmp_seq=10 ttl=53 time=31.693 ms

64 bytes from 74.125.115.147: icmp_seq=12 ttl=53 time=29.364 ms

64 bytes from 74.125.115.147: icmp_seq=14 ttl=53 time=32.580 ms

64 bytes from 74.125.115.147: icmp_seq=15 ttl=53 time=30.922 ms

64 bytes from 74.125.115.147: icmp_seq=16 ttl=53 time=29.523 ms

64 bytes from 74.125.115.147: icmp_seq=18 ttl=53 time=28.277 ms

64 bytes from 74.125.115.147: icmp_seq=19 ttl=53 time=30.520 ms


--- google.com ping statistics ---

20 packets transmitted, 13 packets received, 35% packet loss

round-trip min/avg/max/stddev = 28.277/30.836/33.400/1.327 ms

mac $


could look at packet loose. My results look bad, but I'm on the Internet.


got strange results from apple apple.com was slow or dead, ww.apple.com worked, www.apple.com didn't


Robert

Sep 15, 2011 12:19 PM in response to rccharles

OK Robert,


I'm trying to use awk to extract the average transfer speed as follows:


on idle

try

set the_file to "Macintosh HD:Users:farman:Desktop:text.txt"

set the_file to quoted form of POSIX path of the_file

set intnt to do shell script "ping -c10 google.com | awk -F \/ '/stddev/ {print $6 }'"

tell application "Finder"

set p to intnt

if p < 500 then

say "DSL is OK"

set success to " DSL OK"

set d to (current date) as string

do shell script "echo " & d & success & " >> " & the_file

else

set the_file to "Macintosh HD:Users:farman:Desktop:text.txt"

set the_file to quoted form of POSIX path of the_file

set failure to " DSL down"

set d to (current date) as string

do shell script "echo " & d & failure & " >> " & the_file

say "DSL is down"

end if

end tell

end try

return 15

end idle


but I get an "expected """ but found unknown token" error.


I'm about to give up!

Sep 15, 2011 3:56 PM in response to rccharles

This needs more work, but it's enough to hack.


applescript has a timeout. however, it only works with application. do shell script isn't an application.😢


applescript # 1

problem. for some reason this always errors out. run will invoke timeoutActual, but will also get an error. don't know why. You will have to look at reason for error. You will get timeout error if a timeout occurs. You may need to run this stuff from outside of the applescript editor. I dont know how to pass data nor get data back 😟 There is always a file.



try

with timeout of 2 seconds

tell application "timeoutActual"

run

end tell

end timeout

on error errorMsg

display dialog "Ok we got an error." & errorMsg

end try



applescript Save as application bundle with name of timeoutActual


--set intnt to do shell script "sleep 10"

-- set intnt to do shell script "ping -c10 google.com | awk -F / '/stddev/ {print $6 }'"

display dialog "timeoutActual is running" giving up after 5


return 0





-------------------------------------


Rosenthal is the best book on Applescript that I have seen.

Learn AppleScript: The Comprehensive Guide to Scripting and Automation on Mac OS X, Third Edition the book


It's free & complete.

AppleScript Language Guide pdf download the pdf file

Sep 16, 2011 3:34 PM in response to rccharles

i read about stay open applets today.

on run
    (*    

    This code didn't seem to do the trick.

    You need to manually  start up doShellScriptApp. Be sure to click ok to all the messages or get rid of them.



    tell application "Finder"
        open application file "doShellScriptApp.app" of folder "applescriptFiles" of folder "Applications" of startup disk
    end tell

    *)

    -- Do we need to wait for the application to load?
    delay 5
    beep
    beep
    beep


    set passData to "ping -c10 google.com | awk -F / '/stddev/ {print $6 }'"

    try
        with timeout of 20 seconds
            tell application "doShellScriptApp"
                activate
                set returnedData to doShell(passData)
                display dialog "returned data " & return & returnedData giving up after 25

            end tell
        end timeout
    on error errorMsg
        display dialog "Ok we got an error:  " & return & errorMsg giving up after 25

        return 0
    end try

    tell application "doShellScriptApp"
        activate
        doQuit()
    end tell

    return 0

end run



here is doShellScriptApp

You need to have saved it before saving the above script. be sure to save as an application bundle with stay open flag set.



(* 
When saving, set the do not quit flag.

Should the calling script not quit this application when
done you will need to force quit.  
run activity monitor to quit.

or force quit application.  use keys:
optoin + command + esc

*)




on run
    display dialog "in run..." giving up after 3

end run

on doShell(passedData) --set intnt to do shell script "sleep 10"

    display dialog "timeoutActual is running doShell " & passedData giving up after 5
    set theData to do shell script passedData
    return theData

end doShell

on doQuit()
    display dialog "in doQuit " giving up after 5


    -- bye bye to this app
    continue quit
    return 0

end doQuit

Applescript to test DSL connection - problem

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.