In Applescript, how can I read a website and output the text as a variable?

In Applescript, how can I read a website and output the text as a variable?

I want to read the "Latest" number from here and then use that number to download the latest version of Chromium from here .

+1


a source to share


3 answers


Not a direct Applescript method, but it works well.

Create a shell script to do the download, say chrome-download.sh in your $ HOME / bin directory:

#!/bin/sh
BUILD=`curl http://build.chromium.org/buildbot/snapshots/sub-rel-mac/LATEST`
echo "Downloading build "$BUILD
curl http://build.chromium.org/buildbot/snapshots/sub-rel-mac/$BUILD/chrome-mac.zip -o $HOME/chrome-mac-$BUILD.zip

      



Run it from Applescript (or Automator) in one line:

do shell script "/bin/bash /Users/<your username>/bin/chrome-download.sh"

      

The downloaded file goes into your $ HOME directory. bash script will work with both Linux and Cygwin. Of course, you could just run a bash script too.

+2


a source


As Glenn said, it is much easier to just use a wrapper script and perhaps wrap it in AppleScript with do shell script

. Another alternative if you want the graphical interface for the script to be a program called Platypus .



Finally, if you're looking for a sample script that already does this, I made it when Chromium Mac was announced a couple of days ago: http://chealion.ca/2009/05/chromium-build-bot-updater-script/ (source on GitHub).

+2


a source


A more AppleScript-friendly way would be:

set filePath to (path to temporary items folder as string) & "file.html"

tell application "URL Access Scripting"
    download "http://www.apple.com/sitemap/" to file filePath replacing yes
end tell

--read file into a variable
try
    open for access (file filePath)
    set fileData to (read file filePath)
    close access (file filePath)
on error errMsg number errNum
    try
        close access file filePath
    end try
    error errMsg number errNum
end try

      

For more information, see the dictionaries for accessing the script URL and standard applications. (File> Open Dictionary)

+1


a source







All Articles