问题
I was looking for an option to color all unread mails in apple mail and I found the following script
tell application "Mail"
set background color of (messages of inbox whose read status is false) to red --unread
set background color of (messages of inbox whose read status is true) to none --default read
end tell
I added this script to a mail rule, which applies to every message, then it works almost perfect. The only problem is that it works only for one time. So if I get a new message, than the script doesn't notice it (so it is not red, only bold), or if I read an email, then it will be still red. Please can someone help me, that the script will run in loop, or that the script will run each second.
Just for information, I´m an windows user (mac is really new for me) and I was looking for an scheduled task option, but I didn't found such easy thing on my mac.
回答1:
You have several options to run scheduled tasks. Apple suggests to use the "launchd" agent. Just google "launchd tutorial" for many examples.
The basics are this... you create a plist file (an xml text file with the .plist file extension) with whatever instructions you want and put that it in the folder ~/Library/LaunchAgents. The tutorials will show you how to create many different kinds of plist files. Once you add your plist to that folder then logout/login to make it take effect. To disable a plist fie from running then remove it from the folder and logout/login. It's that simple.
As an example plist for your specific request, this one will run your applescript every 60 seconds...
<?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.myName.myProgramName</string>
<key>ProgramArguments</key>
<array>
<string>osascript</string>
<string>/path/to/applescript.scpt</string>
</array>
<key>StartInterval</key>
<integer>60</integer>
</dict>
</plist>
So in that plist example you just need to put your values in "com.myName.myProgramName", "/path/to/applescript.scpt", and "60" which is the number of seconds to run the applescript.
NOTE: you should name your plist file the same name as you give for "com.myName.myProgramName" with ".plist" as its file extension.
Good luck.
来源:https://stackoverflow.com/questions/29345592/how-to-repeat-or-loop-an-applescript