Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > A Folder Action Applescript Idea...

A Folder Action Applescript Idea...
Thread Tools
iOliverC
Grizzled Veteran
Join Date: Jun 2002
Status: Offline
Reply With Quote
Nov 10, 2003, 03:07 PM
 
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?
     
Meneldil
Dedicated MacNNer
Join Date: Jul 2002
Location: Singapore
Status: Offline
Reply With Quote
Nov 11, 2003, 03:14 AM
 
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.
--
     
bojangles
Senior User
Join Date: May 2000
Location: Lafayette, IN, USA
Status: Offline
Reply With Quote
Dec 26, 2003, 01:07 PM
 
Check out a similar discussion for the script.
“The trouble with quotes on the Internet is that you can never tell if they’re attributed to the right person.”
—Abraham Lincoln
     
Diggory Laycock
Professional Poster
Join Date: Oct 2001
Location: London
Status: Offline
Reply With Quote
Dec 27, 2003, 02:56 PM
 
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
     
Camelot
Mac Elite
Join Date: May 1999
Location: San Jose, CA
Status: Offline
Reply With Quote
Dec 28, 2003, 04:44 AM
 
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.
     
iOliverC  (op)
Grizzled Veteran
Join Date: Jun 2002
Status: Offline
Reply With Quote
Dec 28, 2003, 07:32 AM
 
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?
     
   
Thread Tools
 
Forum Links
Forum 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
Top
Privacy Policy
All times are GMT -4. The time now is 08:59 PM.
All contents of these forums © 1995-2017 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.8 © 2000-2017, Jelsoft Enterprises Ltd.,