Folder Access/Rename Alert

Hi all,

      The network in my department consists of fre Mac systems and 12 PC's. We have all the projects in a Projects Folder in the main server. The problem that we encounter the most is people who work mostly in the pc's hit the enter key to open a folder in the mac and in the process they end up renaming the folders 

Eg: there was a folder AD1352K some one had accidentaly renamed it to “;” which as u can guess caused a lot of problems. Is there a way where i can warn (by which i mean display a dialog) the users that they are changing the folder name, so that they can at least be alerted?

Hi kshyam,

Think I posted this before, but I don’t think it was on a network. You can try it anyway. Try attaching a folder action to the folder that contains the folder that users are renaming. Here’s the script:


property folder_ref : alias "MyImage:Projects:"
property original_name : "Projects"
--
on adding folder items to this_folder after receiving these_items
	set n to name of (info for folder_ref)
	if n is not original_name then
		tell application "Finder"
			set name of folder_ref to original_name
		end tell
		display dialog "Renaming folders is not permitted!" buttons ¬
			{"OK"} default button "OK"
	end if
end adding folder items to

Since I don’t have a network, I used a disk image named “MyImage”. The folder action is connected to this disk and runs when I change the name of the folder “Projects”. You need to change the reference to the folder accordingly. I don’t think you can display a dialog to the user on a network from the server like this, so you might change or get rid of that part and just set the name back to the original name. Maybe you can inform the user in some other way.

Note that the script runs twice. It runs once when the name of the folder is changed by the user and another time when the script changes the name. When the script changes the name back to the original, nothing happens because the name was set back to the original name.

gl,

Thanks Kel,

But i want to check all the folders within the Projects Folder not just that folder itself.

I tried the script like this


property folder_ref : alias "SERV:PROJECTS:" --I'm connected to the server as "SERV"
property original_name : "renamed"
--
on adding folder items to this_folder after receiving these_items
   set n to name of (info for folder_ref)
   if n is not original_name then
       tell application "Finder"
           set name of folder_ref to original_name
       end tell
       display dialog "Renaming folders is not permitted!" buttons ¬
           {"OK"} default button "OK"
   end if
end adding folder items to

Then i ran the script and renamed a few folders , but there was no response.
There’s something wrong with what i did but i don’t know what

Hi kshyam,

The folder actions script I posted need to be connected to the folder and not run.

Try making a scriptsomething like this:


property folder_refs : {alias "MyImage:Projects:", alias "MyImage:Projects:AD1352K:"}
property folder_names : {"Projects", "AD1352K"}
--
set c to (count folder_refs)
repeat with i from 1 to c
	set this_folder to item i of folder_refs
	set this_name to item i of folder_names
	set n to name of (info for this_folder)
	if n is not this_name then
		tell application "Finder" to set name of this_folder to this_name
	end if
end repeat

Here you need to add alias references to every folder whose name you want to check along with their original names in the second list. Compile your script so the alias references are saved in the script. To test it, rename some of the folders that you entered in the lists, then run the script. The names should change back to original names.

There are two main ways to make the script automatically check the names. You can either make the script a folder action script with the ‘on adding folder actions to’ handler or you can use an ‘idle’ handler.

To make the script a folder action script, you attach it to the folders in question. In your case you would need two seperate scripts. Attach one script to your “SERV:” folder. This script would monitor the name of the “PROJECTS” folder. The second script would be attached to the “PROJECTS” folder and would monitor the sub folders within this folder. You would need to change the list of references and names accordingly. You attach folder action script to folders using the Scripts Menu from the menu bar. Search your computer for information on “folder actions”.

Idle handlers are made to run at intervals of seconds. To make a script with an idle handler, you save the scripts as stay open applications The following script when run as a stay open application will check the references and their names every two seconds:


property folder_refs : {alias "MyImage:Projects:", alias "MyImage:Projects:AD1352K:"}
property folder_names : {"Projects", "AD1352K"}
global c
--
on run -- do initializing stuff
	set c to (count folder_refs)
end run
--
on idle
	repeat with i from 1 to c
		set this_folder to item i of folder_refs
		set this_name to item i of folder_names
		set n to name of (info for this_folder)
		if n is not this_name then
			tell application "Finder" to set name of this_folder to this_name
		end if
	end repeat
	return 2 -- check every 2 seconds
end idle

If you run this script from the Script Editor, nothing will happen. It only works when run as an application. A simple example you can use to test if you’re doing things right is this:


on idle
	beep 1
	return 2
end idle

When you run this as a stay open application it should beep every two seconds.

Note that their have been many posts about folder actions being inconsistant. You might want to go with the idle handler.

gl,

Wow Thanks Kel, i’ll get to work on this and get back.

Thanks again