I could not find a way of executing a script for the Guest account during login which executes every minute. They say using cron daemon is deprecated so it looks like I will be using launchd with .plist files.
Scenario: I have a public iMac I want to allow the general public to use the guest account and have it force log out every half-hour. I wrote a ruby script to check the login time and figure out time remaining. I can have it display a banner notification every 10 minutes using osascript and then make it log off my account. Problem is when I try to implement it for the Guest account it doesn't work.
The problem is when I am placing the .plist file inside /Library/LaunchDaemons since it runs after login and also runs as root. Running as root is important since I can have the privilege to shut down processes when time runs out. I need it to execute once every minute. This it the current plist file that does work when I login as my own username "owner" but not guest. Using org.user.plist
My original .plist file looked something like this
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>org.user</string>
<key>Program</key>
<string>/usr/local/bin/notify-custom</string>
<key>RunAtLoad</key>
<true/>
</dict>
</plist>
Update 1 (Not a solution yet) .plist file which runs every 10 seconds for both Guest and my username
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>org.user</string>
<key>ProgramArguments</key>
<string>/usr/local/bin/notify-custom</string>
<key>WatchPaths</key>
<array>
<string>/Users/Guest/Library</string>
<string>/Users/owner/Library</string>
<array>
</integer>
</dict>
</plist>
As a test to make sure the osascript notification banner pops up I have this code inside /usr/local/bin/notify-custom
#/bin/bash
#Using whoami would have shown me logged in as root under LaunchDaemon .plist
loggedinUser=`finger | awk 'NR==3{print $1}'`
#I need to manually run terminal and type sudo as guest for nextline to work
sudo -u $loggedinUser /usr/bin/osascript -e 'display notification "Test" with title "Banner Notification"'
Solution is below.
notify-custom
and is it a binary or a script, and if the latter what's the contents of the script?root
in thewheel
group with0644
for permissions in/Library/LaunchAgents
and it ran when logged in as Guest. With the exception of the string for the Program key the rest of the file was the same. It worked as expected. I also look at the other LaunchAgents in the same location and checking in Activity Monitor their processes started too. So without knowing whatnotify-custom
is and its contents there's not much else I can offer at the moment other that to say .plist files in/Library/LaunchAgents
work in the Guest Account.