Adding folder action through a script... is it possible?

I wrote a script that creates a folder structure for new jobs. I’m trying to find a way to add a folder script to one of the folders created by that script. Is that possible? Assuming that folder actions are turned on on every computer that runs it.

Thanks for any input
Brian

If you move the script file to the client’s Folder Action folder (in ~/Library/Scripts/) and create the folder for the action wherever you need to it be you can then use this script to attach the script to the folder:

tell application "System Events" to attach action to alias "pathToFoldertoHaveAction:" using alias "pathToFldrItem.scpt"

Yes it is possible ! It works with System Events. Look in the eeeeh how do you call that in English in Dutch it’s “Woordenboek” but you use it in script editor to look at the syntax to use for scripting a application. I’m working on it now, and it’s work to add folder actions to a folder true a script. Now I must find a way to remove the old ones… but I am just starting so i guess I can work that out also.

Jan Geerling

You do that with

tell application "System Events" to remove action from alias "PathToFolderWithAction:" using action name "NameOfScript"

But how do you do that if you don’t know the name of the folder action script?
I want to use this as part of a installer and there are different kind of folder action scripts I want to remove …

Jan Geerling

Find it out myself !

set folderwithAction to “here the path of the folder” as alias

tell application “System Events”
set folderActionsOfTheFolder to attached scripts folderwithAction
repeat with teller from 1 to the count of items of folderActionsOfTheFolder
set nameFolderActionScript to name of item teller of folderActionsOfTheFolder
remove action from folderwithAction using action name nameFolderActionScript
end repeat
end tell

Jan Geerling

Hi Jan,

It’s great when people learn how to use dictionaries and do simple things for themselves.

Good job!

gl,

Thanks for the info… I’m not sure if I’m using it right though… here’s a script I wrote to test it… but it didn’t work. Any idea what I’m doing wrong?

set flocation to path to desktop as text

tell application "Finder"
	make new folder at folder flocation with properties {name:"Test Folder"}
end tell

tell application "System Events" to attach action to alias (flocation & "Test Folder") using alias "G5_12 RAID:Library:Scripts:add - new item alert.scpt"

Edit: Sorry… It worked. I just had to move that script back into the folder actions folder. I moved it out to make the path shorter. Do I have to write out the path like I did in that script?

Specify the path like so:

set pathToActionScript to alias ((path to scripts folder from user domain as text) & "Folder Action Scripts:yourFolderAction.scpt")

To install something in it, leave off the “yourFolderAction.scpt” part - the remainder is a generic path to the folder if it exists.

hmmm, still 1 problem with the installer I am making …

Or I must copy the new folder action scripts in the standard FolderActionFolder, and for that I need ‘root’ acces, wich is a bit of a problem for not all the users have a password.
So I created a new FolderActionMap in the Library, but then he don’t add the folderactionscripts (but also he is not giving a ‘error’)
I also tried to change “the attached scripts folder” to the new one in the Library but that also don’t work …

Somebody have an idea?

Jan Geerling

Model: iMac
Operating System: Mac OS X (10.3.9)

Folder Actions Scripts normally go in ~/Library/Scripts/Folder Action Scripts/ and as configured /Library/Scripts/Folder Action Scripts/ only contains the scripts for managing Folder Actions: Attach…, Configure…, Disable…, Enable…, Remove… and these appear in a contextual menu as well.

Why can’t you just have every user install this for themselves?

Hi Adem,

Yep, that did the trick ! I was revering to a wrong ‘FolderActionScriptsFolder’ …

I am scripting an installer, the installer creates all the correct folders and attached the Folder Action Scripts, and also making preferences and a registration code.
It also install some Xcode scripts in the Application Folder (who all check the registration code before working).
The last time we had 2,5 day’s work to get the workflow working by a other company, including server configuration, demonstration etc.
Now it must be possible to do that in 1,5 day, and it saves a lot of time when updating.

Thanks!

Jan Geerling