#FF00AA

Hi! My name is Cédric Bozzi, I make websites and iOS apps, and this is my blog about technology (mostly a Twitter archive, really).

 

Twitter Work Contact

25 April 2007

Open Htaccess Here

@apple@

The single big disadvantage of using OS X to develop websites is that it’s based on Unix and, as such, considers the same files hidden as your production webserver does. If you’re editing local copies of your websites and then uploading them (which you should be doing, as I’ve already written several times), then you’ve got a problem: you need to edit .htaccess files, but the Finder hides them.

There are several solutions, but none of them is satisfactory: You could configure your Apache server to look for htaccess.txt files instead of .htaccess — but that requires control over your web host, and it also means you have to change all your existing sites. You could use some tweaking software to set the Finder’s hidden preference to show hidden files — but then your whole OS X system will look like a complete mess, starting with the desktop. You could use Path Finder instead of the Finder to manage your local development files, which I did for a while — but Path Finder is bloated crap and I hate it. You could use your FTP client to navigate your folders and display hidden files — but, for all its flaws, the Finder has great functionality and using an FTP client instead just sucks. Ideally, you could instruct Transmit to automatically rename local htaccess.txt to .htaccess when they’re uploaded, but… there’s no such option.

Just as I was wondering whether Panic had thought of that problem when designing Coda (I only realized later that was irrelevant, since Coda has its own file browser), I figured: there’s got to be a way to solve this in AppleScript or Automator! And today, after a good night’s sleep, I bring you an Automator miracle: Open Htaccess Here.workflow.

 

How to use it, in a nutshell: download it, open it, use Automator’s “Save As Plug-in” option to create a Finder contextual menu item; now you can right-click any file or folder and select the item you just created from the Automator submenu to open an .htaccess file in TextEdit (if you’ve got a favorite text editor, look for “TextEdit” at the very end of the AppleScript action and substitute it with your choice). If there’s no .htaccess file at this location yet, it will be created.

 

If you want more details, here’s what the workflow looks like (yes, it’s pretty simple — once you make sense of all the idiosyncracies of working with Finder items in AppleScript):

And here’s the AppleScript (I’m not posting code often, so I don’t have CSS rules for it, sorry):

on run {input, parameters}

 

    if input is {} then tell application “Finder” to set input to the target of Finder window 1 as alias

    set input to input as alias

    set thePath to POSIX path of input

 

    —http://bbs.applescript.net/viewtopic.php?pid=69731

    set {folder:isFolder} to (info for input)

    if not (isFolder) then

        —http://www.fischer-bayern.de/applescript/html/parent_f.html

        set AppleScript’s text item delimiters to “/”

        set itemCount to (count text items of thePath)

        set lastItem to the last text item of thePath

        if lastItem = “” then

            set itemCount to itemCount - 2

        else

            set itemCount to itemCount - 1

        end if

        set thePath to text 1 thru text item itemCount of thePath & “/”

    end if

 

    set thePath to thePath & “.htaccess”

    do shell script “touch "” & thePath & “"”

    do shell script “open -a TextEdit "” & thePath & “"”

 

    return thePath

 

end run

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