Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'An AppleScript to tidy up the Desktop' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
An AppleScript to tidy up the Desktop
Authored by: mark hunte on Nov 11, '06 04:12:12AM
What missing is the folder creation in all these scripts.
If some one New to AS uses them they may not realise they
have to Manually make the folders first.
I supsect that that is the issue that 'michaelnp' or its a filevault issue.

This is a script that I put together a couple of years ago, will create the folder needed if it does not exist

(*This folder action script is designed to keep your downloads folder organised *)


property image_extension_list : {"tif", "tiff", "gif", "png", "pict", "pct", "jpg", "bmp", "psd"}
property media_extension_list : {"mp3", "avi", "mov", "mpg", "ram"}
property archive_extension_list : {"zip", "sit", "sitx", "dmg", "tar", "hqx", "toast", "bin", "gz", "img"}
property html_extension_list : {"js", "htm", "html"}
property text_extension_list : {"doc", "txt", "rtf"}
property pdf_extension_list : {"pdf"}
property script_extension_list : {"scpt"}

property image_foldername : "images-DeskTP"
property media_foldername : "media-DeskTP"
property archive_foldername : "archives-DeskTP"
property text_foldername : "Text-DeskTP"
property html_foldername : "html-DeskTP"
property pdf_foldername : "pdf-DeskTP"
property script_foldername : "Script-DeskTP"



on adding folder items to this_folder after receiving added_items
	try
		repeat with this_item in added_items
			tell application "Finder"
				
				
				
				if (the name extension of the this_item is in the image_extension_list) then
					
					my makeamove(this_item, this_folder, image_foldername)
					
				end if
				if (the name extension of the this_item is in the script_extension_list) then
					
					my makeamove(this_item, this_folder, script_foldername)
					
				end if
				if (the name extension of the this_item is in the media_extension_list) then
					
					my makeamove(this_item, this_folder, media_foldername)
					
				end if
				
				if (the name extension of the this_item is in the archive_extension_list) then
					
					my makeamove(this_item, this_folder, archive_foldername)
					
				end if
				
				if (the name extension of the this_item is in the text_extension_list) then
					
					my makeamove(this_item, this_folder, text_foldername)
					
				end if
				
				if (the name extension of the this_item is in the html_extension_list) then
					
					my makeamove(this_item, this_folder, html_foldername)
					
				end if
				if (the name extension of the this_item is in the pdf_extension_list) then
					
					my makeamove(this_item, this_folder, pdf_foldername)
					
				end if
				
			end tell
		end repeat
	on error error_message
		display dialog error_message buttons {"OK"} default button 1
	end try
	
end adding folder items to

on makeamove(this_item, root_folder, target_foldername)
	
	tell application "Finder"
		
		if not (exists folder target_foldername of root_folder) then
			
			make new folder at root_folder with properties {name:target_foldername}
		end if
		
		set the target_folder to folder target_foldername of root_folder
		
		my resolve_conflicts(this_item, root_folder, target_folder)
		
		move file this_item to the target_folder
		
		--
		
	end tell
	
end makeamove

on resolve_conflicts(this_item, root_folder, target_folder) --renames the item if dublicate exists in target folder
	
	tell application "Finder"
		
		set file_extension to the name extension of this_item
		set the file_name to the name of this_item
		
		if the file_extension is "" then
			set the trimmed_name to the file_name
		else
			set the trimmed_name to text 1 thru -((length of file_extension) + 2) of the file_name
		end if
		
		if (exists document file file_name of target_folder) then
			
			set the name_increment to 1
			
			repeat
				set the new_name to (the trimmed_name & "_" & (name_increment as string) & "." & file_extension) as string
				
				if not (exists document file new_name of the target_folder) then
					
					set the name of document file file_name of folder root_folder to the new_name
					exit repeat
				else
					
					set the name_increment to the name_increment + 1
					
				end if
			end repeat
		end if
	end tell
	
	return the file_name
end resolve_conflicts


---
mh

[ Reply to This | # ]