Skip to main content
Solved

Deploying folder actions via Casper


Forum|alt.badge.img+7
  • New Contributor
  • 8 replies

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?

Best answer by gavin_pardoe

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 original
Did this topic help you find an answer to your question?

7 replies

Forum|alt.badge.img+13
  • Valued Contributor
  • 389 replies
  • June 2, 2016

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


Forum|alt.badge.img+7
  • Author
  • New Contributor
  • 8 replies
  • June 2, 2016

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.


Forum|alt.badge.img+15
  • Contributor
  • 589 replies
  • June 2, 2016

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>

Forum|alt.badge.img+13
  • Valued Contributor
  • 389 replies
  • June 2, 2016

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

I kin love "packages" App! :-)


Forum|alt.badge.img+7
  • Author
  • New Contributor
  • 8 replies
  • June 2, 2016

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.


Forum|alt.badge.img+5
  • New Contributor
  • 14 replies
  • Answer
  • June 3, 2016

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

Forum|alt.badge.img+7
  • Author
  • New Contributor
  • 8 replies
  • June 6, 2016

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


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings