property scriptURL : "http://www.monkeyfood.com/software/librarysorter/LibrarySorter.scpt.sit"

 

tell application "System Events" to set folder actions enabled to true

 

-- Display Installation Choices

set splashDialogReply to display dialog "This script can download and install the Library Sorter Folder Action. Choose 'Just Install' if you have already downloaded LibrarySorter.scpt" buttons {"Download and Install", "Just Install", "Cancel"} default button 3

 

--   Download the Folder Action Script

if button returned of splashDialogReply is "Download and Install" then

        display dialog "About to download..." buttons "¥" giving up after 1

        -- Download the Folder Action Script

        open location scriptURL

        delay 5

       

        set scriptSelectionPrompt to "please locate the script once it has finished downloading (It is named 'LibrarySorter.scpt')"

        set FAScript to choose file with prompt scriptSelectionPrompt of type {"osas"}

        set actionsFolder to path to Folder Action scripts folder from user domain

       

        tell application "Finder" to move FAScript to actionsFolder

end if

 

if button returned of splashDialogReply is not "Cancel" then

        if button returned of splashDialogReply is "Just Install" then

                set scriptSelectionPrompt to "please locate the Library Sorter Folder Action script (It is named 'LibrarySorter.scpt')"

                set FAScript to choose file with prompt scriptSelectionPrompt of type {"osas"}

        end if

       

        -- Choose which library folder to attach to 

        set userFavsFolder to path to "favs" from user domain

        set localFavsFolder to path to "favs" from local domain

       

        tell application "Finder"

                set userLibFolder to parent of userFavsFolder as alias

                set localLibFolder to parent of localFavsFolder as alias

        end tell

       

        set libSelect to display dialog "AutoSort - which library?" buttons {"Home Library", "Computer Library", "Both"} default button 3

        if button returned of libSelect is "Home Library" then

                tell application "System Events"

                        attach action to userLibFolder using FAScript

                end tell

               

        end if

        if button returned of libSelect is "Computer Library" then

                tell application "System Events"

                        attach action to localLibFolder using FAScript

                end tell

               

        end if

        if button returned of libSelect is "Both" then

                tell application "System Events"

                        attach action to localLibFolder using FAScript

                        attach action to userLibFolder using FAScript

                end tell

        end if

        display dialog "Library Sorter installed..." buttons "¥" giving up after 2

end if