• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag
 

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: LogoutHook not working
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: LogoutHook not working


  • Subject: Re: LogoutHook not working
  • From: Axel Luttgens <email@hidden>
  • Date: Sun, 04 Mar 2007 15:18:29 +0100

On 4/03/07 13:44, email@hidden wrote:

Hi everyone,

I have been struggling with getting a logout hook to run an applescript, but nothing works.

I know almost nothing about shell scripts and I have followed intructions on the internet (developer.apple and macosxhints). This is one version of the script:

#!/bin/bash
#logoutscript

timestamp=`date ''+%Y/%m/%d/%H.%M.%S''`
logfile="/Users/gunno/Documents/Flex/logoutTime.txt"
myApp="/Library/Hooks/logout.app/"

echo $timestamp >> "$logfile"
open "$myApp"
exit 0


There are some logical problems here. ;-)

When a user logs out, a kAELogOut Apple Event is sent to process loginwindow.
Process loginwindow then sends quit events to every application and processes, foreground and background, running on behalf of the user who is loging out.
When those applications and processes have been sucessfully quit, loginwindow resets various system pieces, and then executes your logout script, from within a very bare environment.
And... you are then trying to launch (with the open command) a new foreground, high-level, application!
In the best case, that attempt will just silently fail, without any harmful consequences.


On the other hand, a logout script is executed as user root, not as the user who logs out.
This of course means that the script has to be double-checked!
But this also means that the script's context isn't the user's context.


I have wrote to defaults and set the execution bit.
Instead of 'open "$myApp"' I have tried various solutions with osacript to no avail. Everything is fine from the terminal, but not when logging out. I have saved my applescript as application, application bundle, script and text.
My applescript:


on run
set gLogFile to (path to documents folder from user domain as string) & "Flex:FlexLogTest.txt"
set fileRef to open for access file gLogFile with write permission
set theText to (current date) as string
write theText to fileRef starting at ((get eof of fileRef) + 1)
close access fileRef
0
end run


So, assuming above script could be successfully run from the logout script, it would be very likely that gLogFile in fact is the path to a file in root's home directory.


The system log shows this error: (62: coreservicesd)tfp: failed on 0:


Such a log line may be written under various circumstances; if you are you sure it is related to your attempts, don't other lines appear too?


What am I doing wrong?


I'm not sure that even osascript could prove very useful in a logout context.
I would first try with something very simple, for example by replacing your line
open "$myApp"
with something like:
osascript -e '2 + 2' >>"$logfile"
If this works, you could then check with:
osascript -e 'path to documents folder from user domain as string' >>"$logfile"
for example, and then progress with more and more sophisticated operations.


Could you let us knwow?

HTH,
Axel

_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden
References: 
 >LogoutHook not working (From: <email@hidden>)

  • Prev by Date: Re: Print to PDF
  • Next by Date: Re: LogoutHook not working
  • Previous by thread: LogoutHook not working
  • Next by thread: Re: LogoutHook not working
  • Index(es):
    • Date
    • Thread