FREN

#FF00AA


31 aug. 2011

Making LESS Useful

I’ve already posted about my web development workflow, and the bit of AppleScript that lets me upload the local file I’m editing to its rightful place on the web server by hitting a simple hotkey in TextWrangler.

But there was a problem with this: it made a pain of using the awesome LESS.app (which allows you such awesome and simple things as defining a color in a variable in the beginning of your CSS file and using it a bunch of times, so you only have to change the value once if you want to make adustments — just as an example among a bunch of more elaborate stuff). Since I was editing the .less file and I wanted to upload the compiled .css file rather than the file I was editing, my workflow just didn’t work. As a result, I just didn’t use LESS unless the benefit was really huge.

That’s until I finally realized I could automate that process, too — AppleScript should be powerful enough to automatically detect that I’m trying to upload a .less file, and then work with the .css instead, shouldn’t it? And I should be able to make it do that, right?

 

So, here goes the updated script:

set fileName to ""

 

tell application "TextWrangler"

save document 1 of window 1

set fileName to (file of document 1 of window 1) as string

end tell

 

set AppleScript’s text item delimiters to "."

if fileName contains "." then

set {fileBasename, fileExtension} to {text 1 thru text item -2, text item -1} of fileName

else

set {fileBasename, fileExtension} to {fileName, ""}

end if

 

if fileExtension is "less" then set fileName to fileBasename & ".css"

 

ignoring application responses

tell application "Transmit"

open fileName

end tell

end ignoring

 

Reminder: for this to work, you have to set up your favorites in Transmit with “DockSend” enabled — that’s the bit of magic that makes Transmit upload a file where it belongs on your server depending on where it is on your local hard drive.

Want to know when I post new content to my blog? It's a simple as registering for free to an RSS aggregator (Feedly, NewsBlur, Inoreader, …) and adding www.ff00aa.com to your feeds (or www.garoo.net if you want to subscribe to all my topics). We don't need newsletters, and we don't need Twitter; RSS still exists.

Legal information: This blog is hosted par OVH, 2 rue Kellermann, 59100 Roubaix, France, www.ovhcloud.com.

Personal data about this blog's readers are not used nor transmitted to third-parties. Comment authors can request their deletion by e-mail.

All contents © the author or quoted under fair use.