Archive for the 'Applescript' Category

Hell froze over

Wednesday, March 12th, 2008

Apple updated their Applescript language guide. I did not see that one coming.

Call Cocoa from Applescript

Monday, September 17th, 2007

I saw this article on MacScripter. It describes using call method to access Cocoa objects and methods. Awesome. I don’t have a use for it offhand but I know I’ll use it in the future.

[AS] Applescript and the command line

Tuesday, July 31st, 2007

I just learned today that osascript (the command line Applescript interpreter) will print the result of the last statement made to stdout. This is good because it doesn’t like commands like display dialog (there’s no windowing system for the command line) or log (which seems to be a Script Editor-only thing). So, to print to stdout, you’d likely do something like the following:

property stdout : ""
on run(arg) -- As an aside, you can also pass args to applescripts using the `on run` handler
    (* Do stuff *)
    set stdout to stdout & "Stage 1 status: complete"

    (* Do more stuff *)
    if success then
        set stdout to stdout & return & "Stage 2 status: complete"
    else
        set stdout to stdout & return & "Stage 2 status: failed"
    end if
    stdout -- Will put stdout in result which will be written to the terminal
    -- Alternatively, you could write `set result to stdout`
end run

[AS] Execute bundled scripts correctly

Friday, July 27th, 2007

I’m planning on releasing some Python scripts that I’ve been working on later this week after I get some more testing done. I’m aware that many people are not familiar with Python or the command line so I thought I’d wrap it all up in an applescript application. Script Editor allows me to make script bundles that keep all of the files together. Unfortunately, do shell script does some funky things. I’ve got several versions of Python installed and running do shell script didn’t use the one that I preferred. I couldn’t hard code the path to my preferred Python because many users may have Python installed in a different place (either the default location, or using a package manager like Fink or MacPorts).

In a somewhat fortuitous result, the which command would return the path for my preferred Python installation. Now, in order to make sure that the preferred python is used, I do this in my scripts:

pythonpath = do shell script "which python"
do shell script pythonpath & " " & pathtoscript

So far, this has always used the python installation I expected.

Safari’s new page load progress indicator

Monday, June 18th, 2007

I saw this flickr photo today. It shows Safari’s new circular/pie progress indicator for page loads. The photo includes the command that makes the necessary changes. I wrapped it up in a little Applescript application to make it simple for those wary of the Terminal.

Download the application