• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Desktop-Sweeper Script
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Desktop-Sweeper Script


  • Subject: Desktop-Sweeper Script
  • From: Christopher Stone <email@hidden>
  • Date: Sun, 30 Sep 2012 20:24:25 -0500

Hey Folks,

I've had a more generic desktop-sweeper script for years that dropped everything not in the exclusion list into a dated folder.

I've intended for some time to write one to filter file-types into specific subfolders within the sweep-folder, and I've finally gotten around to it.

Adjust the exlusionList to fit your needs.

The fileExtFilters table will expand with tabs when compiled, but you may need to neaten it up if you don't use Script Debugger.  And of course there may be other file-types you want to add.

Doing things this way goads me into actually filing things properly away instead of leaving them in the sweep-folder for ages.

Enjoy.

--
Best Regards,
Chris

------------------------------------------------------------------------------------------------
#       Author: Christopher Stone <email@hidden>
#      Created: 2012-09-30 : 16:51
#     Modified: 2012-09-30 : 19:39
#  Application: Finder
#      Purpose: Sweep Stuff off the desktop in an organized fashion.
# Dependencies: Only OSX components used.
#      Version: 1.0
------------------------------------------------------------------------------------------------
property exlusionList : items 1 thru -2 of {¬
  "Action_List.txt", ¬
  "Aliases to Directories", ¬
  "Catch-All", ¬
  "Desktop Notes.rtf", ¬
  "Duplicates", ¬
  "FILE!", ¬
  "Meta-Research.txt", ¬
  "Sweep Desktop", ¬
  "Working Items (Current)", ¬
  "Working Scripts", ¬
  ""}
------------------------------------------------------------------------------------------------
property fileExtFilters : text 2 thru -2 of "
flv mov mp4\t\t\t\t\t\t\t\tMovie_Files
jpg png gif\t\t\t\t\t\t\t\tImage_Files
rtf\t\t\t\t\t\t\t\t\t\tRTF_Files
scpt\t\t\t\t\t\t\t\t\t\tScript_Files
txt\t\t\t\t\t\t\t\t\t\tText_Files
textClipping\t\t\t\t\t\t\tClipping_Files
webarchive\t\t\t\t\t\t\t\tWeb_Archives
webbookmark webloc\t\t\t\t\tWeb_Bookmarks
worksheet\t\t\t\t\t\t\t\tBBEdit_Worksheets
"
------------------------------------------------------------------------------------------------

try

  

  set desktopFolder to path to desktop folder
  set cleanupFolder to ("" & (path to documents folder) & "Sweep Desktop:")
  set cleanList to {}

  

  try
    alias cleanupFolder
  on error
    do shell script "mkdir " & (quoted form of (POSIX path of cleanupFolder))
  end try

  

  set AppleScript's text item delimiters to tab

  

  tell application "Finder"
    tell desktop

      

      # Create move-to record with file-extension filters.
      repeat with i in (paragraphs of fileExtFilters)
        set _temp to {words of first text item, last text item} of contents of i
        set itemsToMove to (items whose kind is not "Volume" and name is not in exlusionList and ¬
          name does not start with "Cleaned-" and name extension is in (item 1 of _temp) and ¬
          label index is not in {2, 6, 7}) as alias list
        if itemsToMove ≠ {} then
          set end of cleanList to {File_List:itemsToMove, Sub_Folder:item 2 of _temp}
        end if
      end repeat

      

      # Add folders to move-to record if appropriate.
      set itemsToMove to (folders whose kind is not "Volume" and name is not in exlusionList and ¬
        name does not start with "Cleaned-" and label index is not in {2, 6, 7}) as alias list
      if itemsToMove ≠ {} then
        set end of cleanList to {File_List:itemsToMove, Sub_Folder:"Folders"}
      end if

      

      if cleanList ≠ {} then

        

        # Make new Clean-up Folder
        set dateTimeString to strftime (current date) into "%Y%m%d-%H%M%S"
        set newFolderName to "Cleaned-" & dateTimeString
        set newFolder to make new folder at (cleanupFolder as alias) with properties {name:newFolderName}
        set label index of newFolder to 2
        set _alias to make alias to newFolder at it
        set label index of _alias to 2

        

        # Move items in move-to record.
        repeat with ndx in cleanList
          set _folder to (make new folder at newFolder with properties {name:Sub_Folder of ndx}) as alias
          move File_List of ndx to _folder
        end repeat

        

        # Move left-over (miscellaneous) items.
        set itemsToMove to (items whose kind is not "Volume" and name is not in exlusionList and ¬
          name does not start with "Cleaned-" and label index is not in {2, 6, 7}) as alias list
        if itemsToMove ≠ {} then
          set _folder to (make new folder at newFolder with properties {name:"Miscellaneous_Files"}) as alias
          move itemsToMove to _folder
        end if

        

        open newFolder
        tell application "Finder"'s front window to if its bounds ≠ {0, 44, 844, 1196} then set its bounds to {0, 44, 844, 1196}

        

      else
        beep
      end if

      

    end tell

    

  end tell

  

on error e number n
  set e to e & return & return & "Num: " & n
  tell current application to set dDlg to display dialog e with title "ERROR!" buttons {"Cancel", "Copy", "OK"} default button "OK"
  if button returned of dDlg = "Copy" then set the clipboard to e
end try

------------------------------------------------------------------------------------------------

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

  • Follow-Ups:
    • Re: Desktop-Sweeper Script
      • From: "David B. Gustavson" <email@hidden>
  • Prev by Date: Re: Help Testing a Mail Script
  • Next by Date: Re: Desktop-Sweeper Script
  • Previous by thread: re: name of target of front window
  • Next by thread: Re: Desktop-Sweeper Script
  • Index(es):
    • Date
    • Thread