My scripts for handling junk mail in OS X Mail do not currently work in the just-released Mail bundled in Mac OS X Lion (10.7). I’m looking into what the new dictionary is to see how best to modify them for work going forward. Thanks for your patience.
Category Archives: AppleScript
Modifying My On-the-Phone AppleScript – iTunes Status
I’ve made a minor modification to my previous iteration of my on-the-phone AppleScript. Here’s the change:
tell application "iTunes" if player state is playing or player state is paused then playpause end tell
In the previous iteration, running on-phone.scpt would start iTunes to playing if it was invoked while iTunes stopped, and then pause iTunes when re-invoked. That doesn’t make sense: if iTunes is stopped, it’s stopped for a reason, and this script shouldn’t change that fact. For me, iTunes is stopped when I’m using AppleScript to invoke RadioSHARK or Pulsar to listen to the radio.
You can download the updated on-phone script.
Developing an On-the-Phone AppleScript
I’m now working from home, but I can’t stand not having music going when I’m working. I often answer the phones, so it was important to me to have an AppleScript that would quickly do the following:
- Mute the system volume so I can focus on the customer.
- Pause iTunes.
- Setting my Adium status as On-the-Phone so my co-workers know I’m on the phone.
The fun thing is that I’ve got to get the script to do the reverse when invoked again. Otherwise, what use is it?
My first step was to use Leaf Raker’s suggestion for how to mute the system volume with AppleScript. The approach there works fine; the only issue is going to be that the system volume returns to 50 when it’s invoked a second time. If you’re always using this script during the day, though, that shouldn’t be a problem. Thanks, Leaf Raker, for getting me started!
The second step is pausing iTunes. If you read the iTunes Applescript Dictionary, you’ll see that it has a verb “playpause” that toggles the status of iTunes. This is helpful for me when I’m listening to a podcast while working, because I would like to not lose my place while I’m on the phone. So it’s tell application "iTunes" to playpause to make it happen.
The last step, of course, is the Adium status change. The Adium wiki has a page on their AppleScript support, and after a number of tests, I found that this worked:
tell application "Adium" set thisStatus to the status type of the first account if thisStatus is available then set the status type of the first account to away set the status message of the first account to "I'm on the phone; be with you shortly" else set the status type of the first account to available set the status message of the first account to "" end if end tell
Now, this only works for my setup because I have the one account in Adium on this machine—Adium, for me, is dedicated to the IM support I have with work. Multiple-account setups would take some sniffing; this is done with of account "somename", rather than “the first account”. Of course, if you’re in my situation—working from home, wanting to set your status away when you’re on the phone—you probably only have one account in Adium that needs toggling. [You better not be on multiple IM channels if you're telecommuting, or you won't get anything done!]
The whole script is as follows:
set curVol to (get (output volume of (get volume settings))) if curVol > 0 then set volume output volume 0 else set volume output volume 50 end if tell application "iTunes" to playpause tell application "Adium" set thisStatus to the status type of the first account if thisStatus is available then set the status type of the first account to away set the status message of the first account to "I'm on the phone; be with you shortly" else set the status type of the first account to available set the status message of the first account to "" end if end tell
You can also download this: on-phone.scpt.
As always: shared without license and support. I’ll help if you ask questions in the comment, but I am under no obligation to get you to done. I worked to figure this one out, so you can work, too.
Unlike with my Mail scripting, I invoke this with the excellent Launchbar, although I’m sure that Quicksilver will invoke it for you, too. I just put this in ~/Library/Scripts for safe-keeping.
Update to my Spam-Reporting AppleScripts
I think I tried to do this back when I set these spam-reporting AppleScripts up originally, but I couldn’t find the right variable to set. Turns out I didn’t look hard enough. Here’s the change:
tell application "Mail"
set theMessages to the selection
repeat with thisMessage in theMessages
set newMessage to make new outgoing message at end of outgoing messages
tell newMessage
set content to thisMessage's source
set subject to thisMessage's subject
make new to recipient with properties {address:"spam@uce.gov"}
end tell
send newMessage
set junk mail status of thisMessage to true
set read status of thisMessage to true
move thisMessage to mailbox "INBOX/ConfirmedJunk" of account "[$account]"
end repeat
end tell
Simple enough, no? The updated scripts: spam_uce_gov.scpt and spoof_paypal_com.scpt. You could, of course, further modify the {address:”email@email.tld”} to send wherever you like. If, for example, you have a specific place you’re fighting phishing attempts [e.g., your bank], and you know their phishing address, set one up for them.
Additional Thoughts
I use these two scripts with the excellent Mail Act-On package. I have rules for each: J for general junk mail, and P for PayPal/eBay spam. Actually, my MA-O use is what drove me to seek out the junk mail status flag, because otherwise to train Mail’s spam filter took an extra step. I wish I’d Googled a little harder three years ago, as I’d probably have saved myself an hour of typing and clicking over that time.
Update: These scripts were broken by syntax changes in OS X Lion, but they have been updated.
AppleScript to Send Mail to spam@uce.gov, Move to Spam-Learning Folder
Okay, the title of this is pretty darn long, but I’m writing for Google.
Back some time ago, I saw this AppleScript to forward spam to the FTC via Mail and liked the concept. It makes me at least feel like I’m doing something, you know? [Probably not much; I'm a government contractor, so I know what government might not do well.] I adapted it to report PayPal phishing attempts to spoof@paypal.com, and well, that was really it. My main change was in deleting the email after sending the mail on forward.
Now that Fastmail provides a spam-learning option for folders, I’m wanting to improve its spam filters. It already does a solid job—most of the spam I get goes into Junk Mail. However, I do get false positives, so I didn’t want Junk Mail to become the spam-learning folder. I then devised this concept:
- Create a folder called ConfirmedJunk and set it in Fastmail’s Web interface to be a spam-learning folder. I also set this folder to auto-purge every month to keep my quota use down.
- Rework my AppleScripts to go from deleting the junk mail to putting in ConfirmedJunk.
- There is no step 3.
Well, it took a little while banging my head on this tonight, but here’s what I came up with:
tell application "Mail"
set theMessages to the selection
repeat with thisMessage in theMessages
set newMessage to make new outgoing message at end of outgoing messages
tell newMessage
set content to thisMessage's source
set subject to thisMessage's subject
make new to recipient with properties {address:"spam@uce.gov"}
end tell
send newMessage
set read status of thisMessage to true
move thisMessage to mailbox "INBOX/ConfirmedJunk" of account "[$account]"
end repeat
end tell
The above is “spam_uce_gov.scpt“.
tell application "Mail"
set theMessages to the selection
repeat with thisMessage in theMessages
set newMessage to make new outgoing message at end of outgoing messages
tell newMessage
set content to thisMessage's source
set subject to thisMessage's subject
make new to recipient with properties {address:"spoof@paypal.com"}
end tell
send newMessage
set read status of thisMessage to true
move thisMessage to mailbox "INBOX/ConfirmedJunk" of account "[$account]"
end repeat
end tell
That’s “spam_paypal_com.scpt“.
Use ‘em if you can. Be sure to put the name of the account in there as Mail knows it and change the folder name as appropriate. I will not know the specifics of your setup unless you mirror mine. This script is provided free of charge and is unsupported.
6 Jun 2010: The scripts shown in this post have been superseded by a more recent update.