Results 1 to 2 of 2
  1. #1
    Applescript runs continuously through launchd plist

    Member Since
    Oct 22, 2008
    Posts
    2
    Applescript runs continuously through launchd plist
    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!!!

  2. #2
    Applescript runs continuously through launchd plist

    Member Since
    Oct 22, 2008
    Posts
    2
    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!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. 13" Macbook runs slow on battery, Runs fast on power
    By askclifford in forum Apple Notebooks
    Replies: 9
    Last Post: 01-08-2012, 12:33 PM
  2. launchd plist file
    By vasu in forum OS X - Operating System
    Replies: 2
    Last Post: 12-13-2011, 10:32 AM
  3. Hard Drive runs continuously......
    By buddyl in forum Apple Desktops
    Replies: 2
    Last Post: 12-21-2009, 07:30 PM
  4. How to run more than one programs in single plist through launchd
    By Pankaj in forum OS X - Development and Darwin
    Replies: 1
    Last Post: 02-18-2008, 12:36 PM
  5. Getting launchd working
    By dr_springfield in forum OS X - Development and Darwin
    Replies: 0
    Last Post: 05-10-2005, 02:40 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •