0
votes

I am trying to create an applescript for a dropbox folder so that when a new file is added to the folder, it will automatically add that file to a particular playlist in iTunes (the goal being to be able to update multiple computers' playlists remotely by just adding one file to one dropbox folder.)

The applescript works with the exception of adding the file into the iTunes playlist. It is a bit tricky to debug because it is a folder action so it cannot be run in script editor. I have been using display dialog to try to understand what is happening but the dialogs show what looks like correct information to me so I am stumped. Any help is greatly appreciated!

I have tried using a POSIX path instead, I have tried setting the item as an alias, as a string, I've tried setting the item to another variable with "\"" & item & "\""

set playlistToUpdate to "Public News Service"

on adding folder items to theFolder after receiving theNewItems
    set filesAdded to {}
    repeat with i from 1 to count of theNewItems
        set thisItem to item i of theNewItems as alias
        tell application "iTunes"
            launch
            delay 2
            display dialog thisItem
            add thisItem to playlist playlistToUpdate
        end tell
    end repeat
end adding folder items to
1

1 Answers

0
votes

A folder action will fail silently unless you do something like use a try statement with an alert dialog. In your posted example, there will be an error in using display dialog with an alias instead of first coercing it to a string.

I've found that by breaking the functionality out into its own handler(s) and adding run and open handlers, the script can be tested and run from the Script Editor or as an applet/droplet, in addition to being used as a folder action, for example:

property playlistToUpdate : "Public News Service"

on run -- applet or from the Script Editor
    doStuff for (choose file with multiple selections allowed)
end run

on open droppedItems -- droplet
    doStuff for droppedItems
end open

on adding folder items to theFolder after receiving theNewItems -- folder action
    doStuff for theNewItems
end adding folder items to

to doStuff for someItems -- the main stuff
    set filesAdded to {}
    repeat with anItem in someItems
        tell application "iTunes"
            launch
            delay 2
            display dialog (anItem as text)
            add anItem to playlist playlistToUpdate
        end tell
    end repeat
end doStuff