Scripting Attach folder action

Ok I’m trying to script the action of attaching folder action scripts to folders. I am going to need to do this on about 25 macs using 60 unique scripts so If can get this to work it would be a huge time saver.
So far I’m running into this error.
Here is my current script in its simple form.

tell application "Folder Actions"
	attach action to alias "Macintosh HD:test folder:" using alias "Macintosh HD:System Folder:Scripts:Folder Action Scripts:test script"
end tell

Syntax looks good, but when the script runs I get this error
“Folder Actions got an error: Can’t make some data into the expected type.”
If anyone has done this and been succesful please let me know, any help would be much appreciated. As always thanks in advance.
PS. I am using Folder action plus also. Not sure if this matters or not.
JT

: PS. I am using Folder action plus also. Not sure if this matters
: or not.
It might. I don’t have FAP, and your script works fine on my Mac.
–tet

Nigel, You are the man!!! I rewrote the script like you said and it worked. It was definitly the break in the middle of the line. Damn that was frustrating the hell out of me, I knew it was right, I figured if the syntax check was good all was good. Thank you so much for taking the time to help me out. JT

This is going to run on multiple macs with different hard drive names. Is there a way to refer to the startup disk in the path name without having to use the correct name of the HD?
Thanks in advance!!
JT

Yes. And a few other folders, too (scroll downto to “startup”)

CORRECT “PATH TO” COMMAND FROM STANDARD ADDITIONS

In many cases the word “folder” or other words may be left off; e.g., “path to apple menu”, “path to apple menu items”, and “path to apple menu items folder” all return the same value; as does the pair “internet plugins” and “plugins”. In other cases, the word “folder” appended to constant causes an error even though the path returned is to a folder; e.g. “path to speakable items” is correct and returns the path to the speakable items folder, but “path to speakable items folder” causes an error under OS9.0.4.

path to apple menu [items folder]
path to application support [folder]
path to At Ease applications folder
path to At Ease documents folder
path to control panels [folder]
path to control strip modules [folder]
path to current user folder – not AS 1.3.7 (OS 8.6)
path to desktop [folder]
path to desktop pictures folder
path to editors folder
path to extensions [folder]
path to Folder Action scripts [folder]
path to fonts [folder]
path to frontmost application
path to help folder
path to [internet] plugins [folder]
path to keychain folder – not AS 1.3.7
path to modem scripts [folder]
path to preferences [folder]
path to printer descriptions [folder]
path to printer drivers [folder]
path to printmonitor [folder]
path to scripting additions [folder]
path to scripts folder
path to shared libraries [folder]
path to shutdown [items folder]
path to speakable items
path to startup [items folder]
path to startup disk
path to system preferences – not AS 1.3.7
path to system folder
path to temporary items [folder]
path to trash [folder]
path to users folder – not AS 1.3.7
path to voices [folder]

OLD VERSION

apple menu items folder
application support folder
At Ease applications folder
At Ease documents folder
control panels folder
control strip modules folder
current user folder
desktop folder
desktop pictures folder
editors folder
extensions folder
Folder Action scripts folder
fonts folder
frontmost application
help folder
internet plugins folder
keychain folder
launcher items folder
modem scripts folder
preferences folder
printer descriptions folder
printer drivers folder
printmonitor folder
scripting additions folder
scripts folder
shared libraries folder
shutdown items folder
speakable items
startup items folder
startup disk
stationary folder
system preferences
sytem folder
temporary items folder
trash folder
users folder
voices folder

I tried this

tell application "Finder"
   get name of startup disk
   set startup disk to the result
end tell
tell application "Folder Actions"
    attach action to alias "startup disk:test folder" using alias "startup disk:test script"
end tell

didnt work, I’m close on this one… any help?

You can’t use “Startup Disk” as a variable. Try this:

tell application "Finder"
    set startupDisk to name of startup disk
end tell

tell application "Folder Actions"
    attach action to alias (startupDisk & ":test folder") using alias (startupDisk & ":System Folder:Scripts:Folder Action Scripts:test script")
end tell

NB, It assumes that the path below “Startup Disk” will be the same.

–tet

: I tried this

: tell application “Finder”

: get name of startup disk

You don’t actually need to use the Finder. The Standard Additions’ command ‘path to’ can get you the path to startup disk, and its optional parameter ‘as string’ will return it as a path string. (eg. “Macintosh HD:”). You can store this in a variable and then concatenate the remainder of the folder and script paths to it, which can conveniently be done in the ‘attach action’ line:

 set startupDisk to (path to startup disk as string)
  tell application "Folder Actions"
    attach action to alias (startupDisk & "test folder") using alias (startupDisk & "test script")
  end tell

I expect you’ve seen mac_guy’s very useful list earlier in this thread of the folders that can be found with ‘path to’. If your folder was on the desktop and the script was in the Folder Action Scripts folder, you could write something like:

tell application "Folder Actions"
    attach action to alias ((path to desktop as string) & "test folder") using ¬
      alias ((path to Folder Action scripts as string) & "test script")
  end tell

NG

Ok the following does work.

set startupDisk to (path to startup disk as string)
tell application "Folder Actions"
   attach action to alias (startupDisk & "test folder") using alias (startupDisk & "test script")
end tell

But, if the folders that need to be attached are nested further down the path, it does not work.
For example if I change the third line of the script to read
attach action to alias (startupDisk & “test folder” & “last folder”) using alias (startupDisk & “test script”)
i get the error “Folder Actions got an error: Folder some object wasn’t found.”
All the scripts live in the Folder Action Scripts folder in the Scripts folder in the System folder in the HD.
The folders I need to attach the scripts to are HD:folder1:folder2:folder3
folder 3 being the folder that needs the script attached to.
Does this make any sense?? Sorry if it doesn’t I’m getting AS burnout.
“sometimes my learning curve is a circle” JT

Ok Iv’e got it to work.
The correct line is
attach action to alias (startupDisk & “1folder:2folder:3folder”)
Thanks to all who helped out. You guys are great, I owe you all a beer or a pint or whatever, I’m buying next time.
Thanks again.
JT