Problem with Curl

I have a equipment (a scale) on my small Network that displays the weight on any browser, any computer as I type “[url=http://Http://169.254.79.250/MostraPeso.shtm]Http://169.254.79.250/MostraPeso.shtm[/url]” as the url.

I am trying to create an Apple script to write a log file cotaining returned data and time, etc…

I can’t begin my script because I am stuck on this:

  1. I type “curl -A “Mozilla/4.0” http://169.254.79.250/MostraPeso.shtm” on the terminal and get this:

I have wrote this script:

and get “can’t make some data into expected type”

Shouldnt it show the same result as on the terminal?

What am I doing wrong?

Thanks!

Is that your entire script? or is there more to it?

As it stands, your two-line script works fine here (once given a URL I can access), so I’m thinking there must be more to your script.

When the error appears, the Script Editor will highlight the part of the script that failed. What part of the script is selected when this happens?

Hi Camelot!

Thanks for replying.

This is my whole script at this moment. After I can get it to work, I will continue writting it.

Here at my work I have 3 computer on the LAN and 1 is a Mac with Apache enabled. If I change the URL on the script, pointing it to the Mac with Apache running, the script works.

But it won’t work with the web server in the scale I am trying to access.

On the terminal of Mac OS X (10.2.8) I type the curl -a comand and get a result. But the script fails…

Can’t understand why…

I apreciate any help. May be I should try a diferente aproach to the problem of getting the source code from the Web Server running on the scale.

What happens if you use a plain curl command in your script like so;

do shell script “curl http://169.254.79.250/MostraPeso.shtm
set curl_output to the result

What data do you want to get out of the web page?

What is the web server for the scale? A computer or is it something “built in” to the scale?

cheers,

dAVE

Hello Dave!

Thanks for posting.

If I do a script just like you replied I get the same error message mentioned before. I tried it. But what puzzzles me is that the same comand on the Terminal displays the souce code of the page! The error only happens within Applescript!

May be it happens because of a special characther not suported by Applescript? Can you see a “?” character on the code?

The scale is not a computer. It has a special card built inside that enables it to be connected to the LAN, and “serve” a site from where I can see the weight on the scale and do some configuration of the equipment.

In our country, we don’t use pounds for measuring weight. We use Kilograms. So the weight displayed on the scale at the moment I captured the source code I posted in this topic was “0,0 Kg”. Please note the weight on the souce code.

I intend to write an Applescript that will capture the html code, filter the value just before “Kg”, check if it is diferent than zero or diferent than the previous value and write a text log like this:

On February 4th at 13:13 hrs the weight changed to 1234,0 Kg.
On February 4th at 13:45 hrs the weight changed to 2638,0 Kg.
On February 4th at 13:58 hrs the weight changed to 875,0 Kg.
On February 4th at 14:23 hrs the weight changed to 234,0 Kg.

I think I should take a diferent approach to the problem. But have no idea how.

May be write a script to run a browser function?

Thanks for any help!

hmm. Possibly curl needs the full path name to run in the ‘do shell script’.

in the Terminal, do
which curl
it should come back and tell you
/usr/bin/curl

then change the applescript to be
do shell script “/usr/bin/curl http://169.254.79.250/MostraPeso.shtm

Let me know if that makes any difference!

Is there any other way to get data from the scale? like telnet or syslog or something else…

I made a copy of the page on my machine, and it works fine once I changed the refresh to point to the right page <mine ;-)>.

You only want the first number on the page? The others won;t be used?

dAVE

Hi Dave!

I didn’t try the full path.

It is a good idea trying. I am at home right now. I will try it tomorow morning.

My scale can weight up to 3.500,0 Kg (in Brazil we use comas for decimals and periods for thousands), so I believe I will need to capture the seven characteres before “Kg”…

I tryed this on the Terminal:

It works if I paste the code on the terminal and hit return twice very quickly.

But didn’t try writing a script for it.

Hello again…

I ran across a book called “Wicked Cool Shell Scripts” today, and one of the examples is exactly what you need!!

I am using BBedit, but you can use any text editor, as long as it uses unix return characters in the file. If you are not sure you can also copy the script and then, in the terminal, do ‘pbpaste > cleaner.script’ which will paste the text into a new file. Then go to the file’s directory and do ‘chmod +x cleaner.script’ to make it executable.

#!/bin/sh

Original is from the book “Wicked Cool Shell Scripts” by No Starch Press.

This script is modified from the example found in http://www.nostarch.com/wcss_60.pdf

url=‘http://169.254.79.250/MostraPeso.shtm
curl $url |
sed ‘s/</
</g;s/>/>
/g’ |
grep -v -E ‘(<|>)’ |
fmt |
uniq -u

To test it, in the terminal, do ‘./cleaner.script | less’ while in the same directory as the script.

Now for the easy part, the beginning of your Applescript:

set result_items to {“”}
– change the line below to where your script is. Use the full path!
set feedback to do shell script “/Users/davidr/Desktop/temp/cleaner.shellscript”
– paragraph 5 is the line after “Peso Atual (PESO ESTVEL):”
set item 1 of result_items to paragraph 5 of feedback
display dialog feedback

Am I ever glad I found that shell script! It looks very useful for a whole bunch of other scripts…

Now what? :wink:

dAVE … who learned a whole bunch of new things today!

Hi dave!

Your script runs just fine!

Thanks very much!

I will order the book right now.

My script looks like this:

Need to add a repeating line to it. ( I wrote my first script just 2 weeks ago, am totally new to Applescript)

Could you help me?

I think it should be something while true o false, etc…

Thanks any way for your great help so far!

Hi,

Glad to hear the script works well.

A few quick questions… how often do you wnat the script to run? Do you want to use text-edit plus, or would you prefer to write the data straigh to a text file? if the result is " 0,0kg" do you want to put it in the file or skip it until there is data?

Check out the Apple site for some good Applescript tutorials, http://www.apple.com/applescript/guidebook/sbrt/index.html

Also take a look at the Script Menu, http://www.apple.com/applescript/scriptmenu/ which has a whole bunch of useful scripts in it.

I’ll be back after lunch with a repeat loop :wink:

dAVE

writing to a text file without the use of tex edit plus would be better, since I would need to have the Tex app running.

I only use tex edit Plus because it is “recordable”. Helps a lot…

Thanks again!

Sorry!

Did not answer your question:

The script running every 10 seconds would be ok.

Thanks for the URLs…

I added them to my bookmarks…