Go Back   The macosxhints Forums > OS X Help Requests > System



Reply
 
Thread Tools Rate Thread Display Modes
Old 09-18-2004, 07:21 PM   #1
Xorb
Prospect
 
Join Date: Sep 2004
Posts: 2
Question Applescript to move files

Hey, I was just wondering if anyone could help me with making a script that can move files to other folders on my computer depending upon the extention. Unfortunately I don't have any expirience with Applescript and have no idea how to go about doing this.

Basically I want to set a set the script as a folder action on my desktop folder; have it send .jpeg, .gif, etc to my pictures folder, .mov and .mpg to my movies folder and send everything else to a "stuff" folder. While I also want to have it do nothing with .download files so it won't move my incomplete Safari downloads.

Any help towards accomplishing this is very appreciated.
Xorb is offline   Reply With Quote
Old 09-18-2004, 09:52 PM   #2
Gfx
Prospect
 
Join Date: Jul 2004
Location: Montreal, Canada
Posts: 43
Here's a script I just did for the challenge (I'm trying to get better with AppleScript). I tested it (a little) and it seems to work fine so far.

It use the file's extension to do it's trick. I know that it can be made to consider the type/creator too but I'll leave it to you to modify it if you want. I also was on the impression that we shouldn't rely on the ".download" extension so I used something else to check if the file was still being downloaded.

You will have to set a few things in the script like your "stuff" folder and maybe a few other things so I suggest you read the comments in it.

Code:
-- add any graphic file extension you need in the list below
property graphicExtList : {"jpg", "gif"}

-- add any movie file extension you need in the list below
property movieExtList : {"mov", "mpg"}

-- set this to the delay time you want the script to check again unfinished downloads
-- based on the difference in the file size between the interval (in seconds) defined above
property myDelay : 5

-- modify and uncomment the line below to reflect the path of your archive folder
-- property myAchiveFolder : "Hard Disk:Users:Your User Name:Your archive folder:" as alias

on adding folder items to this_folder after receiving these_items
	tell application "Finder"
		repeat with i from 1 to number of items in these_items
			set downloadedFile to item i of these_items
			-- get some information from the file
			set the theFileInfo to the info for downloadedFile
			
			-- check if the file is still being downloaded
			-- there is probably a better way to achieve this...
			-- if it's the case... I would be glad to see it! ;)
			-- Should we trust the ".download" extension?
			set oldFileSize to 0
			set fileSize to the size of theFileInfo
			repeat while fileSize is not equal to oldFileSize
				set oldFileSize to fileSize
				delay myDelay
				set the theFileInfo to the info for downloadedFile
				set fileSize to the size of theFileInfo
			end repeat
			
			-- check the kind of file...
			if the name extension of the theFileInfo is in the graphicExtList then
				-- move it to the user's pictures folder 
				move downloadedFile to (path to pictures folder from user domain)
				
			else if the name extension of the theFileInfo is in the movieExtList then
				move downloadedFile to (path to movies folder from user domain)
				
			else -- the file has an unlisted or no extension, move it to the "archive" folder
				move downloadedFile to myAchiveFolder
			end if
		end repeat
	end tell
end adding folder items to
Keep in mind that this script might not be perfect as it has been done rapidly. If anyone find a better more efficient way of doing it or modify the script in a better way I would be glad to see it.

Hope it will do what you asked for.
Gfx is offline   Reply With Quote
Old 09-19-2004, 12:51 PM   #3
Xorb
Prospect
 
Join Date: Sep 2004
Posts: 2
Awesome, thanks for helping me get started with this.

EDIT: Yay it's working, the only issue I have so far is it won't move folders, but it appears to work just fine with files.

Last edited by Xorb; 09-19-2004 at 01:23 PM. Reason: Confirmation
Xorb is offline   Reply With Quote
Old 09-19-2004, 02:06 PM   #4
Gfx
Prospect
 
Join Date: Jul 2004
Location: Montreal, Canada
Posts: 43
Oops... something I haven't thought of... folders. I guess that you can modify this script using some examples you can find in /Library/Scripts.
Gfx is offline   Reply With Quote
Old 04-04-2011, 09:49 AM   #5
himanshu
Major Leaguer
 
Join Date: Aug 2010
Location: India, Pune
Posts: 298
thanks

Thank you very much "GFx"
__________________

10.6.7 Snow Lepord "I n t e l"
himanshu is offline   Reply With Quote
Old 04-04-2011, 09:55 AM   #6
Hal Itosis
Hall of Famer
 
Join Date: Apr 2002
Posts: 3,315
Zombie alert [check dates before posting]
Hal Itosis is offline   Reply With Quote
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump



All times are GMT -5. The time now is 10:38 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.
Site design © IDG Consumer & SMB; individuals retain copyright of their postings
but consent to the possible use of their material in other areas of IDG Consumer & SMB.