|
Next: Any way to get Software Update to run in the back..
|
| Author |
Message |
External

Since: Dec 31, 2007 Posts: 8
|
(Msg. 1) Posted: Mon Dec 31, 2007 7:22 pm
Post subject: Can Applescript tell if computer is online? Archived from groups: alt>comp>lang>applescript (more info?)
|
|
|
Hi there,
I would like to write a conditional Applescript. The script would
trigger itself every few hours and if the computer is not connected to
the Internet I would like it to execute some code. I have a bit of
experience with AS but have no idea how to go about this one.
Perhaps: "if Safari gets message "computer not connected to the
internet" then execute this code"...
Am I on the right track?
Thank you much
Karotto |
|
| Back to top |
|
 |  |
External

Since: Aug 24, 2005 Posts: 120
|
(Msg. 2) Posted: Tue Jan 01, 2008 6:50 pm
Post subject: Re: Can Applescript tell if computer is online? [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
In article
<a80b8e5e-7e80-4bf2-8215-497ef86c0e51.TakeThisOut@h11g2000prf.googlegroups.com>,
biz.TakeThisOut@theplayspace.com.au wrote:
> I would like to write a conditional Applescript. The script would
> trigger itself every few hours and if the computer is not connected to
> the Internet I would like it to execute some code.
You'll need to define what constitutes "connected to the Internet".
There is no way to ceck for that condition. However, if you define what
it means to *you*, tere will be certain conditions that *can* be checked
for. You could for instance check if the machines has a
non-self-assigned IPv4 address:
property s_saIP : "269.254"
set s_IP4 to IPv4 address of (system info)
if s_IP4 does not start with s_saIP then
-- we are connected to a network
doStuff()
end if
on doStuff()
-- do stuff
end doStuff
This assumes [1] that the Mac uses IPv4, [2] that is set up to be
assigned an address (by a DHCP server), [3] that the network the Mac
conects to is actually connected to/part of "the Internet".
For some reason (Tiger's) Standard Additions allows checking forthe
primary IPv4 address only. If you use IPv6 or care about different
network interfaces (Ethernet, Airport, FireWire, etc.), you'll prolly
need to use do shell script.
> I have a bit of
> experience with AS but have no idea how to go about this one.
> Perhaps: "if Safari gets message "computer not connected to the
> internet" then execute this code"...
> Am I on the right track?
Yes, except that the Web, let alone Safari, is not "the Internet". It's
perfectly possible to be connected to the Internet and yet not be able
to fetch something off the Web.
--
Sander Tekelenburg, <http://www.euronet.nl/~tekelenb/>
Mac user: "Macs only have 40 viruses, tops!"
PC user: "SEE! Not even the virus writers support Macs!" |
|
| Back to top |
|
 |  |
External

Since: Dec 31, 2007 Posts: 8
|
(Msg. 3) Posted: Wed Jan 02, 2008 5:38 am
Post subject: Re: Can Applescript tell if computer is online? [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
On Jan 2, 4:50 am, Sander Tekelenburg <u... RemoveThis @domain.invalid> wrote:
> In article
> <a80b8e5e-7e80-4bf2-8215-497ef86c0... RemoveThis @h11g2000prf.googlegroups.com>,
>
> b...@theplayspace.com.au wrote:
> > I would like to write a conditional Applescript. The script would
> > trigger itself every few hours and if the computer is not connected to
> > the Internet I would like it to execute some code.
>
> You'll need to define what constitutes "connected to the Internet".
> There is no way to ceck for that condition. However, if you define what
> it means to *you*, tere will be certain conditions that *can* be checked
> for. You could for instance check if the machines has a
> non-self-assigned IPv4 address:
>
> property s_saIP : "269.254"
> set s_IP4 to IPv4 address of (system info)
> if s_IP4 does not start with s_saIP then
> -- we are connected to a network
> doStuff()
> end if
>
> on doStuff()
> -- do stuff
> end doStuff
>
> This assumes [1] that the Mac uses IPv4, [2] that is set up to be
> assigned an address (by a DHCP server), [3] that the network the Mac
> conects to is actually connected to/part of "the Internet".
>
> For some reason (Tiger's) Standard Additions allows checking forthe
> primary IPv4 address only. If you use IPv6 or care about different
> network interfaces (Ethernet, Airport, FireWire, etc.), you'll prolly
> need to use do shell script.
>
> > I have a bit of
> > experience with AS but have no idea how to go about this one.
> > Perhaps: "if Safari gets message "computer not connected to the
> > internet" then execute this code"...
> > Am I on the right track?
>
> Yes, except that the Web, let alone Safari, is not "the Internet". It's
> perfectly possible to be connected to the Internet and yet not be able
> to fetch something off the Web.
>
> --
> Sander Tekelenburg, <http://www.euronet.nl/~tekelenb/>
>
> Mac user: "Macs only have 40 viruses, tops!"
> PC user: "SEE! Not even the virus writers support Macs!"
Thank you for your reply but this does not work. I always get
"10.37.129.3" as IPv4 address regardless if I am online or not. I am
using Leopard.
Thank you |
|
| Back to top |
|
 |  |
External

Since: Dec 31, 2007 Posts: 8
|
(Msg. 4) Posted: Wed Jan 02, 2008 5:14 pm
Post subject: Re: Can Applescript tell if computer is online? [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
On Jan 3, 11:20 am, Jolly Roger <jollyro....TakeThisOut@pobox.com> wrote:
> In article <1ia44xt.13adiv31by0hzyN%itera...@inode.at>,
> itera...@inode.at (Michael Hawelka) wrote:
>
>
>
> > <b....TakeThisOut@theplayspace.com.au> wrote:
>
> > > if the computer is not connected to
> > > the Internet I would like it to execute some code
>
> > how about something like
>
> > set theResult to ""
> > try
> > set theResult to (do shell script "ping -o -t 2www.google.com")
> > end try
> > if (theResult contains "1 packets received") then
> > display alert ("i am online")
> > else
> > display alert ("i am offline")
> > end if
>
> But what if google.com goes down for maintenance?
>
> --
> Note: Please send all responses to the relevant news group. If you
> must contact me through e-mail, let me know when you send email to
> this address so that your email doesn't get eaten by my SPAM filter.
>
> JR
Thanks. That almost work. I guess I conceiled some information. What
you told me works great if my ethernet cable is unplugged. However,
sometimes my router deletes my password and user id. It is for these
situations I need the Applescript. When that happens I am online but I
can only reach my ISP's site telling me that Ihave the wrong password.
Unfortunately, I can still ping websites (although I cannot browse the
we because I always get my ISP's website). So the script can actually
tell if I can go to a website (like google. and I don't care if it's
down for maintanance. Happens rarely). Sorry I did not disclose all
information . thanks for your help |
|
| Back to top |
|
 |  |
External

Since: Jan 03, 2008 Posts: 1
|
(Msg. 5) Posted: Thu Jan 03, 2008 12:00 am
Post subject: Re: Can Applescript tell if computer is online? [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
<biz RemoveThis @theplayspace.com.au> wrote:
> if the computer is not connected to
> the Internet I would like it to execute some code
how about something like
set theResult to ""
try
set theResult to (do shell script "ping -o -t 2 www.google.com")
end try
if (theResult contains "1 packets received") then
display alert ("i am online")
else
display alert ("i am offline")
end if
Mike |
|
| Back to top |
|
 |  |
External

Since: Nov 05, 2007 Posts: 1218
|
(Msg. 6) Posted: Thu Jan 03, 2008 12:00 am
Post subject: Re: Can Applescript tell if computer is online? [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
In article <1ia44xt.13adiv31by0hzyN%iterate4@inode.at>,
iterate4 DeleteThis @inode.at (Michael Hawelka) wrote:
> <biz DeleteThis @theplayspace.com.au> wrote:
>
> > if the computer is not connected to
> > the Internet I would like it to execute some code
>
> how about something like
>
> set theResult to ""
> try
> set theResult to (do shell script "ping -o -t 2 www.google.com")
> end try
> if (theResult contains "1 packets received") then
> display alert ("i am online")
> else
> display alert ("i am offline")
> end if
But what if google.com goes down for maintenance?
--
Note: Please send all responses to the relevant news group. If you
must contact me through e-mail, let me know when you send email to
this address so that your email doesn't get eaten by my SPAM filter.
JR |
|
| Back to top |
|
 |  |
External

Since: Aug 24, 2005 Posts: 120
|
(Msg. 7) Posted: Thu Jan 03, 2008 2:56 pm
Post subject: Re: Can Applescript tell if computer is online? [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
In article
<4a8b5a8e-d136-4040-8919-03177f12141d.RemoveThis@e10g2000prf.googlegroups.com>,
biz.RemoveThis@theplayspace.com.au wrote:
[... condition to check]
> I can still ping websites (although I cannot browse the
> we because I always get my ISP's website).
Then try something like this:
set theResult to ""
try
set theResult to (do shell script "curl -I http://ww.google.com")
end try
if (theResult contains "HTTP/1.1 ") then
display alert ("i am online")
else
display alert ("i am offline")
end if
--
Sander Tekelenburg, <http://www.euronet.nl/~tekelenb/>
Mac user: "Macs only have 40 viruses, tops!"
PC user: "SEE! Not even the virus writers support Macs!" |
|
| Back to top |
|
 |  |
External

Since: Dec 31, 2007 Posts: 8
|
(Msg. 8) Posted: Thu Jan 03, 2008 4:13 pm
Post subject: Re: Can Applescript tell if computer is online? [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
On Jan 4, 12:56 am, Sander Tekelenburg <u....TakeThisOut@domain.invalid> wrote:
> In article
> <4a8b5a8e-d136-4040-8919-03177f121....TakeThisOut@e10g2000prf.googlegroups.com>,
>
> b...@theplayspace.com.au wrote:
>
> [... condition to check]
>
> > I can still ping websites (although I cannot browse the
> > we because I always get my ISP's website).
>
> Then try something like this:
>
> set theResult to ""
> try
> set theResult to (do shell script "curl -Ihttp://ww.google.com")
> end try
> if (theResult contains "HTTP/1.1 ") then
> display alert ("i am online")
> else
> display alert ("i am offline")
> end if
>
> --
> Sander Tekelenburg, <http://www.euronet.nl/~tekelenb/>
>
> Mac user: "Macs only have 40 viruses, tops!"
> PC user: "SEE! Not even the virus writers support Macs!"
Thanks for the suggestion but it does not work. The script still
thinks I am online even if I can only reach my ISP's website. I am
surprised there is not a simple parameter that can tell if I actually
can load a website like google or not. Any more suggestions or are we
out of options? Thank you much. |
|
| Back to top |
|
 |  |
External

Since: Dec 31, 2007 Posts: 8
|
(Msg. 9) Posted: Thu Jan 03, 2008 5:05 pm
Post subject: Re: Can Applescript tell if computer is online? [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
On Jan 4, 11:13 am, b....RemoveThis@theplayspace.com.au wrote:
> On Jan 4, 12:56 am, Sander Tekelenburg <u....RemoveThis@domain.invalid> wrote:
>
>
>
> > In article
> > <4a8b5a8e-d136-4040-8919-03177f121....RemoveThis@e10g2000prf.googlegroups.com>,
>
> > b...@theplayspace.com.au wrote:
>
> > [... condition to check]
>
> > > I can still ping websites (although I cannot browse the
> > > we because I always get my ISP's website).
>
> > Then try something like this:
>
> > set theResult to ""
> > try
> > set theResult to (do shell script "curl -Ihttp://ww.google.com")
> > end try
> > if (theResult contains "HTTP/1.1 ") then
> > display alert ("i am online")
> > else
> > display alert ("i am offline")
> > end if
>
> > --
> > Sander Tekelenburg, <http://www.euronet.nl/~tekelenb/>
>
> > Mac user: "Macs only have 40 viruses, tops!"
> > PC user: "SEE! Not even the virus writers support Macs!"
>
> Thanks for the suggestion but it does not work. The script still
> thinks I am online even if I can only reach my ISP's website. I am
> surprised there is not a simple parameter that can tell if I actually
> can load a website like google or not. Any more suggestions or are we
> out of options? Thank you much.
I GOT IT! Thanks alot. Just had to change the wording a bit (if
contains "google" then...) and now it works fine. Thanks again |
|
| Back to top |
|
 |  |
External

Since: Aug 24, 2005 Posts: 120
|
(Msg. 10) Posted: Fri Jan 04, 2008 5:58 am
Post subject: Re: Can Applescript tell if computer is online? [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
In article
<384431b0-3178-4239-a376-410395b0abfd.TakeThisOut@e10g2000prf.googlegroups.com>,
biz.TakeThisOut@theplayspace.com.au wrote:
> On Jan 4, 12:56 am, Sander Tekelenburg <u....TakeThisOut@domain.invalid> wrote:
[...]
> > set theResult to (do shell script "curl -Ihttp://ww.google.com")
That's not what I posted. Look carefully at my origial text. You removed
a space -- an essential one (as all characters are, in programming  ).
Either you somehow messed up the quoting manually, or your newsclient
(Google apparently), screwed things up. Given that your quoting habit
sucks anyway, my bet is that Google is to blame. I suggest you upgrade
to a real newsclient. Plenty of options: <http://www.newsreaders.com/>.
In article
<847897e1-6163-4631-a1b2-89b74e839355.TakeThisOut@s12g2000prg.googlegroups.com>,
biz.TakeThisOut@theplayspace.com.au wrote:
> I GOT IT! Thanks alot. Just had to change the wording a bit (if
> contains "google" then...) and now it works fine. Thanks again
You're welcome, but your change makes it less reliable. There is no
guarantee that the result will contain the string "google". That string
just happens to be in what Google's servers output today, and only for
certain addresses, and very likely only to certain IP addresses, etc.
What I posted is far more reliable. If it doesn't work, you're running
something else than what I posted. (Every character counts, so be
careful when copy&pasting code -- especially beware of linewraps
introduced by newsclients, newsservers, etc.)
--
Sander Tekelenburg, <http://www.euronet.nl/~tekelenb/>
Mac user: "Macs only have 40 viruses, tops!"
PC user: "SEE! Not even the virus writers support Macs!" |
|
| Back to top |
|
 |  |
External

Since: Nov 05, 2007 Posts: 1218
|
(Msg. 11) Posted: Fri Jan 04, 2008 5:58 am
Post subject: Re: Can Applescript tell if computer is online? [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
In article <user-AF708D.05585604012008 DeleteThis @textnews.euro.net>,
Sander Tekelenburg <user DeleteThis @domain.invalid> wrote:
> I suggest you upgrade
> to a real newsclient. Plenty of options: <http://www.newsreaders.com/>.
MT-NewsWatcher is arguably the best news client available for Mac OS X.
--
Note: Please send all responses to the relevant news group. If you
must contact me through e-mail, let me know when you send email to
this address so that your email doesn't get eaten by my SPAM filter.
JR |
|
| Back to top |
|
 |  |
| Related Topics: | update applescript - I am only now practiced enough in Applescript that some anomalies in the language are bugging me. In looking for work-arounds, one of the first documents I read was the Apple web page listing all the bugs in version 1.9.1. I have version 1.9.1 on os...
Please help with this applescript code - The line below is part of an Applescript macro that works fine for converting Appleworks documents to RTF format. Can anyone please tell me how I amend this line of code to save Appleworks documents in ASC (Ascii) text format. (ASC is one of the 'Save As...
Help with a BBEdit AppleScript - I need to insert Quark tags into a text file that is exported from a classified ads application. I just can't seem to get the syntax right to have a font tag <f"LegalNews-Bold> inserted at the beginning of the line before the date tag. For...
New AppleScript features in 10.5 - On this page <http://www.apple.com/applescript/> (which is formatted in a very un-Apple manner) there's a list of the new features in AppleScript, with each on a clickable link. Some look interesting and I don't want to torpedo any fun discussio...
How do I get an applescript to run as a cron job? - Hello, I have written a very simple script that opens a Filemaker file and runs a script. Here's the script: tell application "FileMaker Pro" open file "MyFile.fp7" do script "LaunchMyScript" end tell I want to have... |
|
You can post new topics in this forum You can reply to topics in this forum You can edit your posts in this forum You can delete your posts in this forum You can vote in polls in this forum
|
|
|
|