I can’t find an attached scripts property for ‘folder’ or in the folder actions suite here in Mavericks also. You’ll probably need to rewrite your own attached scripts routine. The dictionary:
set f to choose folder
tell application "System Events"
set fa_name to name of f
set fa to first folder action whose name is fa_name
every script of fa
end tell
As far as I know, the answer is available in every mac.
In the script : Remove Folder Actions which is available on my Yosemite device, the syntax used to get the name of the scripts attached to a folder is :
tell application “System Events” to ¬
set FAScripts to name of every script of folder action FolderActionName
where FolderActionName is the name of a folder to which scripts are attached.
I double checked, the script is exactly the same on my Mavericks device.
Yvan KOENIG (VALLAURIS, France) jeudi 16 octobre 2014 20:27:58
I can’t get using the path property of a folder action. Don’t know why. You probably need to use the name property in conjunction with the reference to the folder.
The only problem which is a big one is that you might have more than one folder with the same name. That’s why you need to do something to check the references.
Actually kel1 has found a real problem. Yvan’s code relies on the name of the folder, but I actually three or four folders with the same name (WPDocs) on my system, and the users I’m writing for may also have multiple folders with the same name.
Kel1 or anyone - is there a way to make Yvan’s code restrict itself to a specific path?
I think there might be a way to compare the folder paths. The folder action script has a variable whose value is the same as the chosen folder. For instance:
on adding folder items to thisFolder after receiving these items
-- code here
end on adding folder items to
The variable thisFolder is a reference to the folder. So we need to read the script and find what the value is. The script would have had to be run at least once.
I cannot test this out though. I have a screw in my tire and need to fix it soon. Maybe Yvan or someone else can try to do it. I’ll try to do it when I get back also.
[i]In the script : Remove Folder Actions which is available on my Yosemite device,.
I double checked, the script is exactly the same on my Mavericks device.[/i]
I assumed that you would be curious enough to look at the named script which is available on every boot volume.
Here is a subset which show the way to select a folder with attached scripts.
I don’t know how it behaves when several folders with the same name have attached script.
It don’t hurt to run it for see.
Ah - I misunderstood (my fault entirely) what you meant by the Remove Folder Actions script being available on the device. It doesn’t matter what I thought you meant - but I stupidly didn’t realize that you meant that the script was one of the sample scripts supplied by Apple. Obviously that’s what you meant, but I didn’t see it.
I’ll experiment with what happens with multiple folders that have the same name and will report back.
Thank you for having had the patience to continue with this.
This is a hard problem. I don’t know how to get the value of the variable by reading the script.
I’m thinking that maybe you can modify the scripts. If you give the scripts run handlers, then you can run the script and somehow it tells you what folder it is attached to. Something like that.
I think you can read the plist com.apple.FolderActions. Try looking at: ~/Library/Preferences/com.apple.FolderActions.plist. Not sure how to read the alias key right now.
Edited:
do shell script "defaults read com.apple.folderactions"
Got the basic parts. Try running this and look at the results:
tell application "System Events"
set plistFile to (POSIX path of preferences folder) & "/com.apple.folderactions.plist"
tell property list file plistFile
tell contents
set scriptList to value of property list item "folderActions"
end tell
end tell
set scriptCount to count scriptList
repeat with i from 1 to scriptCount
set thisScript to item i of scriptList
-- get folder path from data (|alias|)
-- get attached scripts for this folder action (|scripts| list)
end repeat
end tell
scriptList
scriptList is a list of records. Each record holds info on every folder action. You can get the folder path by parsing the data as text (the |alias| label). Write the data to file and read as text. You can get the attached scripts through the |scripts| label.
If you’re interested I’ll be back tomorrow or maybe you can do it. It’s getting late (yawning).
Edited: here’s an example result of the scriptList where I have two folders with the same name:
Edited: I deleted the quote. There was too much info.
Edited: think there is a good way to parse the text for the folder path.
get startup disk name and folder action name
your delimiters might look like this “Macintosh HD:” and “:untitled folder”
get text that is between that and concatenate the ends back
you have your folder action folder path
You can also get the posix style path.
Edited: first need to strip non-visible characters. Darn.
Thank you for this, which I’ve been experimenting with.
But there may be a workaround, at least for the script I’m working on.
What I want to do is test whether a folder action script is attached to a specific folder, and then attach the folder action script if it is not already attached.
If the script is already attached, then a “duplicate script” error occurs. It should be possible to trap that by number and not display the error. If the script is not already attached, it gets attached correctly.