332 words on Software
When writing CSS it’s a good idea to validate your style sheets. The W3C offer a validator for that. Which in principle can be downloaded to your local computer, but doing so requires using CVS and possibly more pain to actually get things set up afterwards. So I have never done that but just used their website form instead. Being lazy by nature I finally wrote a script that just opens the validator automatically for my frontmost SubEthaEdit document in the hope that it inspires more regular usage of the validator. For other editors it’s also available as a system Service.
So, for your convenience:
You will need UnicodeChecker for the script to work. The system Service was created courtesy of ThisService. Alternatively just look at it:
tell application "SubEthaEdit" to set theText to plain text of first document
process(theText)
on process(theText)
— convert spaces to +
set oldTID to AppleScript’s text item delimiters
set AppleScript’s text item delimiters to {" "}
set textArray to text items of theText
set AppleScript’s text item delimiters to {"+"}
set theText to textArray as string
set AppleScript’s text item delimiters to oldTID
— URL encoding
tell application "UnicodeChecker" to set URLText to escape theText to URL preserving " +abcdefghijklmnopqrstuvwxyzABCDEFGHJIJKLMNOPQRSTUVWXYZ1234567890" without preserving default set
— creating and opening the URL
set myURL to "http://jigsaw.w3.org/css-validator/validator?text=" & URLText
tell application "System Events"
if (count (processes whose name is "Safari")) is not 0 then
tell application "Safari"
if URL of first document contains "jigsaw.w3.org/css-validator/" then
— re-use the previously used CSS validator display
set URL of first document to myURL
end if
end tell
end if
— otherwise just open the URL in the default browser
open location myURL
end tell
end process