Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Need help with this Applescript/plist

This has been a learning experience for me. Everything checks out logically to me in this script/ plist but something isn't correct. Everything runs, but then the script runs every minute which is getting annoying since I'm opening a few programs in the script. If typing code it gets frustrating as it changes the active window.


Note, this is my first applescript and plist excercise so feel free to critique my code. The goal of the script is to be scheduled to run twice daily (2 plists) - in the am change my IM status to available, open some programs and enable an email account. In the evening, change status, disable email.


Since it's re running I figured it was simply the plist, but comparing it to other templates for accomplishing a task which repeats once daily it checks out to me.


<plist version="1.0">
<dict>
          <key>Label</key>
          <string>RMWEBENABLE</string>
          <key>ProgramArguments</key>
          <array>
                    <string>/disablemail.app/Contents/MacOS/applet</string>
          </array>
          <key>StartCalendarInterval</key>
          <dict>
                    <key>Hour</key>
                    <integer>8</integer>
                    <key>Minute</key>
                    <integer>2</integer>
          </dict>
</dict>
</plist>


So I'm assuming in my ignorace I have something that's not sucessfully closing an if statement or somethign is just done ineffeciently. Here's the script.


set offTime to 17

set onTime to 9

set dayOfWeek to weekday of (current date)

set theHour to get the (hours of (current date))


if theHour ≥ offTime or dayOfWeek = Saturday or dayOfWeek = Sunday then



#LEAVE ME ALONE!!!!


tell application "Mail"

set enabled of account "mailbox" to false

end tell

tell application "Messages"

set status to invisible

end tell

tell application "Microsoft Lync"


quit

end tell


else if theHour ≥ onTime then



#I'm available for contact

tell application "Mail"

set enabled of account "mailbox" to true

end tell


tell application "Messages"

set status to available

end tell


tell application "Microsoft Lync"


activate

end tell


tell application "Firefox"


activate

end tell


tell application "Coda 2"


activate

end tell


tell application "Google Chrome"


activate

end tell

end if


--------------------------


I guess I could do an absolute value say

elseiftheHour = 8 and theMinute = 2 then


but I'd prefer the way it is now since My computer may be off when this is scheduled to run, and I believe this will run on wake, or maybe it was a helpful sideeffect of the repeating... I can always change the plist to run on startup as well.

MacBook Pro with Retina display, OS X Mountain Lion (10.8.3)

Posted on May 9, 2013 7:17 AM

Reply
6 replies

May 9, 2013 7:06 PM in response to jxxjchcxx

As you were told in the other thread you had on this AppleScripts really don;t do well run like this.


If I was to guess my first thought would be the exit value of the script. As you don't have one it is possible that launchd is seeing the program as failing and restarting it. Try adding an exit 0 (or the AppleScript equivalent) at the end of the script and see if that makes a difference.

Need help with this Applescript/plist

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.