Sunday 20 March 2011

Mac OS X - finder doesn't go back up a directory via backspace

God I miss that in Finder... so much for Mac's being easy to use.... that's BS. Windows Explorer is much easier to use...

Keyboard shortcuts for doing most of the easy file manipulations seem to be be lacking or overly complicated. e.g. Return to open a folder <CMD + O>, F2 to rename <use the mouse>, Delete to delete from the right <FN + backspace>....

Anyway, I decided to have a backspace to go up a directory, but as Mac OS X doesn't cater for just backspace, I had to settle with ALT+Backspace, and for that to call up a macro via Keyboard Maestro applescript.

I used growl to notify me and this seems to work pretty well, as long as full pathnames are not used in the window title.

On to the script:

--register growl
tell application "GrowlHelperApp"
    -- Make a list of all the notification types
    -- that this script will ever send:
    set the allNotificationsList to ¬
        {"Go up"}
   
    -- Make a list of the notifications
    -- that will be enabled by default.     
    -- Those not enabled by default can be enabled later
    -- in the 'Applications' tab of the growl prefpane.
    set the enabledNotificationsList to ¬
        {"Go up"}
   
    -- Register our script with growl.
    -- You can optionally (as here) set a default icon
    -- for this script's notifications.
    register as application ¬
        "AppleScript Go up" all notifications allNotificationsList ¬
        default notifications enabledNotificationsList ¬
        icon of application "Finder"
   
    --       Send a Notification...
   
   
   
end tell
tell application "System Events"
    set app_name to name of the first process whose frontmost is true
   
    if app_name is not "Finder" then
        --tell application "GrowlHelperApp"
        --    notify with name ¬
        --        "Go up" title ¬
        --        "Go up" description ¬
        --        app_name application name "AppleScript Go up"
        --end tell
        --display dialog app_name
        return 0
    else
        tell application "Finder"
            try
                set the_folder to (folder of the front window) as text
            on error
                tell application "GrowlHelperApp"
                    notify with name ¬
                        "Go up" title ¬
                        "Go up" description ¬
                        "Cannot go up" application name "AppleScript Go up"
                end tell
               
                return 0
            end try
            set the clipboard to the_folder
            --display dialog the_folder
            set len to the count of the_folder
            set len to len - 1
            set old_folder to text 1 thru len of the_folder
            --get jsut the window name
            set rev to reverse of characters of old_folder as text
            set loc to offset of ":" in rev
            set start to len - loc + 2
            set old_folder to text start thru len of old_folder
            --display dialog old_folder
           
            --close previous folder window
            close Finder window old_folder
           
            --display dialog the_folder
            set len to count of the_folder
            set len to len - 1
            set the_folder to text 1 thru len of the_folder
            --display dialog the_folder
           
            --display dialog len
            set rev to reverse of characters of the_folder as text
            set loc to offset of ":" in rev
            set len to len - loc
            set the_folder to text 1 thru len of the_folder
            --display dialog the_folder
           
            activate "Finder"
            open the_folder
            --set workingDir to the_folder
           
        end tell
        tell application "GrowlHelperApp"
            notify with name ¬
                "Go up" title ¬
                "Go up" description ¬
                the_folder application name "AppleScript Go up"
        end tell
    end if
end tell


This didn't take long to knock up, maybe an hour to learn applescript, growl and the limitations of Mac OS X... It auto registers with Growl each time it starts up, but that doesn't really matter.

No comments:

Post a Comment