Recursively searching through folders unlocking files

Howdy–

I’m sure this is a simple/newbie question, but today is I Can Page A Book But I Will Be Incompetent Day for me and I just can’t seem to figure this one out. I’m trying to write a script that will go through a directory and all of it’s subdirectories unlocking all of the files. I’ve used this recursive script on other operations related to Adobe and other apps, but this is the first time for the Finder. Logically, it should work, but as soon as it comes to the first file, I get an error (detailed below). Any ideas? Thanks!


tell application "Finder"
	set source_folder to choose folder
	my createList(source_folder)
end tell

on createList(item_list)
	set the the_items to list folder item_list without invisibles
	set item_list to item_list as string
	repeat with i from 1 to number of items in the the_items
		set the_item to item i of the the_items
		set the_item_alias to (item_list & the_item) as alias
		set this_info to info for the_item_alias
		if folder of this_info is true then
			my createList(the_item_alias)
		else
			set locked of the_item_alias to false --stack overflow
			--set locked of this_info to false --no change
		end if
	end repeat
end createList

Never mind. I just figured it out…:rolleyes:


tell application "Finder"
	set source_folder to choose folder with prompt "UnlockAllItems: Please select directory."
	my createList(source_folder)
end tell

on createList(item_list)
	set the the_items to list folder item_list without invisibles
	set item_list to item_list as string
	repeat with i from 1 to number of items in the the_items
		set the_item to item i of the the_items
		set the_item_alias to (item_list & the_item) as alias
		set this_info to info for the_item_alias
		if folder of this_info is true then
			my createList(the_item_alias)
		else
			my process_item(the_item_alias)
		end if
	end repeat
end createList

on process_item(this_item)
	tell application "Finder"
		set locked of this_item to false
	end tell
end process_item

Hi Phil
Would something like this work:

tell application "Finder"
	set t to files of entire contents of (choose folder) as alias list
	repeat with f in t
		tell item f
			set locked to false
		end tell
	end repeat
end tell

oops! Nevermind you did it!!

Hi philip,

it’s not possible to set properties of a file via info for
the Finder should do it:

createList(choose folder)

on createList(item_list)
	set the the_items to list folder item_list without invisibles
	set item_list to item_list as string
	repeat with the_item in the_items
		set the_item_alias to (item_list & the_item) as alias
		if folder of (info for the_item_alias) then
			my createList(the_item_alias)
		else
			tell application "Finder" to set locked of the_item_alias to false
		end if
	end repeat
end createList

PS: I simplified the script a bit;)

Much more elegant than mine, Stefan. Thanks!

Unless you particularly want to practise scripting recursion, this is quite fast:

tell application "Finder" to set locked of files of entire contents of (choose folder) to false