finder - recursively setting label in nested folders

I’m trying to recursively set labels in a folder and all it’s contents using


tell application "Finder"
	set label index of every item of entire contents of (selection as alias) to 1
end tell


which works but I get the following error

“Finder got an error: Network File permission error”

Q: how can I resolve this error and get the script to recursively set the labels.

Hi, try using “folder” as so:

set label index of every item of entire contents of folder (selection as alias) to 1

Hi,

at least you will get an error in case two or more items are selected because selection returns always a list

Try this


tell application "Finder"
	repeat with anItem in (get selection)
		set label index of anItem to 1
		if class of anItem is folder then
			set label index of every item of entire contents of anItem to 1
		end if
	end repeat
end tell

I guess the “Network File permission error” is an access privilege error on a shared volume

This will throw an error in any case, because folder alias is a double reference.
The keyword folder is only useful in front of a string path

That’s weird, it always works here :confused: And it didn’t before I inserted the word “folder”
I swear my Mac is special!

It works if one single folder is selected, although double referencing is actually wrong syntax

If you select one file you get

error “Finder got an error: Can’t make alias "Disk:Path:To:File.ext" into type folder.” number -1700 from alias “Disk:Path:To:File.ext” to folder

or with multiple items

error "Can’t make {alias "Disk:Path:To:File.ext", alias "Disk:Path:To:File1.ext"} to alias

Sorry! This was a finger slip on my command key! 6 hours sleep! My bad…:lol:

Still gives the error.

Also, I have checked the sharing and permissions and made sure that the folder has read and write and applied to enclosed items.

Q: Is there a way to get the name of the file/folder that is causing the error?

tell application "Finder"
   repeat with anItem in (get selection)
       set label index of anItem to 1
       if class of anItem is folder then
           set label index of every item of entire contents of anItem to 1
       end if
   end repeat
end tell

This edited script is supposed to tell you which folder issue an error.


tell application "Finder"
	repeat with anItem in (get selection)
		set label index of anItem to 1
		if class of anItem is folder then
			try
				set label index of every item of entire contents of anItem to 1
			on error
				display dialog "Error when treating folder : " & anItem
			end try
		end if
	end repeat
end tell

KOENIG Yvan (VALLAURIS, France) mardi 30 juillet 2013 21:11:23

Thanks for the code. The dialog does come up but the path to the item itself doesn’t it stops one directory above.

Ok apparently osx doesn’t recursively unlock files. So

chflags -R nouchg *

command needs to be sent through the terminal then run the script.

SUCCESS!

If you read carefully the code, it was not designed to flag the final file itself but the folder embedding it.

KOENIG Yvan (VALLAURIS, France) mercredi 31 juillet 2013 10:05:56

Hello.

I made a tool a while ago: macLabel, that you can use from a do shell script together with the find command and similies. You can find it here.

Once you have copied into a bin folder you can just type macLabel (enter) for help.

Yes. I’m aware that the code didn’t deal with permissions or finder related. What I was stating was that using the finder it doesn’t recursively unlock all the files which I assumed that the permissions would inherit. The specific reference was based on my observation to resolve the original error. Since the error was more related to permission level/finder rather than any script/code related error.

greatly appreciate the code. I’ll look at it. Looks like a lot of work.

The applescript here does work.

thank you all for the replies. This is why I always come back to macsripter.net

great community.
great help.
the best people.