Question

I'm new to applescript but I want to set up a folder action that:

1. Recognises when a file is added to a folder
2. Tags said folder red
3. Adds a Reminder to the "Downloads" reminder list that has the name of the newly-added file as the body text of the reminder

Using google and Applescript's record function I've frankenscripted this together so far

property dialog_timeout : 30 -- set the amount of time before dialogs auto-answer.

on adding folder items to this_folder after receiving added_items



try
    tell application "Finder"
        set FILEname to name of (added_items)
        set label index of folder "untitled folder" of folder "Desktop" of folder "heyjeremyoates" of folder "Users" of startup disk to 2
    end tell

    tell application "Reminders"
        set mylist to list "Downloads"
        tell mylist
            make new reminder with properties {name:"D/L Complete", body:FILEname, due date:(current date)}
        end tell
    end tell
end try

end adding folder items to

Darn thing won't work. Infuriating. I tested it as a folder action with "test" as the name and body of the reminder and it worked fine. I'm pretty sure I've gone wrong somewhere in setting FILEname as the name of the newly copied item because the script as it is now no longer turns the folder red.

The idea behind this is so I can see, from my iPhone/iPad, how many large/scheduled downloads to my home mac (both torrents and large work files - I'll have a seperate folder action and reminder list for each download folder) there are that are yet to be managed.

It seemed like setting up a Growl/Prowl combo was wasteful if iCloud/Reminders and a dozen lines of code could deliver what I wanted anyway. Ideally I'll write a second applescript that will delete the reminder when I rename or move the related file, and though I haven't even thought about how that would work if anyone has any suggestions for it I'd be super grateful

It is a pity you can't (natively) have OSX notifications pushed to an iOS device linked to the same iCloud account though (with the appropriate granularity)

But I digress - can anyone see what I'm screwing up here?

Thanks in advance for even reading this far

Was it helpful?

Solution

added_items is a list of aliases, and name of (added_items) resulted in an error.

on adding folder items to this_folder after receiving added_items
    tell application "Finder"
        set label index of this_folder to 2
        repeat with f in added_items
            set n to name of f
            tell application "Reminders" to tell list "Downloads"
                make new reminder with properties {name:"D/L Complete", body:n, due date:(current date)}
            end tell
        end repeat
    end tell
end adding folder items to

(Save the script in ~/Library/Workflows/Applications/Folder Actions/ and enable the folder action from Folder Actions Setup.)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top