Deploying folder actions via Casper

aaronf
New Contributor II

Has anyone been successful at deploying folder actions through Casper? There appears to be some potential with an Applescript. I've gotten the following script to work for 10.6 up through 10.10 but the "attach action" command appears to have been deprecated in 10.11. It will enable folder actions on the specified folder in 10.11 but does not assign the folder action script.

tell application "System Events"
       attach action to folder "path/to/folder" using "path/to/script"
end tell

My other thought was to edit the “com.apple.FolderActionsDispatcher.plist” located in the user’s preferences folder. This is storing the data that assigns the folder actions and scripts. However, the XML node storing the data I would need to change appears to be encrypted. Initially, my thought was that I could use the “defaults write” command to edit this file and use some variables to accommodate for all the different accounts. Anyone know if there’s a way to edit this plist if it’s encrypted?

1 ACCEPTED SOLUTION

gavin_pardoe
New Contributor III

I have script for configuring folder actions. been a while since i last used it but it worked really well. you just need to change the path to the target folder and script you are applying to it.

tell application "System Events"
    --Set Varibles and Create Aliases

    set folder actions enabled to true
    set userTrash to (path to trash folder) as string
    set theScript to POSIX file "/Library/Scripts/Folder Action Scripts/touch.scpt" as alias
    set targetScript to theScript as text
    tell application "Finder" to set scriptName to name of alias targetScript
    set targetFolder to the userTrash as text

end tell

set targetFolder to the result as text --Configure Target Folder
tell application "Finder" to ¬
    set FAName to name of alias targetFolder
tell application "System Events"
    if folder action FAName exists then
    else
        make new folder action ¬
            at end of folder actions ¬
            with properties {path:targetFolder} -- name:FAName, 
    end if
end tell

tell application "System Events" --Congifure Script for Target Folder to Use
    tell folder action FAName
        make new script ¬
            at end of scripts ¬
            with properties {name:scriptName}
    end tell
end tell

View solution in original post

7 REPLIES 7

kerouak
Valued Contributor

I used 'packages' heres a ss of the contents..4b0a381488124b81bc804858eead460c

aaronf
New Contributor II

I think you're describing how you push out the folder action. I probably should have titled the post "Assigning or Attaching Folder Actions via Casper." The title is probably misleading. I've been able to push out the folder action. The part that I'm stuck on is assigning a specific folder action to a specific folder. Basically, via a script, mimic how you use the "Folder Actions Setup" app to do this.

8ffe28dbed2248c1bf799c407e510326

thoule
Valued Contributor II

Can you use a LaunchD? Or LaunchAgent for user based?
Drop this in /Library/LaunchDaemons along with creating the folder and script to run as needed in the paths mentioned below.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>edu.school.mywatchertool</string>
<key>ProgramArguments</key>
<array>
<string>/usr/local/COMPANY/ScriptToRun.sh</string>
</array>
<key>WatchPaths</key>
<array>
<string>/usr/local/COMPANY/FolderToWatch/</string>
</array>
<key>OnDemand</key>
<true/>
</dict>
</plist>

kerouak
Valued Contributor

Oh, The 'QLS' folder is the one with thte FA's on..

I kin love "packages" App! :-)

aaronf
New Contributor II

I initially looked at creating a launch agent with watchpaths. One of the requirements for this is that the script is only triggered by files being added. By default watchpaths will trigger the script for adding and removing files. I could not figure out how to limit the script to only be triggered by adding files.

gavin_pardoe
New Contributor III

I have script for configuring folder actions. been a while since i last used it but it worked really well. you just need to change the path to the target folder and script you are applying to it.

tell application "System Events"
    --Set Varibles and Create Aliases

    set folder actions enabled to true
    set userTrash to (path to trash folder) as string
    set theScript to POSIX file "/Library/Scripts/Folder Action Scripts/touch.scpt" as alias
    set targetScript to theScript as text
    tell application "Finder" to set scriptName to name of alias targetScript
    set targetFolder to the userTrash as text

end tell

set targetFolder to the result as text --Configure Target Folder
tell application "Finder" to ¬
    set FAName to name of alias targetFolder
tell application "System Events"
    if folder action FAName exists then
    else
        make new folder action ¬
            at end of folder actions ¬
            with properties {path:targetFolder} -- name:FAName, 
    end if
end tell

tell application "System Events" --Congifure Script for Target Folder to Use
    tell folder action FAName
        make new script ¬
            at end of scripts ¬
            with properties {name:scriptName}
    end tell
end tell

aaronf
New Contributor II

Perfect! Just what I was looking for. Got me pointed in the right direction. Thank You!