 |
 |
A Folder Action Applescript Idea...
|
 |
|
 |
|
Grizzled Veteran
Join Date: Jun 2002
Status:
Offline
|
|
I have an idea for a Folder Action, but I have zilch Applescript skills.
So I was wondering if anyone could help me write this script.
Basically, this is what it does: You have a folder, lets call it 'Downloads', inside it, it has sub-folders such as Pictures, Fonts etc. In Safari I would set it to download files to the Downloads folder. The Applescript would take the files in the Downloads folder, and based on their extension (like .jpg) it would move it to the appropriate folder.
Can this be done?
|
|
|
| |
|
|
|
 |
|
 |
|
Dedicated MacNNer
Join Date: Jul 2002
Location: Singapore
Status:
Offline
|
|
You could do it with a shell script, the only thing I'm not sure about is how to trigger it automatically when a download is completed. Otherwise you could make it a cron job and have it run every 30 minutes or something. As for applescript, I don't know it, so I'm not sure. Seems like it ought to work, but the trigger might be tricky.
|
|
--
|
| |
|
|
|
 |
|
 |
|
Senior User
Join Date: May 2000
Location: Lafayette, IN, USA
Status:
Offline
|
|
|
|
|
“The trouble with quotes on the Internet is that you can never tell if they’re attributed to the right person.”
—Abraham Lincoln
|
| |
|
|
|
 |
|
 |
|
Professional Poster
Join Date: Oct 2001
Location: London
Status:
Offline
|
|
here's the code for a Library autosorting script of mine that might help:
Code:
property SaverRecord : {extension:"saver", description:"Screen Saver", directory:"Screen Savers"}
property prefpaneRecord : {extension:"prefpane", description:"System Preference Pane", directory:"preferencePanes"}
property scriptRecord : {extension:"scpt", description:"Compiled AppleScript", directory:"scripts"}
property serviceRecord : {extension:"service", description:"System Service", directory:"services"}
property frameworkRecord : {extension:"framework", description:"Framework", directory:"frameworks"}
property scriptingAdditionRecord : {extension:"osax", description:"Scripting Addition", directory:"ScriptingAdditions"}
property aiffSoundRecord : {extension:"aiff", description:"Macintosh Sound", directory:"Sounds"}
property ttfFontRecord : {extension:"ttf", description:"TrueType Font", directory:"Fonts"}
property dFontRecord : {extension:"dfont", description:"dFont", directory:"Fonts"}
property otfFontRecord : {extension:"otf", description:"otFont", directory:"Fonts"}
property kthRecord : {extension:"kth", description:"Keynote Theme", directory:"Application Support:Keynote:Themes"}
property colorSyncRecord : {extension:"icc", description:"ColorSync Profile", directory:"ColorSync:Profiles"}
property applicationEnhancerRecord : {extension:"ape", description:"Application Enhancer Module", directory:"Application Enhancers"}
property terminalRecord : {extension:"term", description:"Terminal Saved Windows", directory:"Application Support:Terminal"}
property validRecords : {SaverRecord, prefpaneRecord, scriptRecord, serviceRecord, frameworkRecord, scriptingAdditionRecord, aiffSoundRecord, ttfFontRecord, dFontRecord, otfFontRecord, kthRecord, colorSyncRecord, applicationEnhancerRecord, terminalRecord}
--The handler for responding to when items are added to a folder:
on adding folder items to TargetFolder after receiving DroppedItems
-- set targetFolderAlias to targetFolder as alias
repeat with currentFile in DroppedItems
tell application "Finder"
set targetFolderName to the name of TargetFolder
set droppedFileName to the name of currentFile
set droppedFileInfo to info for currentFile
end tell
repeat with currentRecord in validRecords
if extension of currentRecord is equal to the name extension of droppedFileInfo then
tell application "Finder"
set newTargetFolder to (folder named (directory of currentRecord) of TargetFolder)
if newTargetFolder exists then -- not sure about validity of this line...
move currentFile to newTargetFolder
display dialog " " & targetFolderName & " has auto-sorted a " & description of currentRecord & "." buttons {""} default button 1 giving up after 3 --seconds
else
display dialog "the folder isn't there!" buttons {"OK"}
end if
end tell
end if
end repeat
end repeat
end adding folder items to
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: May 1999
Location: San Jose, CA
Status:
Offline
|
|
You need to be very careful doing this with your downloads folder.
As you start the download, the file is created and your script fires.
However, there's a significant chance that the script fires before the file has finished downloading and you'll move the file out from underneath Safari, almost guaranteeing a broken download.
Your script needs to check somehow if the file is still being downloaded and only move the file if it's done.
|
|
Gods don't kill people - people with Gods kill people.
|
| |
|
|
|
 |
|
 |
|
Grizzled Veteran
Join Date: Jun 2002
Status:
Offline
|
|
The library auto-sorter code was what I was looking for, and Camelot's right, my download did get broken :-/. Is there any AppleScript way to avoid this?
|
|
|
| |
|
|
|
 |
 |
|
 |
|
|
|
|
|

|
|
 |
Forum Rules
|
 |
 |
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
 |
 |
 |
 |
|
 |
|