Thursday, April 21, 2011

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

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

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

From stackoverflow
  • Not a direct Applescript way, but this 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 lands in your $HOME directory. The bash script will work from Linux or Cygwin, as well. Of course, you could just run the bash script directly, too.

  • As Glenn said it's much easier to just use a shell script and possibly wrap it in AppleScript by using do shell script. Another alternative if you want a GUI of sorts to the script is to look at a program called Platypus.

    Lastly if you're looking for a sample script that already does this I made one when Chromium Mac was announced a couple days back: http://chealion.ca/2009/05/chromium-build-bot-updater-script/ (Source on GitHub).

0 comments:

Post a Comment