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.

 

Archives

2001   01   02   03   04   05   06   07   08   09   10   11   12  

2002   01   02   03   04   05   06   07   08   09   10   11   12  

2003   01   02   03   04   05   06   07   08   09   10   11   12  

2004   01   02   03   04   05   06   07   08   09   10   11   12  

2005   01   02   03   04   05   06   07   08   09   10   11   12  

2006   01   02   03   04   05   06   07   08   09   10   11   12  

2007   01   02   03   04   05   06   07   08   09   10   11   12  

2008   01   02   03   04   05   06   07   08   09   10   11   12  

2009   01   02   03   04   05   06   07   08   09   10   11   12  

2010   01   02   03   04   05   06   07   08   09   10   11   12  

2011   01   02   03   04   05   06   07   08   09   10   11   12  

2012   01   02   03   04   05   06   07   08   09   10   11   12  

2013   01   02   03   04   05   06   07   08   09   10   11   12  

2014   01   02   03   04   05   06   07   08   09   10   11   12