Benches macOS

4

recursive folder action?

apple Verified

Imported from the Apple Support Forums via the Wayback Machine 🔗

Does anyone know if/how i can attach a folder action to a folder *including all its sub-folders* ?

Is that possible at all?

More specifically, i would like to add a movie to iTunes whenever i move a movie into my ~/Movies folder *or any of its sub-folders*.

Thanks a lot in advance for any insights or hints.

Best regards,

Gabriel.

Message was edited by: GabrielZ

4 replies

Sign in or join Beachball Help to reply.

  1. 0

    dev_sleidy

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    'Does anyone know if/how i can attach a folder action to a folder including all its sub-folders ?' - yes, the answer is 'no'.

    As per the '
    Folder Actions' web page:

    Folder Actions is a unique Mac OS X feature that allows scripts to be “attached” to folders and automatically executed whenever any or all of the following events occur:

    the attached folder is opened

    the window of
    the attached folder is closed

    the window of
    the attached folder is moved or resized

    items are placed into
    the attached folder

    items are removed from
    the attached folder

    'Is that possible at all?' - no.

  2. 0

    Hiroto

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    Hello GabrielZ,

    You may try something like this to attach a FA to an entire tree.

    Note that if you have a large number of subfolders in target tree and attach folder action to its every node, there might occur some performance problem in your system.

    Script has been tested under OS9 (using application "Folder Actions" instead of "System Events") but not under OSX.

    Good luck,

    H

    -- SCRIPT

    (*

    FA attach to tree

    FA remove from tree

    *)

    set rootf to path to "mdoc" from user domain -- alias "HD:Users:[current
    username]:Movies:"

    set scptf to "HFS:path:to:script:file" as alias

    FA
    attach_totree(rootf, scptf) -- attach

    --FA
    remove_fromtree(rootf, scptf) -- remove

    on FA
    attach_totree(rootf, scptf)

    (*

    alias rootf : alias of root folder

    alias scptf : alias of script file to be attached

    *)

    script o

    property aa : {}

    -- get alias list of target folders

    tell application "Finder"

    tell item rootf

    try

    set aa to folders of entire contents as alias list

    on error

    set aa to folders of entire contents as alias as list

    end try

    end tell

    end tell

    set beginning of my aa to rootf

    -- attach script to each of them

    tell application "System Events"

    repeat with a in my aa

    set a to a's contents

    attach action to a using scptf

    end repeat

    end tell

    -- decent notice

    display dialog "Done." with icon 1 giving up after 2

    end script

    tell o to run

    end FA
    attach_totree

    on FA
    remove_fromtree(rootf, scptf)

    (*

    alias rootf : alias of root folder

    alias scptf : alias of script file to be removed

    *)

    script o

    property aa : {}

    -- get alias list of target folders

    tell application "Finder"

    tell item rootf

    try

    set aa to folders of entire contents as alias list

    on error

    set aa to folders of entire contents as alias as list

    end try

    end tell

    set n to name of scptf

    end tell

    set beginning of my aa to rootf

    -- remove script from each of them

    set err to 0

    tell application "System Events"

    repeat with a in my aa

    set a to a's contents

    try

    remove action from a using action name n

    on error --

    set err to err + 1

    end try

    end repeat

    end tell

    -- decent notice

    if err = 0 then

    set mss to "Done."

    else

    set mss to "Done, anyway."

    end if

    display dialog mss with icon 1 giving up after 2

    end script

    tell o to run

    end FA
    remove_fromtree

    -- END OF SCRIPT

    Message was edited by: Hiroto

  3. 0

    GabrielZ

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    Thanks a lot for your help!

    (Sorry, can't give you credits right now, because the system gives me an error mesg when i click on 'solved' or 'helpful' ;-( )

    Best regards,

    Gabriel.

  4. 0

    GabrielZ

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    Thanks a lot -- good to know.

    Best regards,

    Gabriel.