|
|
#1 |
|
Prospect
Join Date: Sep 2004
Posts: 2
|
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.
|
|
|
|
|
|
#2 |
|
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
Hope it will do what you asked for. |
|
|
|
|
|
#3 |
|
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 |
|
|
|
|
|
#4 |
|
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.
|
|
|
|
|
|
#5 |
|
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"
|
|
|
|
|
|
#6 |
|
Hall of Famer
Join Date: Apr 2002
Posts: 3,315
|
Zombie alert [check dates before posting]
|
|
|
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|