Hi,
I want to clear my desktop and file all files on my desktop to a specified folder.
at present I use:
set DesktopFolder to ("Macintosh HD:Users:Dave:Desktop")
tell application "Finder"
	move (files in folder DesktopFolder whose name extension is "pdf") to folder "Macintosh HD:Users:Dave:PDF"
end tell   
and have multiple lines under this line to move mp3’s to a different folder.
What I would like is to be able to create a 2 column table and have the file extension in one column and the location in the other and have the script loop this line and replace the file extension and location each time it goes down a line of the list.
This would allow multiple file extensions to be added to the list without needing to adjust the applescript.
Can it be done?
Dave
         
        
          
        
           
           
           
         
         
            
            
          
       
      
        
        
          Hi,
this is a way
property extensionList : {"pdf", "mp3"}
set homeFolder to path to home folder as text --> "Macintosh HD:Users:Dave:" in your case
set locationList to {homeFolder & "PDF", homeFolder & "MP3"}
repeat with i from 1 to count extensionList
	tell application "Finder"
		-- the desktop folder of the current user is the "root" folder of the Finder
		move (files whose name extension is (item i of extensionList)) to folder (item i of locationList)
	end tell
end repeat
Note: the script doesn’t use a property for the path list, because properties are evaluated once at compile time
and relative paths like path to home folder won’t be portable any more
         
        
        
           
           
           
         
         
            
            
          
       
      
        
        
          Suppose you had a text file on your desktop called test.txt. The file contains the following with each path separated from the extension by a comma. We first read in the contents of the file and separate that into a list separated by each line using “paragraphs”. Then we loop through each line and get each value using AppleScript’s text item delimiters set to a comma. At the end of the script we reset AppleScript’s text item delimiters to its default value of “”.
pdf,Macintosh HD:Users:Dave:Desktop:PDF
jpg,Macintosh HD:Users:Dave:Desktop:JPG
set DesktopFolder to path to desktop folder as text
set textTextPath to (path to desktop folder as text) & "test.txt"
set testText to read file textTextPath
set lineList to paragraphs of testText
set AppleScript's text item delimiters to ","
repeat with i from 1 to count of lineList
	set textItems to text items of (item i of lineList) -- make a list separated by the comma from each line in the text file
	set theExtension to item 1 of textItems
	set folderPath to item 2 of textItems
	
	tell application "Finder"
		move (files in folder DesktopFolder whose name extension is theExtension) to folder folderPath
	end tell
end repeat
set AppleScript's text item delimiters to ""
         
        
        
           
           
           
         
         
            
            
          
       
      
        
        
          That is awesome.Totally above my level of expertise.
At least now when my wife uses the iMac she wont leave random files all over the desktop.
Thanks
Dave