New To Mac-Forums?

Welcome to our community! Join the discussion today by registering your FREE account. If you have any problems with the registration process, please contact us!

Get your questions answered by community gurus Ľ Advice and insight from world-class Apple enthusiasts Ľ Exclusive access to members-only contests, giveaways and deals

Join today!

 
Start a Discussion
 

Mac-Forums Brief

Subscribe to Mac-Forums Brief to receive special offers from Mac-Forums partners and sponsors

Join the conversation RSS
OS X - Development and Darwin Discussion and questions about development for Mac OS X.

Applescript runs continuously through launchd plist


Post Reply New Thread Subscribe

 
Thread Tools
rothnd

 
Member Since: Oct 22, 2008
Posts: 2
rothnd is on a distinguished road

rothnd is offline
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!!!
QUOTE Thanks
rothnd

 
Member Since: Oct 22, 2008
Posts: 2
rothnd is on a distinguished road

rothnd is offline
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!
QUOTE Thanks

Post Reply New Thread Subscribe


« Keyboard to Shell ?? | how to get a "make" in 10.5.5 »
Thread Tools

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
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
Forum Jump

Similar Threads
Thread
Thread Starter
Forum
Replies
Last Post
How to run more than one programs in single plist through launchd Pankaj OS X - Development and Darwin 1 02-18-2008 12:36 PM
[ANN] New comprehensive AppleScript book hanaan OS X - Development and Darwin 0 11-06-2004 07:28 PM

All times are GMT -4. The time now is 01:02 AM.

Powered by vBulletin
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
X

Welcome to Mac-Forums.com

Create your username to jump into the discussion!

New members like you have made this community the ultimate source for your Mac since 2003!


(4 digit year)

Already a member?