<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>GFMorris.org &#187; AppleScript</title>
	<atom:link href="http://gfmorris.org/categories/applescript/feed/" rel="self" type="application/rss+xml" />
	<link>http://gfmorris.org</link>
	<description>Smart Guy, Dumb Code</description>
	<lastBuildDate>Sat, 17 Jul 2010 15:39:22 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Developing an On-the-Phone AppleScript</title>
		<link>http://gfmorris.org/archives/2010/06/16/developing-an-on-the-phone-applescript/</link>
		<comments>http://gfmorris.org/archives/2010/06/16/developing-an-on-the-phone-applescript/#comments</comments>
		<pubDate>Wed, 16 Jun 2010 19:12:48 +0000</pubDate>
		<dc:creator>Geof F. Morris</dc:creator>
				<category><![CDATA[AppleScript]]></category>
		<category><![CDATA[Adium]]></category>
		<category><![CDATA[system volume]]></category>

		<guid isPermaLink="false">http://gfmorris.org/?p=39</guid>
		<description><![CDATA[I&#8217;m now working from home, but I can&#8217;t stand not having music going when I&#8217;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 [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m now <a href="http://wphelpcenter.com/">working from home</a>, but I can&#8217;t stand not having music going when I&#8217;m working.  I often answer the phones, so it was important to me to have an AppleScript that would quickly do the following:</p>
<ol>
<li>Mute the system volume so I can focus on the customer.</li>
<li>Pause iTunes.</li>
<li>Setting my Adium status as On-the-Phone so my co-workers know I&#8217;m on the phone.</li>
</ol>
<p>The fun thing is that I&#8217;ve got to get the script to do the reverse when invoked again.  Otherwise, what use is it?</p>
<p>My first step was to use <a href="http://leafraker.com/2007/11/13/mute-system-volume-with-apple-script-and-quicksilver/">Leaf Raker&#8217;s suggestion for how to mute the system volume with AppleScript</a>.  The approach there works fine; the only issue is going to be that the system volume returns to 50 when it&#8217;s invoked a second time.  If you&#8217;re always using this script during the day, though, that shouldn&#8217;t be a problem.  Thanks, Leaf Raker, for getting me started!</p>
<p>The second step is pausing iTunes.  If you read the iTunes Applescript Dictionary, you&#8217;ll see that it has a verb &#8220;playpause&#8221; that toggles the status of iTunes.  This is helpful for me when I&#8217;m listening to a podcast while working, because I would like to not lose my place while I&#8217;m on the phone.  So it&#8217;s <code>tell application "iTunes" to playpause</code> to make it happen.</p>
<p>The last step, of course, is the Adium status change.  <a href="http://trac.adium.im/wiki/AppleScript_Support_1.2">The Adium wiki has a page on their AppleScript support</a>, and after a number of tests, I found that this worked:</p>
<pre>
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
</pre>
<p>Now, this only works for my setup because I have the one account in Adium on this machine&#8212;Adium, for me, is dedicated to the IM support I have with work.  Multiple-account setups would take some sniffing; this is done with <code>of account "somename"</code>, rather than &#8220;the first account&#8221;.  Of course, if you&#8217;re in my situation&#8212;working from home, wanting to set your status away when you&#8217;re on the phone&#8212;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!]</p>
<p>The whole script is as follows:</p>
<pre>
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
</pre>
<p>You can also download this: <a href="http://gfmorris.org/wordpress/wp-content/uploads/2010/06/on-phone.scpt">on-phone.scpt</a>.</p>
<p>As always: shared without license and support.  I&#8217;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.  <img src='http://gfmorris.org/wordpress/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>Unlike with <a href="http://gfmorris.org/archives/2010/06/06/update-to-my-spam-reporting-applescripts/">my Mail scripting</a>, I invoke this with the excellent <a href="http://www.obdev.at/products/launchbar/index.html">Launchbar</a>, although I&#8217;m sure that <a href="http://quicksilver.en.softonic.com/mac">Quicksilver</a> will invoke it for you, too.  I just put this in ~/Library/Scripts for safe-keeping.</p>
<img src="http://gfmorris.org/wordpress/?ak_action=api_record_view&id=39&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://gfmorris.org/archives/2010/06/16/developing-an-on-the-phone-applescript/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Update to my Spam-Reporting AppleScripts</title>
		<link>http://gfmorris.org/archives/2010/06/06/update-to-my-spam-reporting-applescripts/</link>
		<comments>http://gfmorris.org/archives/2010/06/06/update-to-my-spam-reporting-applescripts/#comments</comments>
		<pubDate>Mon, 07 Jun 2010 03:21:11 +0000</pubDate>
		<dc:creator>Geof F. Morris</dc:creator>
				<category><![CDATA[AppleScript]]></category>

		<guid isPermaLink="false">http://gfmorris.org/?p=34</guid>
		<description><![CDATA[I think I tried to do this back when I set these spam-reporting AppleScripts up originally, but I couldn&#8217;t find the right variable to set. Turns out I didn&#8217;t look hard enough. Here&#8217;s the change: tell application "Mail" set theMessages to the selection repeat with thisMessage in theMessages set newMessage to make new outgoing message [...]]]></description>
			<content:encoded><![CDATA[<p>I think I tried to do this back <a href="http://gfmorris.org/archives/2007/10/17/applescript-spam-handler/">when I set these spam-reporting AppleScripts up originally</a>, but I couldn&#8217;t find the right variable to set.  Turns out I didn&#8217;t look hard enough.  Here&#8217;s the change:</p>
<pre>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
		<strong>set junk mail status of thisMessage to true</strong>
		set read status of thisMessage to true
		move thisMessage to mailbox "INBOX/ConfirmedJunk" of account "[$account]"
	end repeat
end tell</pre>
<p>Simple enough, no?  The updated scripts: <a href="http://gfmorris.org/wordpress/wp-content/uploads/2010/06/spam_uce_gov.scpt">spam_uce_gov.scpt</a> and <a href="http://gfmorris.org/wordpress/wp-content/uploads/2010/06/spoof_paypal_com.scpt">spoof_paypal_com.scpt</a>.  You could, of course, further modify the <i>{address:&#8221;email@email.tld&#8221;}</i> to send wherever you like.  If, for example, you have a specific place you&#8217;re fighting phishing attempts [e.g., your bank], and you know their phishing address, set one up for them.</p>
<p><strong>Additional Thoughts</strong></p>
<p>I use these two scripts with the excellent <a href="http://indev.ca/MailActOn.html">Mail Act-On</a> 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&#8217;s spam filter took an extra step.  I wish I&#8217;d Googled a little harder three years ago, as I&#8217;d probably have saved myself an hour of typing and clicking over that time.</p>
<img src="http://gfmorris.org/wordpress/?ak_action=api_record_view&id=34&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://gfmorris.org/archives/2010/06/06/update-to-my-spam-reporting-applescripts/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>AppleScript to Send Mail to spam@uce.gov, Move to Spam-Learning Folder</title>
		<link>http://gfmorris.org/archives/2007/10/17/applescript-spam-handler/</link>
		<comments>http://gfmorris.org/archives/2007/10/17/applescript-spam-handler/#comments</comments>
		<pubDate>Thu, 18 Oct 2007 03:04:21 +0000</pubDate>
		<dc:creator>Geof F. Morris</dc:creator>
				<category><![CDATA[AppleScript]]></category>

		<guid isPermaLink="false">http://gfmorris.org/archives/2007/10/17/applescript-spam-handler/</guid>
		<description><![CDATA[Okay, the title of this is pretty darn long, but I&#8217;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&#8217;m doing something, you know? [Probably not much; I'm a government contractor, so I [...]]]></description>
			<content:encoded><![CDATA[<p>Okay, the title of this is pretty darn long, but I&#8217;m writing for Google.  <img src='http://gfmorris.org/wordpress/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Back some time ago, I saw this <a href="http://www.macosxhints.com/article.php?story=20060219014940761&#038;lsrc=osxh">AppleScript to forward spam to the FTC via Mail</a> and liked the concept.  It makes me at least feel like I&#8217;m doing <em>something</em>, 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.</p>
<p>Now that <a href="http://blog.fastmail.fm/2007/09/26/new-folders-screen-and-features-released/">Fastmail provides a spam-learning option for folders</a>, I&#8217;m wanting to improve its spam filters.  It already does a solid job&#8212;most of the spam I get goes into Junk Mail.  However, I do get false positives, so I didn&#8217;t want Junk Mail to become the spam-learning folder.  I then devised this concept:</p>
<ol>
<li>Create a folder called ConfirmedJunk and set it in Fastmail&#8217;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.</li>
<li>Rework my AppleScripts to go from deleting the junk mail to putting in ConfirmedJunk.</li>
<li>There is no step 3.</li>
</ol>
<p>Well, it took <a href="http://twitter.com/gfmorris/statuses/343690462">a little while</a> <a href="http://twitter.com/gfmorris/statuses/343997682">banging my head</a> on this tonight, but <a href="http://twitter.com/gfmorris/statuses/344011792">here&#8217;s what I came up with</a>:</p>
<pre>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</pre>
<p>The above is &#8220;<a href="http://gfmorris.org/wordpress/wp-content/uploads/2007/10/spam_uce_gov.scpt">spam_uce_gov.scpt</a>&#8220;.</p>
<pre>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</pre>
<p>That&#8217;s &#8220;<a href="http://gfmorris.org/wordpress/wp-content/uploads/2007/10/spoof_paypal_com.scpt">spam_paypal_com.scpt</a>&#8220;.</p>
<p>Use &#8216;em if you can.  <strong>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.</strong></p>
<p><ins datetime="2010-06-07T03:21:34+00:00">6 Jun 2010</ins>: <a href="http://gfmorris.org/archives/2010/06/06/update-to-my-spam-reporting-applescripts/">The scripts shown in this post have been superseded by a more recent update</a>.</p>
<img src="http://gfmorris.org/wordpress/?ak_action=api_record_view&id=27&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://gfmorris.org/archives/2007/10/17/applescript-spam-handler/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
