Motherboard Forums


Reply
Thread Tools Display Modes

LaunchAgent to quit Safari

 
 
Lewis
Guest
Posts: n/a
 
      07-18-2012, 06:49 AM
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?

--
I WILL NOT DO THE DIRTY BIRD Bart chalkboard Ep. AABF08
 
Reply With Quote
 
 
 
 
Thom Rosario
Guest
Posts: n/a
 
      07-22-2012, 11:50 AM
Lewis <(E-Mail Removed)> wrote:
> 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?



Perhaps try a shell command instead of an AppleScript?
> killall Safari


should do the trick
 
Reply With Quote
 
 
 
 
Lewis
Guest
Posts: n/a
 
      07-22-2012, 11:32 PM
In message <(E-Mail Removed)-september.org>
Thom Rosario <(E-Mail Removed)> wrote:
> Lewis <(E-Mail Removed)> wrote:
>> 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?



> Perhaps try a shell command instead of an AppleScript?
>> killall Safari


The point is to have this fire at 06:15 every single day, or as soon as
the machine wakes up in the morning if it's after 06:15.

The osascript command works, it is the LaunchAgent that doesn't seem to work.

--
THE PRESIDENT DID IT IS NOT AN EXCUSE Bart chalkboard Ep. AABF05
 
Reply With Quote
 
Lewis
Guest
Posts: n/a
 
      07-22-2012, 11:49 PM
In message <(E-Mail Removed)>
Jolly Roger <(E-Mail Removed)> wrote:
> In article <(E-Mail Removed)>,
> Lewis <(E-Mail Removed)> wrote:


>> 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?


> Have you examined the system log to see if there are entries around the
> time the event is supposed to happen?


Yes, and there's nothing at all in them. The user is not an admin user, so he doesn't have access to all the loggin, so I will try and reload the LaunchAgent and doublecheck if the admin account sees anything in the logs.

--
When we woke up that morning we had no way of knowing that in a matter
of hours we'd changed the way we were going. Where would I be now? Where
would I be now if we'd never met? Would I be singing this song to
someone else instead?
 
Reply With Quote
 
Lewis
Guest
Posts: n/a
 
      07-23-2012, 02:01 AM
In message <(E-Mail Removed)>
Jolly Roger <(E-Mail Removed)> wrote:
> BTW, if Safari is not running, your script will cause it to launch. ; )


Launch and then quit. Small price to pay for getting it to quit on a
regular basis. I have never seen it take multiple GB of real memory on
my machines, but on this one last time I checked it was using 10.4GB of
Real Memory for something like 8 tabs.

--
Just give us a kiss to celebrate here, today.
 
Reply With Quote
 
Lewis
Guest
Posts: n/a
 
      07-23-2012, 08:35 AM
In message <(E-Mail Removed)>
Paul Sture <(E-Mail Removed)> wrote:
> Why not put the whole call to osascript into a script and call that?


I will probably do that.

--
Mirrors contain infinity. Infinity contains more things than you think.
Everything, for a start. Including hunger. Because there's a million
billion images, but only one soul to go around. --Witches Abroad
 
Reply With Quote
 
John Drako
Guest
Posts: n/a
 
      07-23-2012, 05:41 PM
On Wed, 18 Jul 2012 02:49:25 -0400, Lewis wrote
(in article <(E-Mail Removed)>):

> 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>

 
Reply With Quote
 
Lewis
Guest
Posts: n/a
 
      07-24-2012, 02:47 AM
In message <Z0gPr.9781$%(E-Mail Removed)>
John Drako <(E-Mail Removed)> wrote:
> On Wed, 18 Jul 2012 02:49:25 -0400, Lewis wrote
> (in article <(E-Mail Removed)>):


>> 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).

--
what was supposed to be so special about a full moon? It was only a big
circle of light. And the dark of the moon was only darkness. But
half-way between the two, when the moon was between the worlds of light
and dark, when even the moon lived on the edge... maybe then a witch
could believe in the moon. --Witches Abroad
 
Reply With Quote
 
John Drako
Guest
Posts: n/a
 
      07-24-2012, 04:03 AM
On Mon, 23 Jul 2012 22:47:26 -0400, Lewis wrote
(in article <(E-Mail Removed)>):

> In message <Z0gPr.9781$%(E-Mail Removed)>
> John Drako <(E-Mail Removed)> wrote:
>> On Wed, 18 Jul 2012 02:49:25 -0400, Lewis wrote
>> (in article <(E-Mail Removed)>):

>
>>> 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.

 
Reply With Quote
 
Barry Margolin
Guest
Posts: n/a
 
      07-24-2012, 04:11 AM
In article <t8pPr.94645$(E-Mail Removed) >,
John Drako <(E-Mail Removed)> wrote:

> On Mon, 23 Jul 2012 22:47:26 -0400, Lewis wrote
> (in article <(E-Mail Removed)>):
>
> > In message <Z0gPr.9781$%(E-Mail Removed)>
> > John Drako <(E-Mail Removed)> wrote:
> >> On Wed, 18 Jul 2012 02:49:25 -0400, Lewis wrote
> >> (in article <(E-Mail Removed)>):

> >
> >>> 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, (E-Mail Removed)
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
 
Reply With Quote
 
 
 
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Safari Web Content/ Quit and Keep Windows j Burns Apple 13 02-05-2013 03:08 AM
How to launch a LaunchAgent? Dav Apple 1 08-16-2012 09:48 PM
LaunchAgent to quit Safari Lewis Apple 0 07-18-2012 06:51 AM
Are you sure you want to quit Safari? Davoud Apple 28 08-12-2007 02:38 PM
OS X apps now really Quit when requested to Quit?? Mr. Uh Clem Apple 12 04-07-2006 04:07 PM


All times are GMT. The time now is 05:09 AM.


Welcome!
Welcome to Motherboard Point
 

Advertisment