Server Share Permission Fixer...

A quick little script that can be saved as a ‘Stay Open’ app to fix smb sharing permissions problems on local networks. Shows one active location, and 2 commented-out that can be setup to granulate permissions fixes to whole volumes or even just folders.

Do one startup fix, also a daily at 2AM each day and checks every two seconds (per share) and runs a fix if the disk usage changes.


----
-- Server Permission Repair.  03/27/2018 by Adam Albrec (game_creator@hotmail.com)
----


-- Admin User Name and Password (place values INSIDE quotes).
set user_name to "" as text
set pass_word to "" as text


----
-- First Run Fix.
----

try
	do shell script "sudo chmod -R 777 /Volumes/Location1" user name user_name password pass_word with administrator privileges
end try

--try
--do shell script "sudo chmod -R 777 /Volumes/Location2" user name user_name password pass_word with administrator privileges
--end try

--try
--do shell script "sudo chmod -R 777 /Volumes/Location3" user name user_name password pass_word with administrator privileges
--end try



on idle
	-- Daily Fix (at 2AM)
	set dailyCheck to "false"
	set CurrentTime to (do shell script "date +\"%l:%M %p\" | awk '{$1=$1;print}'") as text
	if CurrentTime is "1:59 AM" then
		set dailyCheck to "true"
	end if
	if dailyCheck is "true" then
		set CurrentTime to (do shell script "date +\"%l:%M %p\" | awk '{$1=$1;print}'") as text
		if CurrentTime is "2:00 AM" then
			try
				do shell script "sudo chmod -R 777 /Volumes/Location1" user name user_name password pass_word with administrator privileges
			end try
			
			--try
			--do shell script "sudo chmod -R 777 /Volumes/Location2" user name user_name password pass_word with administrator privileges
			--end try
			
			--try
			--do shell script "sudo chmod -R 777 /Volumes/Location3" user name user_name password pass_word with administrator privileges
			--end try
			
			set dailyCheck to false
		end if
	end if
	
	
	
	----
	-- Volume "Location1" auto check and Read/Write mod.
	----
	
	set Location1_size to ""
	try
		set Location1_size to the 12th word of (do shell script "df -k /Volumes/Location1") as list
	end try
	delay 2
	set Location1_size_check to ""
	try
		set Location1_size_check to the 12th word of (do shell script "df -k /Volumes/Location1") as list
	end try
	try
		if Location1_size is not equal to Location1_size_check then
			do shell script "sudo chmod -R 777 /Volumes/Location1" user name user_name password pass_word with administrator privileges
		end if
	end try
	
	
	
	----
	-- Volume "Location2" auto check and Read/Write mod.
	----
	
	--set Location2_size to ""
	--try
	--set Location2_size to the 12th word of (do shell script "df -k /Volumes/Location2") as list
	--end try
	--delay 2
	--set Location2_size_check to ""
	--try
	--set Location2_size_check to the 12th word of (do shell script "df -k /Volumes/Location2") as list
	--end try
	--try
	--if Location2_size is not equal to Location2_size_check then
	--do shell script "sudo chmod -R 777 /Volumes/Location2" user name user_name password pass_word with administrator privileges
	--end if
	--end try
	
	
	
	----
	-- Volume "Location3" auto check and Read/Write mod.
	----
	
	--set Location3_size to ""
	--try
	--set Location3_size to the 12th word of (do shell script "df -k /Volumes/Location3") as list
	--end try
	--delay 2
	--set Location3_size_check to ""
	--try
	--set Location3_size_check to the 12th word of (do shell script "df -k /Volumes/Location3") as list
	--end try
	--try
	--if Location3_size is not equal to Location3_size_check then
	--do shell script "sudo chmod -R 777 /Volumes/Location3" user name user_name password pass_word with administrator privileges
	--end if
	--end try
	
	
	
	----
	-- End of Script.
	----
end idle