By John Gruber
WorkOS: APIs to ship SSO, SCIM, FGA, and User Management in minutes. Check out their launch week.
I’ve released a minor 1.0.1 update to my CSS Syntax Checker for BBEdit and TextWrangler; the biggest change is that it is now compatible with Mac OS X 10.3.x.
The Perl component needed only a wee change. I was using
HTML::Entities
to translate entity values into plain text, but the
HTML::Entities
module is not installed by default on Mac OS X 10.3.
Asking people to learn to use CPAN just so they can syntax-check
their CSS files is a bit much to ask. The fix was easy: I switched to
the unescapeHTML()
routine from CGI.pm
.
The AppleScript bits needed a bit more attention. The way the script
was originally written, you could store the AppleScript and Perl
scripts wherever you wanted on disk, so long as they were together in
the same folder. The AppleScript located the Perl script using the
path to me
command, which returns the path to the AppleScript script
itself; once it gets this path, the script can then look next to
itself for the Perl script.
However, AppleScript’s path to me
command only works this way on
10.4; on 10.3 and prior, it returns the path to the application that
is executing the script, not the path to the script file itself.
The workaround is that the AppleScript now checks what version of the
OS is present, and only uses the path to me
technique if running on
10.4.0 or later. Otherwise, it only looks in one hard-coded location:
BBEdit’s (or TextWrangler’s) Scripts folder.
Another Tiger-ism in the original script is that I made use of the
new-in-Tiger display alert
command, which produces much
nicer-looking dialog alerts than the old display dialog
command.
(See this entry in my Tiger Details report for examples.)
The workaround, once again, is to check for the version of the OS, and
to use the new display alert
command only when running on Mac OS X
10.4.0 or later.
To be pedantic, it’s not the version of the OS I check against; rather it’s the version of AppleScript. AppleScript 1.10 is the version that shipped with Mac OS X 10.4, so checking for AppleScript 1.10 or later is more or less the same as checking whether you’re running on Mac OS X 10.4.0 or later.
Here’s a snippet of example code:
-- Binary-coded decimal of applescript version 1.10
property AS_VERSION_1_10 : 17826208
on show_alert(the_title, the_message)
if ((system attribute "ascv") ≥ AS_VERSION_1_10) then
-- AppleScript 1.10 or later (10.4)
display alert the_title message the_message
else
display dialog the_title & return & return & the_message ¬
buttons {"OK"} default button 1 with icon note
end if
return
end show_alert
system attribute "ascv"
is how you ask for the version of
AppleScript; the value returned is a binary-coded decimal integer. At
the beginning of the script, I set the property AS_VERSION_1_10
to
17826208, which is the binary-coded decimal value for AppleScript
version 1.10. It’s better practice to define a constant with a
sensible name than to compare against a seemingly arbitrary value like
“17826208” repeatedly.
show_alert()
is a simple utility routine I slapped together. If you
call it like this:
my show_alert("This is the title", "This is the message.")
then the result looks like this on 10.4:
but looks sort of like this on 10.3 or earlier:
(I say “sort of” because that’s actually a screenshot of the display
dialog
command taken on 10.4, because I’m just too lazy to bother
getting a screenshot from the old iMac I have that’s still running
10.3. Even the output from display dialog
looks better on 10.4 than
it did before, so the dialog will look even crustier when actually
running on 10.3. Again, see my Tiger Details report for actual
screenshots of the differences.)
Lastly, note that the show_alert()
routine above will only compile
under 10.4 or later, because older versions of the Standard Additions
OSAX don’t define the display alert
command. Once compiled, the
script works just fine on 10.3, but to compile it under 10.3, you need
to use the raw Apple event syntax for the display alert
command:
«event sysodisA»
.
Previous: | Prizes for 2005 Membership Drive |
Next: | Membership Numbers |