Seems like you're blindingly copying code without knowing what you're doing.
1) If you want to change permissions on your logoutscript you use chmod NOT chown eg chmod 755 /usr/local/bin/logoutscript.
Code:
-- All my statements in an Applescript
-- Save it with meaningful name eg logoutscript.scpt
-- Note : script is NOT tested. I'm not responsible yada yada etc...
-- Example how to use list of users
set the_user to do shell script "logname"
set the_user_list to {"gradek", "grade1", "grade2", "grade3", "grade4", "grade5", "grade6"}
if the_user is in the_user_list then
-- You don't need a tell Finder block for the do shell script statements
--tell application "Finder"
--example of the use of the_user variable
do shell script "rm -R /users/" & the_user & "/Library"
do shell script "cp -R /users/shared/library /users/grade1/"
do shell script "chown -R grade1 /users/grade1/Library"
--end tell
end if
Code:
#!/bin/bash
# I'm telling osascript to run the [COLOR="Red"]Applescript[/COLOR] I've made and saved in Script Editor
/usr/bin/osascript "/path/to/your/script/[COLOR="red"]logoutscript.scpt[/COLOR]"
or
Code:
#!/bin/bash
# I'm doing it differently and decided to put my Applescript statements in the shell script
/usr/bin/osascript <<-[COLOR="Red"]EOF[/COLOR]
--tell application "Finder"
do shell script "rm -R /users/grade1/Library"
do shell script "cp -R /users/shared/library /users/grade1/"
do shell script "chown -R grade1 /users/grade1/Library"
--end tell
[COLOR="red"]EOF[/COLOR]
2) If you do your sudo defaults write command what do you see when you do sudo defaults read. What do you see when you do echo $PATH. Is /usr/local/bin in your PATH. If not your shellscript will not execute.
3) Does the folder /users exist? Shouldn't that be /Users.
4) You might run into trouble with spaces. Read this :
http://developer.apple.com/library/mac/#technotes/tn2065/_index.html
A working example :
My LogoutHook :
Code:
sudo defaults write com.apple.loginwindow LogoutHook "/Users/test/logout"
Contents of the logout shellscript :
Code:
#!/bin/bash
/usr/bin/osascript "/Users/test/Documents/Applescripts/LogoutDialog.scpt"
Contents of the LogoutDialog.scpt Applescript. Nothing fancy it just deletes a folder named Postscript located on my Desktop and shows a dialog box at the end. It also does some logging to see what the script did.
Code:
set commonScript to load script alias "LeopardFirewire:Users:test:Library:Scripts:Common code.scpt"
set the_user to do shell script "logname"
set the_user_list to {"test"}
if the_user is in the_user_list then
try
do shell script "rm -R /Users/" & the_user & "/Desktop/Postscript"
log_event("Removed the Postscript directory from the Desktop of user : " & the_user) of commonScript
on error theErr
log_event("Error occured : " & theErr) of commonScript
end try
end if
tell application "System Events"
activate
display dialog "The logout script has finished if you see this dialog. Check ~/Library/Logs/Logoutscript-events.log. The dialog will close after 15 seconds." with title "Logout Dialog" with icon caution giving up after 15
end tell
I logged out 2 times. The first time it removed the Postscript folder, the second time it errored because the Postscript folder didn't exist anymore.
The output from the log :
2012-06-15 20:24:43 Removed the Postscript directory from the Desktop of user : test
2012-06-15 20:25:55 Error occured : rm: /Users/test/Desktop/Postscript: No such file or directory
In the Console application in All Messages I see the following for
The first line in my log :
15/06/12 20:24:45 /System/Library/CoreServices/System Events.app/Contents/MacOS/System Events[1243] OpenScripting.framework - 'gdut' event accepted from process "osascript" (pid=1238 uid=0 euid=0) with different owner than (uid=501 euid=501)
15/06/12 20:25:00 com.apple.loginwindow[1107] «class bhit»:, «class gavu»:true
The second line in my log :
15/06/12 20:25:56 /System/Library/CoreServices/System Events.app/Contents/MacOS/System Events[1315] OpenScripting.framework - 'gdut' event accepted from process "osascript" (pid=1310 uid=0 euid=0) with different owner than (uid=501 euid=501)
15/06/12 20:26:11 com.apple.loginwindow[1248] «class bhit»:, «class gavu»:true