In article <t8pPr.94645$ >,
John Drako <> wrote:
> On Mon, 23 Jul 2012 22:47:26 -0400, Lewis wrote
> (in article <>):
>
> > In message <Z0gPr.9781$%>
> > John Drako <> wrote:
> >> On Wed, 18 Jul 2012 02:49:25 -0400, Lewis wrote
> >> (in article <>):
> >
> >>> I have the following launchagent:
> >>>
> >>> <?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>jte.safari</string>
> >>> <key>ProgramArguments</key>
> >>> <array>
> >>> <string>/usr/bin/osascript</string>
> >>> <string>-e</string>
> >>> <string>"tell application \"Safari\" to quit"</string>
> >>> </array>
> >>> <key>ServiceDescription</key>
> >>> <string>Quit Safari</string>
> >>> <key>StartCalendarInterval</key>
> >>> <dict>
> >>> <key>Hour</key>
> >>> <integer>6</integer>
> >>> <key>Minute</key>
> >>> <integer>15</integer>
> >>> </dict>
> >>> </dict>
> >>> </plist>
> >>>
> >>> Which should quit Safari every morning at 6:15, only it doesn't. I
> >>> checked today and the safari process was a month old.
> >>>
> >>> I have other LaunchAgents that work fine. It is loaded and listed as
> >>> active in `launchctl list | grep jte.safari`
> >>>
> >>> Generally the machine is asleep at 6:15, but my understanding was that a
> >>> timed event would fire the next time it could, not simply be skipped.
> >>>
> >>> Any ideas?
> >
> >> You're missing the username argument:
> >
> >> right before the last </dict> add:
> >
> >> <key>UserName</key>
> >> <string>your short user name here</string>
> >> </dict>
> >> </plist>
> >
> > I have well more than a dozen ~/Library/LaunchAgents and not one has a
> > Username key. As I understand it, the username is only used if you want
> > a task to run from /Library as a specific user instead of either root
> > (LaunchDaemons) or the user logging in (LaunchAgents).
>
> It helped in the past for me. Give it a try before dismissing it.
While it obviously can't hurt to try, I think he's right. UserName
isn't needed in personal LaunchAgent files, only in the system-wide
file. I've never had to add that in any of my LaunchAgent files.
In fact, I'd go so far as to say that putting it in personal files would
be *wrong*. User A shouldn't be able to run programs as User B, so what
would be the point if the only name you can put there is the one that it
knows it has to run the program as.
I suspect the problem is the quoting. Try changing:
<string>"tell application \"Safari\" to quit"</string>
to:
<string>tell application "Safari" to quit</string>
Quotes around a string are only needed for the shell, but LaunchDaemon
is running the program directly, not going through a shell. And the
separate <string>...</string> elements in the array already indicate
that it's a single string argument.
--
Barry Margolin,
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***