Applescript runs continuously through launchd plist

Joined
Oct 22, 2008
Messages
2
Reaction score
0
Points
1
Hey all

I'm hoping someone out there has learned something useful about launchd, plist's, and timing scripts.

I have a rather simple script that I was trying to make run on a schedule through launchd (15 min to be exact) mainly to get to learn the system.

The general problems... I finally got through it all enough to load the script into launchd through a valid plist ("verified in Lingon" though I don't think was necessary since all Lingon did was add fields withe "false" values). The jist though is the plist file (I've named com.nathan.messagealert.plist to keep the *^#4& formatting going) calls on an Applescript (which runs perfectly fine in the editor or even as an app on startup) which it should then run on a "StartInterval" schedule of 900 sec. Now, I read and found the proper way of making the script an executable file which made it load but it's acting very funny. Remember the time schedule of 15 min I mentioned?? Well, when the script was loaded it kept running and running and running...you get the idea. It wouldn't stop until I killed it.

Any thoughts on why this would react this way? Is a scpt file ok? Does the scpt need a "quit" or "exit" at the end of it? I'm just analyzing the possibilities...

Here is the Applescript scpt file which at the moment has no other properties than just that (is not run only, an app, etc)

Code:
say "Welcome back, Nathan."

tell application "Mail"
	repeat with thisAccount in every account
		set thisInBox to mailbox named "INBOX" of thisAccount
		set thisUnreadCount to unread count of thisInBox
		
		if thisUnreadCount is not 0 then
			set unreadMessages to (messages of thisInBox whose read status is false)
			
			if thisUnreadCount > 1 then
				set pluralText to "s"
				set verbText to "are"
			else
				set pluralText to ""
				set verbText to "is"
			end if
			
			set speechCountText to "There " & verbText & " " & thisUnreadCount & " unread message" & pluralText & " in " & (name of thisAccount) & "."
			say speechCountText
			
			tell application "Safari"
				activate
			end tell
			
		end if
	end repeat
end tell

And here is the plist file

Code:
<?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>Disabled</key>
	<true/>
	<key>KeepAlive</key>
	<false/>
	<key>Label</key>
	<string>com.nathan.messagealert</string>
	<key>OnDemand</key>
	<false/>
	<key>Program</key>
	<string>/usr/bin/osascript</string>
	<key>ProgramArguments</key>
	<array>
		<string>osascript</string>
		<string>/Library/Scripts/MailMessage.scpt</string>
	</array>
	<key>RunAtLoad</key>
	<false/>
	<key>StartInterval</key>
	<integer>1200</integer>
</dict>
</plist>

Again, any input on why this would cause the script to run over and over and over would be greatly appreciated. Thanks!!!
 
OP
R
Joined
Oct 22, 2008
Messages
2
Reaction score
0
Points
1
Ok, Just to get caught up here and make it very clear where I'm at here's the new full story

The applescript script seems to be failing for some reason despite compiling and working properly from the script editor.

Here is the plist that calls the script and seems to be working properly (by that I mean that it executes the first say command at 5 min intervals)

CODE
<?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>com.nathan.MessageAlert</string>
<key>ProgramArguments</key>
<array>
<string>/usr/bin/osascript</string>
<string>/Library/Scripts/MailMessage.scpt</string>
</array>
<key>StartInterval</key>
<integer>300</integer>
</dict>
</plist>
[/CODE]

And here is the script
CODE
say "hello"
tell application "Mail"
activate
delay 5
repeat with thisAccount in every account
set thisInBox to mailbox named "INBOX" of thisAccount
set thisUnreadCount to unread count of thisInBox

if thisUnreadCount is not 0 then
set unreadMessages to (messages of thisInBox whose read status is false)

if thisUnreadCount > 1 then
set pluralText to "s"
set verbText to "are"
else
set pluralText to ""
set verbText to "is"
end if

set speechCountText to "There " & verbText & " " & thisUnreadCount & " unread message" & pluralText & " in " & (name of thisAccount) & "."
say "Welcome Back Nathan."
say speechCountText

tell application "Safari"
activate
end tell

end if
end repeat
end tell
[/CODE]

I thought by fixing the issues with the plist this would all be good but I am, yet again, at a loss. I'd like to mention that the script file is just that...a .scpt file... This file was not saved with any other properties offered (e.g. Run on Start, App, etc). Is this causing the problem or....? Also, again, it does execute the first say command but mail, the first application to open, never opens and the script never continues.

I'd appreciate any info in learning the problem here is!
 

Shop Amazon


Shop for your Apple, Mac, iPhone and other computer products on Amazon.
We are a participant in the Amazon Services LLC Associates Program, an affiliate program designed to provide a means for us to earn fees by linking to Amazon and affiliated sites.
Top