No Future Support for Junk Mail Scripting

My Lion-ready scripts for routing junk mail to the FTC’s site still work, but I have a high crash rate when using Mail Act-On 3.x to initiate that script.  The crash logs say that MAO is to blame for the crash, and perhaps that is so.  But it also feels like I’m screaming into the void here with the spam reporting, and so I will no longer be updating these scripts.  They are provided as-is from the July 2011 release.

You are free to use them as you see fit, and if you want to update, upgrade, and publish them, that’s great!  All I ask is that you link to at least one of the posts here.  People do land here on Google, and so I’d like to keep that chain unbroken.  When I see incoming link traffic, I’ll make a link to your site so people know that there is indeed a future for them; you may also let me know via email.  It’s been a good run.  I originally released this script in 2007.

If you’re curious, all I’m doing is culling ham out of the spam folder using Fastmail’s Web interface, and I’m filing all known-bad messages in that ConfirmedJunk folder that I mentioned in the previous posts.  Those are simple commands for a batch of messages.  I really wish that I had a way to easily pull ham out of the Fastmail junk folder without using the Web interface, but they’re seemingly not set up for that.  It doesn’t take that long to fire up Fastmail in a browser, so I’m just dealing with it.

‘Cause Waking Up Is Hard to Do

This is a nerdy post. I’m telling you that before you get sucked in. In short, I use my computer, which resides in my office, to send a continuous alarm to a set of speakers in my bedroom. I do this with a couple of AppleScripts and a cronjob. If what I said made you wonder if I was speaking a second language, this is not the post for you. However, as some of you have expressed a little bit of wonder at my Rube Goldberg alarm clock, I decided that I’d write it up. Here goes!

Why All the Trouble?

I’m a night owl. My most productive hours are 2200-0200, as shown by the timestamp on this post. I sleep better in the morning after the sun has come up than I do most of the time at night. My best sleep hours start at 0400. I have more than a year’s worth of data to prove this, as I’ve been tracking my sleep with Sleep Cycle alarm clock for more than two years. My ideal work schedule would be 1200-2100, as I could sleep in until 1030 or so.

The world does not live on my schedule.

My mother can tell you that waking me up is not easy. [I told her about this setup and she laughed for like 10 seconds. “Does it work? I bet it doesn’t work.” THANKS, MOM.] When I am at their house, she will stand at the door and repeat my name for a minute or two before I sleepily wonder just what in tarnation is going on. My MSMS roommates will tell you that I can get out of bed, walk across the room, turn the alarm off, get back in bed, and go right back to sleep. I can tell you that I’ve moved my alarm clock any number of times. I used to re-arrange my bedroom furniture every sixth months to fight this.

Yet what I’m doing right now is working. I explained it a couple of weeks ago on Facebook, and they were stunned to see the process. As such, I feel that I owe you an explanation.

What’s Happening Here?

I am piping audio around my house. This is starting to come into vogue with hardware and software solutions that replace things like Sonus systems, setups that run into the high hundreds and low thousands of dollars. This isn’t necessary anymore, especially if you use a Mac.

Equipment needed:

  • Any old Mac
  • Airport Express (AE)
  • Stereo speakers, self-powered, that accept 1/8″ input.

To make this work, connect the speakers to the AE. The AE serves as an AirPlay point that can be used for all sorts of things, including this alarm system. I pipe all sorts of audio to my bedroom, mainly a Web stream of BBC World Service and radio captured on my radioSHARK. [I’ll talk about these later, especially if there’s interest. The AppleScript that I have for the BBCWS stream is kinda fun.]

Software needed

Airfoil has a Windows version, too, but it’s still aimed at AirPlay. You’ll have to figure out how to automate Windows on your own, though.

Let’s Go, Baby

Here’s the chain of events:

  1. The night before, I use Audacity record an M4A of what I want to hear the next morning when I am waking up. I Export this file to ~/Documents/Alarms/. I name the file YYYYMMDD of the date I’ll be waking up. I found out tonight that using the same datestamp twice will cause the next step to fail.
  2. I fire off meridian-alarms.scpt using Launchbar. [If you’re trying to do this and haven’t been using Launchbar or Quicksilver: WTF, yo.] This 1) quits Meridian then 2) moves the file from ~/Documents/Alarms/ to ~/Library/Sounds/ and 3) re-activates Meridian. The quit/restart option is required for Meridian to know that the new alarm exists. [I’d like to thank the dev for telling me how to do this.] The only hitch is that you do have to click on a dialog box to quit.
  3. Go into the preferences for the Alarm and set the new wakeup sound to the file that you’ve just made. Failure to do this gets you the previous day’s alarm. Make sure that the Continuous option is checked, or you’ll hear yourself for 12 seconds and nevermore.
  4. Set up a fire-off time with Cronnix to run meridian-pipe.scpt. This will set you up for piped audio from Meridian to those speakers at alarm time.
  5. Go the fuck to sleep.
  6. Come wakey time, your cronjob will fire. Airfoil will be routing sound from Meridian to your bedroom speakers. Once your alarm fires, you’ll be hearing yourself from the night before.

Here are some screenshots that may help you understand what’s happening:

You click the highlighted line to get the alarm preference set.
Use the Play a Sound: drop-down to move to your new alarm sound.
Make sure to set times in Cronnix that correspond with the times that Meridian is set to send an alarm.

To kill the alarm, you’re going to have to get out of bed, walk out of your bedroom, find the computer in whatever room you keep, sit down, and turn the alarm off. I find that the combination of a) hearing why I need to be awake and b) having to do a lot of work to stay asleep makes things work for me.

How to Make This Work for You

I generalized the scripts, which have things like YOUR_HD, YOUR_USERNAME, and YOUR_AE in them. Please change those values to appropriate ones for you. Spaces are okay: my HDD is “HAL 9000”, which plays a part in the weird world of how I name my computers and attached hardware. [That naming system is now out of date.]

Is this overly nerdy? You bet. If one person uses this craziness, I’ll be happy.

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:

  1. Mute the system volume so I can focus on the customer.
  2. Pause iTunes.
  3. 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:

  1. 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.
  2. Rework my AppleScripts to go from deleting the junk mail to putting in ConfirmedJunk.
  3. 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.