<?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>Mac Stuff</title>
	<atom:link href="http://macstuff.beachdogs.org/blog/?feed=rss2" rel="self" type="application/rss+xml" />
	<link>http://macstuff.beachdogs.org/blog</link>
	<description>A place for all my Macintosh-related scripts, tricks and tips</description>
	<lastBuildDate>Mon, 09 Apr 2012 16:12:59 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Quick Applescript to check your Mac for the Flashback infection</title>
		<link>http://macstuff.beachdogs.org/blog/?p=323</link>
		<comments>http://macstuff.beachdogs.org/blog/?p=323#comments</comments>
		<pubDate>Thu, 05 Apr 2012 19:54:37 +0000</pubDate>
		<dc:creator>webmaster</dc:creator>
				<category><![CDATA[Applescript]]></category>
		<category><![CDATA[Management]]></category>
		<category><![CDATA[Scripts]]></category>

		<guid isPermaLink="false">http://macstuff.beachdogs.org/blog/?p=323</guid>
		<description><![CDATA[There is lots of media exposure on the possibility that multiple Macs may be infected by a trojan called &#8220;Flashback&#8220;. This involves a vulnerability in Java that malicious websites can exploit. If you have Java on your Mac you need to make sure you have updated to the latest Java update from Apple to patch [...]]]></description>
			<content:encoded><![CDATA[<p>There is lots of media exposure on the possibility that multiple Macs may be infected by a trojan called &#8220;<a href="http://www.symantec.com/security_response/writeup.jsp?docid=2011-093016-1216-99" target="_blank">Flashback</a>&#8220;.  This involves a vulnerability in Java that malicious websites can exploit.  </p>
<p>If you have Java on your Mac you need to make sure you have updated to the latest Java update from Apple to patch this issue. The easiest way is to just run Software Update on your Mac and get the latest updates from Apple.  You can download them manually as well from Apple:</p>
<ul>
<li><a href="http://support.apple.com/kb/DL1515" target="_blank">Java for OS X Lion 2012-001</a></li>
<li><a href="http://support.apple.com/kb/DL1516" target="_blank">Java for Mac OS X 10.6 Update 7</a></li>
</ul>
<p>If you are concerned that you might already be infected F-Secure has some excellent instructions on how to find out <a href="http://www.f-secure.com/v-descs/trojan-downloader_osx_flashback_i.shtml" target="_blank">here</a>.  The Applescript below will run the commands referenced in the F-Secure article to do a quick and dirty check.  If everything comes back clean it will tell you.  If it comes back as possibly infected it will direct you (or your user) to the website for more detailed information.</p>
<p>I&#8217;m posting it as a script file for download here:<br />
<a href='http://macstuff.beachdogs.org/blog/wp-content/uploads/2012/04/Flashback_checker.scpt_1.zip'>Flashback Checker Script</a></p>
<p>Or you can copy the code from here and paste it into AppleScript Editor to run:</p>
<div id="wpshdo_1" class="wp-synhighlighter-outer"><div id="wpshdt_1" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_1"></a><a id="wpshat_1" class="wp-synhighlighter-title" href="#codesyntax_1"  onClick="javascript:wpsh_toggleBlock(1)" title="Click to show/hide code block">Code block</a></td><td align="right"><a href="#codesyntax_1" onClick="javascript:wpsh_code(1)" title="Show code only"><img border="0" style="border: 0 none" src="http://macstuff.beachdogs.org/blog/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_1" onClick="javascript:wpsh_print(1)" title="Print code"><img border="0" style="border: 0 none" src="http://macstuff.beachdogs.org/blog/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="http://macstuff.beachdogs.org/blog/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img border="0" style="border: 0 none" src="http://macstuff.beachdogs.org/blog/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_1" class="wp-synhighlighter-inner" style="display: block;"><pre class="applescript" style="font-family:monospace;"><span class="co1">--see if this entry exists.  If not an error will occur and be trapped</span>
<span class="kw3">try</span>
	<span class="kw1">do shell script</span> <span class="st0">&quot;defaults read /Applications/Safari.app/Contents/Info  LSEnvironment&quot;</span>
	<span class="co1">--set this variable if this entry exists</span>
	<span class="kw3">set</span> LSE <span class="kw3">to</span> <span class="st0">&quot;true&quot;</span>
<span class="kw3">on</span> <span class="kw3">error</span> errmsg
	<span class="co1">--set this variable if the error contains the message &quot;does not exist&quot;</span>
	<span class="kw3">if</span> errmsg <span class="kw2">contains</span> <span class="st0">&quot;does not exist&quot;</span> <span class="kw3">then</span>
		<span class="kw3">set</span> LSE <span class="kw3">to</span> <span class="st0">&quot;false&quot;</span>
	<span class="kw3">end</span> <span class="kw3">if</span>
<span class="kw3">end</span> <span class="kw3">try</span>
<span class="co1">--search Firefox for infections</span>
<span class="kw3">try</span>
	<span class="kw1">do shell script</span> <span class="st0">&quot;defaults read /Applications/Firefox.app/Contents/Info  LSEnvironment&quot;</span>
	<span class="co1">--set this variable if this entry exists</span>
	<span class="kw3">set</span> FLSE <span class="kw3">to</span> <span class="st0">&quot;true&quot;</span>
<span class="kw3">on</span> <span class="kw3">error</span> errmsg
	<span class="co1">--set this variable if the error contains the message &quot;does not exist&quot;</span>
	<span class="kw3">if</span> errmsg <span class="kw2">contains</span> <span class="st0">&quot;does not exist&quot;</span> <span class="kw3">then</span>
		<span class="kw3">set</span> FLSE <span class="kw3">to</span> <span class="st0">&quot;false&quot;</span>
	<span class="kw3">end</span> <span class="kw3">if</span>
<span class="kw3">end</span> <span class="kw3">try</span>
<span class="co1">--see if this entry exists.  If not an error will occur and be trapped</span>
<span class="kw3">try</span>
	<span class="kw1">do shell script</span> <span class="st0">&quot;defaults read ~/.MacOSX/environment DYLD_INSERT_LIBRARIES&quot;</span>
	<span class="kw3">set</span> DLib <span class="kw3">to</span> <span class="st0">&quot;true&quot;</span>
<span class="kw3">on</span> <span class="kw3">error</span> errmsg
	<span class="co1">--set this variable if the error contains the message &quot;does not exist&quot;</span>
	<span class="kw3">if</span> errmsg <span class="kw2">contains</span> <span class="st0">&quot;does not exist&quot;</span> <span class="kw3">then</span>
		<span class="kw3">set</span> DLib <span class="kw3">to</span> <span class="st0">&quot;false&quot;</span>
	<span class="kw3">end</span> <span class="kw3">if</span>
<span class="kw3">end</span> <span class="kw3">try</span>
<span class="co1">--if all variables are false then the machine isn't infected</span>
<span class="kw3">if</span> LSE <span class="kw3">is</span> <span class="st0">&quot;false&quot;</span> <span class="kw2">and</span> DLib <span class="kw3">is</span> <span class="st0">&quot;false&quot;</span> <span class="kw2">and</span> FLSE <span class="kw3">is</span> <span class="st0">&quot;false&quot;</span> <span class="kw3">then</span>
	<span class="kw1">display dialog</span> <span class="st0">&quot;You are not infected with Flashback&quot;</span>
	<span class="co1">--if any variable is true the machine may be infected and needs closer inspection</span>
<span class="kw3">else</span> <span class="kw3">if</span> LSE <span class="kw3">is</span> <span class="st0">&quot;true&quot;</span> <span class="kw2">or</span> DLib <span class="kw3">is</span> <span class="st0">&quot;true&quot;</span> <span class="kw2">or</span> FLSE <span class="kw3">is</span> <span class="st0">&quot;true&quot;</span> <span class="kw3">then</span>
	<span class="kw1">display dialog</span> <span class="st0">&quot;You may have the Flashback infection&quot;</span> <span class="sy0">&amp;</span> <span class="kw3">return</span> <span class="sy0">&amp;</span> <span class="st0">&quot;Go to following URL for more information:&quot;</span> <span class="sy0">&amp;</span> <span class="kw3">return</span> <span class="sy0">&amp;</span> <span class="kw3">return</span> <span class="sy0">&amp;</span> <span class="st0">&quot;http://www.f-secure.com/v-descs/trojan-downloader_osx_flashback_i.shtml&quot;</span>
<span class="kw3">end</span> <span class="kw3">if</span></pre></div></div>
]]></content:encoded>
			<wfw:commentRss>http://macstuff.beachdogs.org/blog/?feed=rss2&#038;p=323</wfw:commentRss>
		<slash:comments>17</slash:comments>
		</item>
		<item>
		<title>Creating local snapshots in Time Machine in Lion 10.7</title>
		<link>http://macstuff.beachdogs.org/blog/?p=316</link>
		<comments>http://macstuff.beachdogs.org/blog/?p=316#comments</comments>
		<pubDate>Thu, 17 Nov 2011 19:33:41 +0000</pubDate>
		<dc:creator>webmaster</dc:creator>
				<category><![CDATA[Management]]></category>
		<category><![CDATA[Scripts]]></category>
		<category><![CDATA[shell scripts]]></category>
		<category><![CDATA[System]]></category>
		<category><![CDATA[Lion]]></category>
		<category><![CDATA[time machine]]></category>

		<guid isPermaLink="false">http://macstuff.beachdogs.org/blog/?p=316</guid>
		<description><![CDATA[With the release of Lion Apple has added a new, somewhat hidden, ability to Time Machine. The ability to do local snapshots. Basically, when you are away from your Time Machine disc and have this enabled Lion will create your hourly snapshots locally instead of on your backup drive. Once you re-connect the drive it [...]]]></description>
			<content:encoded><![CDATA[<p>With the release of Lion Apple has added a new, somewhat hidden, ability to Time Machine. The ability to do local snapshots.  Basically, when you are away from your Time Machine disc and have this enabled Lion will create your hourly snapshots locally instead of on your backup drive.  Once you re-connect the drive it will move them over to your drive and wipe them off the local disc.</p>
<p>This is a great service for laptop users.  Now you can have those hourly snapshots created no matter where you are.  So, if you make some changes to a document while you&#8217;re away those changes will still be added to your Time Machine backup. </p>
<p>To enable these local snapshots you have use the new command-line tool for Time Machine named <code>tmutil</code>. </p>
<p>To enable local snapshots:</p>
<p><code>sudo tmutil enablelocal</code></p>
<p>To disable them AND clear all the local snapshots:</p>
<p><code>sudo tmutil disablelocal</code></p>
<p>You can confirm that you&#8217;ve enabled local snapshots by opening System Preferences > Time Machine and looking for the line circled in the image.</p>
<p><a href="http://macstuff.beachdogs.org/blog/wp-content/uploads/2011/11/localtmsnaps.png"><img src="http://macstuff.beachdogs.org/blog/wp-content/uploads/2011/11/localtmsnaps-300x200.png" alt="Local Time Machine Snapshots" title="" width="300" height="200" class="aligncenter size-medium wp-image-317" /></a></p>
<p>The <code>tmutil</code> utility has a bunch of other useful commands that allow you to enable or disable backups, start and stop backups, choose a new disk, etc.  Type <code>man tmutil</code> to see the whole list.  I can see this tool being used by lots of system administrators in scripts.</p>
<p>Apple also has a nice KB article explaining this feature <a href="http://support.apple.com/kb/HT4878" target="_blank">here</a></p>
]]></content:encoded>
			<wfw:commentRss>http://macstuff.beachdogs.org/blog/?feed=rss2&#038;p=316</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Hiding old purchases in the iTunes/Mac App stores</title>
		<link>http://macstuff.beachdogs.org/blog/?p=313</link>
		<comments>http://macstuff.beachdogs.org/blog/?p=313#comments</comments>
		<pubDate>Tue, 15 Nov 2011 17:59:22 +0000</pubDate>
		<dc:creator>webmaster</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://macstuff.beachdogs.org/blog/?p=313</guid>
		<description><![CDATA[Just about everyone with an iOS device has bought or gotten free apps that they thought would be cool or useful and then decided they didn&#8217;t need it. Deleting from your device is easy but what about your iTunes library? Especially now with iCloud keeping track of everything it&#8217;s not so obvious. It&#8217;s an especially [...]]]></description>
			<content:encoded><![CDATA[<p>Just about everyone with an iOS device has bought or gotten free apps that they thought would be cool or useful and then decided they didn&#8217;t need it.  Deleting from your device is easy but what about your iTunes library?  Especially now with iCloud keeping track of everything it&#8217;s not so obvious.  It&#8217;s an especially annoying thing when you keep seeing updates for all those apps showing up in the various App stores.  With the release of iTunes 10.5 you can now hide those apps from view AND from updating.</p>
<p>The technique is basically the same in iTunes as well as on your device:</p>
<ol>
<li>Click on the iTunes Store</li>
<li>Click the Purchased link on the far right</li>
<li>Pick your content (Music, Books, Apps, etc.)</li>
<li>Hover over the item you want to hide until you see the “X”</li>
<li>Click the “X” to hide that purchase</li>
</ol>
<p>Here are the links to the Apple KB articles on both the iTunes and Mac App stores and how to hide the unwanted apps.</p>
<p><a href="http://support.apple.com/kb/HT4919">iTunes Store: Hiding and unhiding purchases</a></p>
<p><a href="http://support.apple.com/kb/HT4928">Mac App Store: Hiding and unhiding purchases</a></p>
]]></content:encoded>
			<wfw:commentRss>http://macstuff.beachdogs.org/blog/?feed=rss2&#038;p=313</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Viewing or hiding hidden files in the Finder using AppleScript</title>
		<link>http://macstuff.beachdogs.org/blog/?p=293</link>
		<comments>http://macstuff.beachdogs.org/blog/?p=293#comments</comments>
		<pubDate>Fri, 05 Nov 2010 18:30:31 +0000</pubDate>
		<dc:creator>webmaster</dc:creator>
				<category><![CDATA[Applescript]]></category>
		<category><![CDATA[Scripts]]></category>

		<guid isPermaLink="false">http://macstuff.beachdogs.org/blog/?p=293</guid>
		<description><![CDATA[Mac OS X has a lot of files that are hidden from view in the Finder. They are hidden for a very good reason, which is most of them are system files that you don&#8217;t need to mess with if you want your computer to keep working well. However, there are occasions where it would [...]]]></description>
			<content:encoded><![CDATA[<p>Mac OS X has a lot of files that are hidden from view in the Finder.  They are hidden for a very good reason, which is most of them are system files that you don&#8217;t need to mess with if you want your computer to keep working well.  However, there are occasions where it would nice to be able to view these files in the Finder.  </p>
<p>This script lets you toggle the view on and off.  So, you can turn it on, do what you need and then turn it off.  </p>
<div id="wpshdo_2" class="wp-synhighlighter-outer"><div id="wpshdt_2" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_2"></a><a id="wpshat_2" class="wp-synhighlighter-title" href="#codesyntax_2"  onClick="javascript:wpsh_toggleBlock(2)" title="Click to show/hide code block">Code block</a></td><td align="right"><a href="#codesyntax_2" onClick="javascript:wpsh_code(2)" title="Show code only"><img border="0" style="border: 0 none" src="http://macstuff.beachdogs.org/blog/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_2" onClick="javascript:wpsh_print(2)" title="Print code"><img border="0" style="border: 0 none" src="http://macstuff.beachdogs.org/blog/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="http://macstuff.beachdogs.org/blog/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img border="0" style="border: 0 none" src="http://macstuff.beachdogs.org/blog/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_2" class="wp-synhighlighter-inner" style="display: block;"><pre class="applescript" style="font-family:monospace;"><span class="kw3">try</span>
	<span class="kw3">set</span> toggleView <span class="kw3">to</span> <span class="br0">&#40;</span><span class="kw1">do shell script</span> <span class="st0">&quot;defaults read com.apple.Finder AppleShowAllFiles&quot;</span><span class="br0">&#41;</span>
<span class="kw3">on</span> <span class="kw3">error</span>
	<span class="kw3">set</span> toggleView <span class="kw3">to</span> <span class="st0">&quot;NO&quot;</span>
<span class="kw3">end</span> <span class="kw3">try</span>
<span class="kw3">if</span> toggleView <span class="kw3">is</span> <span class="st0">&quot;NO&quot;</span> <span class="kw2">or</span> toggleView <span class="kw3">is</span> <span class="st0">&quot;0&quot;</span> <span class="kw3">then</span>
	<span class="kw3">set</span> br <span class="kw3">to</span> <span class="kw1">display dialog</span> <span class="st0">&quot;Showing hidden files is disabled.&quot;</span> <span class="sy0">&amp;</span> <span class="kw3">return</span> <span class="sy0">&amp;</span> <span class="st0">&quot;Would you like to enable it?&quot;</span> <span class="kw1">buttons</span> <span class="br0">&#123;</span><span class="st0">&quot;Yes&quot;</span>, <span class="st0">&quot;No&quot;</span><span class="br0">&#125;</span> default button <span class="br0">&#123;</span><span class="st0">&quot;No&quot;</span><span class="br0">&#125;</span>
	<span class="kw3">set</span> theAnswer <span class="kw3">to</span> <span class="kw2">the</span> button returned <span class="kw3">of</span> br
	<span class="kw3">if</span> theAnswer <span class="kw3">is</span> <span class="st0">&quot;Yes&quot;</span> <span class="kw3">then</span>
		<span class="kw1">do shell script</span> <span class="st0">&quot;defaults write com.apple.Finder AppleShowAllFiles YES&quot;</span>
		<span class="kw1">do shell script</span> <span class="st0">&quot;killall Finder&quot;</span>
		<span class="kw1">display dialog</span> <span class="st0">&quot;Showing hidden files has been enabled&quot;</span> <span class="kw1">buttons</span> <span class="br0">&#123;</span><span class="st0">&quot;Ok&quot;</span><span class="br0">&#125;</span> giving up <span class="kw2">after</span> 5
	<span class="kw3">end</span> <span class="kw3">if</span>
<span class="kw3">else</span>
	<span class="kw3">if</span> toggleView <span class="kw3">is</span> <span class="st0">&quot;YES&quot;</span> <span class="kw2">or</span> toggleView <span class="kw3">is</span> <span class="st0">&quot;1&quot;</span> <span class="kw3">then</span>
		<span class="kw3">set</span> br <span class="kw3">to</span> <span class="kw1">display dialog</span> <span class="st0">&quot;Showing hidden files is enabled.&quot;</span> <span class="sy0">&amp;</span> <span class="kw3">return</span> <span class="sy0">&amp;</span> <span class="st0">&quot;Would you like to disable it?&quot;</span> <span class="kw1">buttons</span> <span class="br0">&#123;</span><span class="st0">&quot;Yes&quot;</span>, <span class="st0">&quot;No&quot;</span><span class="br0">&#125;</span> default button <span class="br0">&#123;</span><span class="st0">&quot;Yes&quot;</span><span class="br0">&#125;</span>
		<span class="kw3">set</span> theAnswer <span class="kw3">to</span> <span class="kw2">the</span> button returned <span class="kw3">of</span> br
		<span class="kw3">if</span> theAnswer <span class="kw3">is</span> <span class="st0">&quot;Yes&quot;</span> <span class="kw3">then</span>
			<span class="kw1">do shell script</span> <span class="st0">&quot;defaults write com.apple.Finder AppleShowAllFiles NO&quot;</span>
			<span class="kw1">do shell script</span> <span class="st0">&quot;killall Finder&quot;</span>
			<span class="kw1">display dialog</span> <span class="st0">&quot;Showing hidden files has been disabled&quot;</span> <span class="kw1">buttons</span> <span class="br0">&#123;</span><span class="st0">&quot;Ok&quot;</span><span class="br0">&#125;</span> giving up <span class="kw2">after</span> 5
		<span class="kw3">end</span> <span class="kw3">if</span>
	<span class="kw3">end</span> <span class="kw3">if</span>
<span class="kw3">end</span> <span class="kw3">if</span></pre></div></div>
<p>Copy the code into AppleScript Editor and then save it out as an application.  Double clicking on it will bring up a dialog box telling you the current state of viewing hidden files and gives you the option of switching it.  Since you have to restart the Finder after you make this change you&#8217;ll see the Finder quit and restart.</p>
]]></content:encoded>
			<wfw:commentRss>http://macstuff.beachdogs.org/blog/?feed=rss2&#038;p=293</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Opening a FaceTime connection via AppleScript/Automator</title>
		<link>http://macstuff.beachdogs.org/blog/?p=280</link>
		<comments>http://macstuff.beachdogs.org/blog/?p=280#comments</comments>
		<pubDate>Fri, 22 Oct 2010 15:19:08 +0000</pubDate>
		<dc:creator>webmaster</dc:creator>
				<category><![CDATA[Applescript]]></category>
		<category><![CDATA[Scripts]]></category>

		<guid isPermaLink="false">http://macstuff.beachdogs.org/blog/?p=280</guid>
		<description><![CDATA[The new FaceTime video chat beta is now available from Apple. It allows you to video chat with anyone using that app on any Mac running the service as well as an iPhone 4 or the latest iPod running iOS 4 or better. It&#8217;s extremely easy and I can see a lot of great uses [...]]]></description>
			<content:encoded><![CDATA[<p>The new <a href="http://www.apple.com/mac/facetime/" target="_blank">FaceTime</a> video chat beta is now available from Apple.  It allows you to video chat with anyone using that app on any Mac running the service as well as an iPhone 4 or the latest iPod running iOS 4 or better.  It&#8217;s extremely easy  and I can see a lot of great uses for it.</p>
<p>One of the very cool things about it is that you can use a URL to initiate a FaceTime call.  As described in this <a href="http://hints.macworld.com/article.php?story=20101021131026694" target="_blank">Mac OS X Hints</a> article just use the following syntax:</p>
<ul>
<li>facetime://appleid</li>
<li>facetime://email@address</li>
<li>facetime://phone# as a URL in Safari&#8217;s address bar.</li>
</ul>
<p>Since you can use a URL that means you can use AppleScript to connect to a session or Automator to even schedule and initiate a call using iCal Alarms.</p>
<p>The only line you need is this:</p>
<div id="wpshdo_3" class="wp-synhighlighter-outer"><div id="wpshdt_3" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_3"></a><a id="wpshat_3" class="wp-synhighlighter-title" href="#codesyntax_3"  onClick="javascript:wpsh_toggleBlock(3)" title="Click to show/hide code block">Code block</a></td><td align="right"><a href="#codesyntax_3" onClick="javascript:wpsh_code(3)" title="Show code only"><img border="0" style="border: 0 none" src="http://macstuff.beachdogs.org/blog/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_3" onClick="javascript:wpsh_print(3)" title="Print code"><img border="0" style="border: 0 none" src="http://macstuff.beachdogs.org/blog/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="http://macstuff.beachdogs.org/blog/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img border="0" style="border: 0 none" src="http://macstuff.beachdogs.org/blog/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_3" class="wp-synhighlighter-inner" style="display: block;"><pre class="pascal" style="font-family:monospace;">open location <span class="st0">&quot;facetime://joe@emailaddress.com&quot;</span></pre></div></div>
<p>Obviously you can use any of the URL syntaxes listed above in place of the email address.  Save it as a script/application/workflow and you&#8217;re ready to chat!</p>
]]></content:encoded>
			<wfw:commentRss>http://macstuff.beachdogs.org/blog/?feed=rss2&#038;p=280</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>How to back up Address Book automatically</title>
		<link>http://macstuff.beachdogs.org/blog/?p=269</link>
		<comments>http://macstuff.beachdogs.org/blog/?p=269#comments</comments>
		<pubDate>Tue, 19 Oct 2010 17:29:46 +0000</pubDate>
		<dc:creator>macadmin</dc:creator>
				<category><![CDATA[Automator]]></category>
		<category><![CDATA[Management]]></category>
		<category><![CDATA[Scripts]]></category>
		<category><![CDATA[shell scripts]]></category>

		<guid isPermaLink="false">http://macstuff.beachdogs.org/blog/?p=269</guid>
		<description><![CDATA[For quite a while now you&#8217;ve been able to manually backup your entire Address Book. This has saved many people massive heartache when they&#8217;ve had their machines go down/did an OS re-install or various other scary things (Yeah, I know, if you have MobileMe you don&#8217;t need to do this but most people don&#8217;t). The [...]]]></description>
			<content:encoded><![CDATA[<p>For quite a while now you&#8217;ve been able to manually backup your entire Address Book.  This has saved many people massive heartache when they&#8217;ve had their machines go down/did an OS re-install or various other scary things (Yeah, I know, if you have MobileMe you don&#8217;t need to do this but most people don&#8217;t).</p>
<p>The big issue with backing up this way, as with any backup, is getting people to do it and do it regularly.  To backup your Address Book all you need to do it copy the /Users/&#8221;user name&#8221;/Library/Application Support/AddressBook folder in each users home directory.  Simple, direct and easy.  But you may have noticed that when you do a manual backup via the Address Book application you get a file with the &#8220;.abbu&#8221; extension.  That&#8217;s just the AddressBook folder renamed and getting that extension.  The beauty of having this file is when you want to restore your Address Book via the menu you can just point to this file.  Otherwise you have to drag the backed up folder to the original spot.  Again, not hard to do but some users have problems doing things that go outside of clicking on a menu item.</p>
<p>So, to back up your Address Book and put it in nice &#8220;.abbu&#8221; file for easy restores just do this:<br />
<div id="wpshdo_4" class="wp-synhighlighter-outer"><div id="wpshdt_4" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_4"></a><a id="wpshat_4" class="wp-synhighlighter-title" href="#codesyntax_4"  onClick="javascript:wpsh_toggleBlock(4)" title="Click to show/hide code block">Code block</a></td><td align="right"><a href="#codesyntax_4" onClick="javascript:wpsh_code(4)" title="Show code only"><img border="0" style="border: 0 none" src="http://macstuff.beachdogs.org/blog/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_4" onClick="javascript:wpsh_print(4)" title="Print code"><img border="0" style="border: 0 none" src="http://macstuff.beachdogs.org/blog/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="http://macstuff.beachdogs.org/blog/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img border="0" style="border: 0 none" src="http://macstuff.beachdogs.org/blog/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_4" class="wp-synhighlighter-inner" style="display: block;"><pre class="bash" style="font-family:monospace;"><span class="re2">filedate</span>=<span class="sy0">`/</span>bin<span class="sy0">/</span><span class="kw2">date</span> <span class="st0">&quot;+%m-%d-%y&quot;</span><span class="sy0">`</span>
<span class="kw2">cp</span> <span class="re5">-R</span> <span class="st0">&quot;/Users/username/Library/Application Support/AddressBook&quot;</span> <span class="st0">&quot;/Users/username/Documents/Address Book Backups/Address Book Backup <span class="es2">$filedate</span>.abbu&quot;</span></pre></div></div></p>
<p>Obviously you change the &#8220;username&#8221; section to the name of the home directory.  Also, you can change the backup folder to what ever you want.  This script just appends the current date to the backup so you can keep multiple backups if needed.</p>
<p>To run this you have a bunch of options:</p>
<ol>
<li>You can run it via cron or launchd.  Just put the two lines together and seperated by a &#8220;;&#8221;.
<ul>
You can create the launchd item here &#8211; <a href="http://plist.spotmac.de/" target="_blank">http://plist.spotmac.de/</a></ul>
</li>
<li>You can run it as an Automator iCal plug-in.  Just drag over the &#8220;Run Shell Script&#8221; action and paste in the script.  Then schedule it via iCal.</li>
<li>You can save it as a script and run it from what ever automation application you prefer.</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://macstuff.beachdogs.org/blog/?feed=rss2&#038;p=269</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Check how much disk space is left using AppleScript</title>
		<link>http://macstuff.beachdogs.org/blog/?p=262</link>
		<comments>http://macstuff.beachdogs.org/blog/?p=262#comments</comments>
		<pubDate>Thu, 14 Oct 2010 19:55:15 +0000</pubDate>
		<dc:creator>webmaster</dc:creator>
				<category><![CDATA[Applescript]]></category>
		<category><![CDATA[Management]]></category>
		<category><![CDATA[Scripts]]></category>

		<guid isPermaLink="false">http://macstuff.beachdogs.org/blog/?p=262</guid>
		<description><![CDATA[This is a fairly simple one but someone out there may need this. My boss recently had a weird problem where his disk was suddenly filling up. A reboot fixed it but we were having a hard time finding the process that was suddenly eating 15 GB of disk space with no warning. So, I [...]]]></description>
			<content:encoded><![CDATA[<p>This is a fairly simple one but someone out there may need this.  My boss recently had a weird problem where his disk was suddenly filling up.  A reboot fixed it but we were having a hard time finding the process that was suddenly eating 15 GB of disk space with no warning.  So, I came up with this script that just gets how much free space is left on his disk.  We ran it as a cron job every 15 minutes so we could hopefully get some warning before things filled up and became unusable.  The script displays a warning when the disk has 5% or less of free space.  You can edit it for your own uses.  It also has the ability to email the report to you.  Comment out the section you don&#8217;t want to use.  To have it send emails when you are not logged in use something like <a href="http://www.peterborgapps.com/lingon/">Lingon</a> for a launchd item or <a href="http://code.google.com/p/cronnix/">Cronnix</a> for a cron job.  Save your script in the appropriate location and have the launchd/cron job call it using the &#8220;osascript&#8221; command.  So, if the file was saved in the /Users/Shared folder the line would read:</p>
<p>osascript /Users/Shared/disk_check.scpt</p>
<div id="wpshdo_5" class="wp-synhighlighter-outer"><div id="wpshdt_5" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_5"></a><a id="wpshat_5" class="wp-synhighlighter-title" href="#codesyntax_5"  onClick="javascript:wpsh_toggleBlock(5)" title="Click to show/hide code block">Code block</a></td><td align="right"><a href="#codesyntax_5" onClick="javascript:wpsh_code(5)" title="Show code only"><img border="0" style="border: 0 none" src="http://macstuff.beachdogs.org/blog/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_5" onClick="javascript:wpsh_print(5)" title="Print code"><img border="0" style="border: 0 none" src="http://macstuff.beachdogs.org/blog/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="http://macstuff.beachdogs.org/blog/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img border="0" style="border: 0 none" src="http://macstuff.beachdogs.org/blog/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_5" class="wp-synhighlighter-inner" style="display: block;"><pre class="applescript" style="font-family:monospace;"><span class="kw3">set</span> mysubject <span class="kw3">to</span> <span class="st0">&quot;Disk Usage Report&quot;</span>
<span class="kw3">set</span> myrecipient <span class="kw3">to</span> <span class="st0">&quot;sysadmin@example.com&quot;</span>
<span class="co1">--get the amount of free space</span>
<span class="kw3">set</span> dSize <span class="kw3">to</span> <span class="br0">&#40;</span><span class="kw1">do shell script</span> <span class="st0">&quot;df -h / | grep %&quot;</span><span class="br0">&#41;</span> <span class="kw2">as</span> <span class="kw1">text</span>
<span class="co1">--pull out the percent used from the result</span>
<span class="kw3">set</span> theTotal <span class="kw3">to</span> word 6 <span class="kw3">in</span> dSize <span class="kw2">as</span> <span class="kw1">number</span>
<span class="co1">--if the total used space is 95% or more put up a warning. Comment out if running the email section</span>
<span class="kw3">if</span> theTotal <span class="kw3">is</span> <span class="kw2">greater</span> than <span class="kw2">or</span> <span class="kw2">equal</span> <span class="kw3">to</span> 95 <span class="kw3">then</span>
	<span class="kw1">display dialog</span> <span class="st0">&quot;Your disk is &quot;</span> <span class="sy0">&amp;</span> theTotal <span class="sy0">&amp;</span> <span class="st0">&quot;% full&quot;</span>
<span class="kw3">end</span> <span class="kw3">if</span>
<span class="co1">--comment out this section if no email is desired.</span>
<span class="kw3">set</span> mybody <span class="kw3">to</span> <span class="br0">&#40;</span><span class="st0">&quot;Free Space: &quot;</span> <span class="sy0">&amp;</span> theTotal <span class="sy0">&amp;</span> <span class="st0">&quot;%&quot;</span><span class="br0">&#41;</span>
<span class="kw1">do shell script</span> <span class="br0">&#40;</span><span class="st0">&quot;echo <span class="es0">\&quot;</span>&quot;</span> <span class="sy0">&amp;</span> mybody <span class="sy0">&amp;</span> <span class="st0">&quot;<span class="es0">\&quot;</span> | mail -s <span class="es0">\&quot;</span>&quot;</span> <span class="sy0">&amp;</span> mysubject <span class="sy0">&amp;</span> <span class="st0">&quot;<span class="es0">\&quot;</span> &quot;</span> <span class="sy0">&amp;</span> myrecipient<span class="br0">&#41;</span></pre></div></div>
<p>Click here to download a copy: <a href='http://macstuff.beachdogs.org/blog/wp-content/uploads/2010/10/disk_check.scpt_.zip'>Disk Check script</a></p>
]]></content:encoded>
			<wfw:commentRss>http://macstuff.beachdogs.org/blog/?feed=rss2&#038;p=262</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Disable Directory Listing for User Sites Folder in Macintosh OS X</title>
		<link>http://macstuff.beachdogs.org/blog/?p=247</link>
		<comments>http://macstuff.beachdogs.org/blog/?p=247#comments</comments>
		<pubDate>Thu, 08 Jul 2010 14:51:52 +0000</pubDate>
		<dc:creator>webmaster</dc:creator>
				<category><![CDATA[Management]]></category>
		<category><![CDATA[System]]></category>
		<category><![CDATA[Terminal]]></category>

		<guid isPermaLink="false">http://macstuff.beachdogs.org/blog/?p=247</guid>
		<description><![CDATA[I&#8217;ve been using the &#8220;Sites&#8221; folder in my local home directory for some web development testing recently. I had a couple of directories created that didn&#8217;t include an &#8220;index.html&#8221; file. That means that anyone hitting the directory itself could list the contents and see all the other files I was working on in there. Not [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been using the &#8220;Sites&#8221; folder in my local home directory for some web development testing recently.  I had a couple of directories created that didn&#8217;t include an &#8220;index.html&#8221; file.  That means that anyone hitting the directory itself could list the contents and see all the other files I was working on in there.  Not a major problem for what I was doing but a security issue none the less.  After a quick bit of research I found it was quite easy to disable this at the command line.</p>
<p>Open Terminal and type <code>cd /private/etc/apache2/users</code>.  Inside the &#8220;users&#8221; folder will be conf files for each of the users with accounts on the machine. So, if we have a user with the short name of &#8220;joe&#8221; on the machine there will be a file in there named &#8220;joe.conf&#8221;.</p>
<p>To edit this file you need to have root permissions.  So open it using <code>sudo</code>.  I prefer using <code>pico</code> as my editor but use whichever works for you.  The command below assumes you are already in the &#8220;users&#8221; folder.</p>
<p><code>sudo pico joe.conf</code></p>
<p>You&#8217;ll see something like this:<br />
<code><directory "/Users/joe/Sites/"><br />
Options Indexes MultiViews<br />
AllowOverride None<br />
Order allow,deny<br />
Allow from all<br />
</directory><br />
</code></p>
<p>Navigate down to the line <code>Options Indexes MultiViews</code>.  Carefully delete the <code>Indexes</code> part of the line and save the file.  Now restart Apache, either by going to System Preferences and turning off and then back on Web Sharing, or at the command line by typing <code>sudo apachectl restart</code>.</p>
<p>Now navigate to a directory in your &#8220;Sites&#8221; folder that doesn&#8217;t have an index file.  You should get a &#8220;403 No permissions&#8221; error unless you specify a file.  Much more secure.  Note that you&#8217;ll need to do this individually for each account on the machine.  </p>
<p>I&#8217;ve tested this with Snow Leopard and I&#8217;m betting it will work with Leopard.  I&#8217;m not sure if versions of the OS below 10.5 support this feature.</p>
]]></content:encoded>
			<wfw:commentRss>http://macstuff.beachdogs.org/blog/?feed=rss2&#038;p=247</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Backing up MySQL databases on an OS X Server</title>
		<link>http://macstuff.beachdogs.org/blog/?p=184</link>
		<comments>http://macstuff.beachdogs.org/blog/?p=184#comments</comments>
		<pubDate>Mon, 14 Dec 2009 17:31:51 +0000</pubDate>
		<dc:creator>webmaster</dc:creator>
				<category><![CDATA[Scripts]]></category>
		<category><![CDATA[Server]]></category>
		<category><![CDATA[System]]></category>
		<category><![CDATA[Terminal]]></category>

		<guid isPermaLink="false">http://macstuff.beachdogs.org/blog/?p=184</guid>
		<description><![CDATA[I recently started using the build-in MySQL database server on my Leopard server. I&#8217;m collecting user login data in one database and SMB and AFP login information in another. Nothing major but information I wouldn&#8217;t really want to lose. I was looking for an easy way to backup these databases when a post on the [...]]]></description>
			<content:encoded><![CDATA[<p>I recently started using the build-in MySQL database server on my Leopard server.  I&#8217;m collecting user login data in one database and SMB and AFP login information in another.  Nothing major but information I wouldn&#8217;t really want to lose.  I was looking for an easy way to backup these databases when a post on the <a href="http://www.macenterprise.org" target="_blank">MacEnterprise</a> mailing list asked the same thing.  Several people suggested <a href="http://sourceforge.net/projects/automysqlbackup/" target="_blank">AutoMySQLBackup</a>, an open source shell script.  After checking into it I can say it is an incredibly easy way of backing up all your data.  The author has done a great service by posting this script.</p>
<p>The script backups up the databases to the local drive but can also email the backups to you.  I wanted them emailed so I could archive them and have them backed up there as well.  That way I don&#8217;t have to come up with any other scripts to move the backups some where else.</p>
<p>The AutoMySQLBackup script requires that you have <a href="http://www.mutt.org/" target="_blank">Mutt</a> installed if you want to have it email anything.  Mutt is an command line email program that does not come pre-installed on OS X.  Here are the steps I went through to get everything up and running.</p>
<p><strong>Step 1 &#8211; Install Mutt</strong></p>
<p>There are instructions on the Mutt website for installing the program but I wanted something I could easily update without a lot of hassle.  I decided to install using <a href="http://www.macports.org" target="_blank">MacPorts</a>.  </p>
<p>Download and install the latest version of MacPorts.  There is excellent documentation on the web page.  You&#8217;ll need the Apple Developer&#8217;s Tools installed before installing MacPorts.  If you don&#8217;t already have them you can install them from your OS X install disc or download them from the <a href="http://developer.apple.com/" target="_blank">Apple Developer Connection </a>site.</p>
<p>Once MacPorts is installed an running you&#8217;re ready to install Mutt.  At the time of this writing the default version of Mutt in the MacPorts repository is 1.4.2.  I wanted the 1.5.x version as I had read that it was much easier to configure.  Check the MacPorts list of available ports before you install.  To get the 1.5.x version I had to install the development version.</p>
<p>In Terminal type the following:</p>
<p><code>sudo port install mutt-devel +smtp +ssl +imap +pop</code></p>
<p>If you want the standard install of mutt enter this:</p>
<p><code>sudo port install mutt +smtp +ssl +imap +pop</code></p>
<p>Then go do something else for a while as it downloads and compiles everything.  After a bit you&#8217;ll have an install of mutt.</p>
<p><strong>Step 2 &#8211; Configure Mutt</strong></p>
<p>With the 1.5.x version of Mutt I only had to make one configuration file.  In the home directory root of the account you are running the script from make a &#8220;.muttrc&#8221; file.</p>
<p><code>touch .muttrc</code></p>
<p>Now, use your favorite editor (I prefer pico) and add the address of the SMTP server you plan to use:</p>
<p><code>set smtp_url="smtp://my.smtp.server.com"</code></p>
<p>Now try sending an email from Mutt in Terminal and make sure everything is working correctly.</p>
<p><strong>Step 3 &#8211; Configuring AutoMySQLBackup</strong></p>
<p>Download <a href="http://sourceforge.net/projects/automysqlbackup/">AutoMySQLBackup</a> and put it where ever you put your scripts.  I changed the permission so that only the account I was running it from had any access.</p>
<p><code> chmod 700 automysqlbackup.sh</code></p>
<p>Open the script in your editor of choice.  Don&#8217;t use Word or other such editors as they will mess up your line returns. Use a command-line editor or a GUI editor like <a href="http://www.codingmonkeys.de/subethaedit/" target="_blank">SubEthaEdit</a> that understands UNIX line returns.</p>
<p>The script author has great instructions right in the script so I won&#8217;t cover those here.  I did, however, have to make two changes to the script to get things to work.</p>
<p>First, I had to add in the path to the MacPorts installation in the path variable for the script.  That was on line 338.</p>
<p>The original reads:</p>
<p><code>PATH=/usr/local/bin:/usr/bin:/bin:/usr/local/mysql/bin</code></p>
<p>Edit it to look like this:</p>
<p><code>PATH=/opt/local/bin:/opt/local/sbin:/usr/local/bin:/usr/bin:/bin:/usr/local/mysql/bin</code></p>
<p>Remember, all the MacPorts installations live in /opt/local.  Now the script can find Mutt.</p>
<p>The second change I had to make was to the order of items that the script was sending to Mutt.  It just didn&#8217;t work in 1.5.x as written.  This is on line 644 of the script.</p>
<p>The original reads:</p>
<p><code>mutt -s "$ERRORNOTE MySQL Backup Log and SQL Files for $HOST - $DATE" $BACKUPFILES $MAILADDR < $LOGFILE</code>	</p>
<p>I had to switch the order of $BACKUPFILES and $MAILADDR to get it send the file to me.  So my edited version looks like this:</p>
<p></code><code>mutt -s "$ERRORNOTE MySQL Backup Log and SQL Files for $HOST - $DATE" $MAILADDR $BACKUPFILES   < $LOGFILE</code></p>
<p>After making that switch and running the script it backed up my databases and emailed me the backup files as well.  Fantastic!</p>
<p>Schedule your script to run on a nightly basis so you get regular backups of everything.  You can either do that via </code><code>cron</code> or via a <code>launchd</code> item.  If you want to use <code>cron</code> and don&#8217;t want to do it at the command line I recommend <a href="http://www.versiontracker.com/dyn/moreinfo/macosx/9478" target="_blank">Cronnix</a>.  For <code>launchd</code> I recommend <a href="http://sourceforge.net/projects/lingon/" target="_blank">Lingon</a></p>
<p>One last note.  When I was trying to troubleshoot why the attachments weren&#8217;t being send I couldn&#8217;t find the log files that said what was happening.  That&#8217;s because the automysqlbackup script puts them in the script and then deletes them along with everything else after it mails them.  To disable that function I had to comment out these two lines at the very end of the script:<br />
<code><br />
eval rm -f "$LOGFILE"<br />
eval rm -f "$LOGERR"<br />
</code></p>
<p>Once I had things working I uncommented them so things would continue to be cleaned up.</p>
]]></content:encoded>
			<wfw:commentRss>http://macstuff.beachdogs.org/blog/?feed=rss2&#038;p=184</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Getting user login data from Macs using AppleScript</title>
		<link>http://macstuff.beachdogs.org/blog/?p=141</link>
		<comments>http://macstuff.beachdogs.org/blog/?p=141#comments</comments>
		<pubDate>Thu, 10 Sep 2009 14:13:37 +0000</pubDate>
		<dc:creator>webmaster</dc:creator>
				<category><![CDATA[Applescript]]></category>
		<category><![CDATA[Management]]></category>
		<category><![CDATA[Scripts]]></category>

		<guid isPermaLink="false">http://macstuff.beachdogs.org/blog/?p=141</guid>
		<description><![CDATA[A lab we work with recently upgraded to 10.5 and found that the program they were running to get the user login data for their billing wouldn&#8217;t work in 10.5 and wasn&#8217;t going to be upgrading. In looking at the data it was grabbing it was clear the same data could be gotten using the [...]]]></description>
			<content:encoded><![CDATA[<p>A lab we work with recently upgraded to 10.5 and found that the program they were running to get the user login data for their billing wouldn&#8217;t work in 10.5 and wasn&#8217;t going to be upgrading.  In looking at the data it was grabbing it was clear the same data could be gotten using the <code>last</code> command in Terminal. You can see more about <code>last</code> at my post <a href="http://macstuff.beachdogs.org/blog/?p=19">here</a>. However, these folks were not computer-savvy and needed the information in a comma-delimited file.  So, I came up with this script.</p>
<p>When you run the script it asks you which month you want the data for in a list.  Select the month and it will generate a file on the desktop with that months data.  You can save it out as an application, run it from Script Editor or run it as a launchd/cron job.  You can customize the output by changing the line that begins with &#8220;write&#8221;.   For example, replace the &#8220;,&#8221; with <code>tab</code> and create a tab-delimited file instead.  </p>
<p>If you run this script logged in as a regular user you will only get the login information for that user.  If you run it as an administrator you&#8217;ll get the login information for every account on the machine.</p>
<p>Click here to download the script file:<br />
<a href='http://macstuff.beachdogs.org/blog/wp-content/uploads/2009/09/Monthly-Login-accounting.scpt.zip'>Monthly Login accounting</a></p>
<div id="wpshdo_6" class="wp-synhighlighter-outer"><div id="wpshdt_6" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_6"></a><a id="wpshat_6" class="wp-synhighlighter-title" href="#codesyntax_6"  onClick="javascript:wpsh_toggleBlock(6)" title="Click to show/hide code block">Code block</a></td><td align="right"><a href="#codesyntax_6" onClick="javascript:wpsh_code(6)" title="Show code only"><img border="0" style="border: 0 none" src="http://macstuff.beachdogs.org/blog/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_6" onClick="javascript:wpsh_print(6)" title="Print code"><img border="0" style="border: 0 none" src="http://macstuff.beachdogs.org/blog/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="http://macstuff.beachdogs.org/blog/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img border="0" style="border: 0 none" src="http://macstuff.beachdogs.org/blog/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_6" class="wp-synhighlighter-inner" style="display: block;"><pre class="applescript" style="font-family:monospace;"><span class="kw3">set</span> the_months <span class="kw3">to</span> <span class="br0">&#123;</span><span class="br0">&#125;</span>
<span class="kw3">set</span> the_total <span class="kw3">to</span> 0
<span class="kw3">set</span> the_time <span class="kw3">to</span> <span class="st0">&quot;&quot;</span>
<span class="kw3">set</span> the_computer <span class="kw3">to</span> <span class="br0">&#40;</span>computer <span class="kw1">name</span> <span class="kw3">of</span> <span class="br0">&#40;</span>system info<span class="br0">&#41;</span><span class="br0">&#41;</span>
<span class="co1">--get the raw login log information</span>
<span class="kw3">set</span> the_login <span class="kw3">to</span> <span class="br0">&#40;</span><span class="kw1">do shell script</span> <span class="st0">&quot;last&quot;</span><span class="br0">&#41;</span> <span class="kw2">as</span> <span class="kw1">text</span>
<span class="kw3">set</span> the_count <span class="kw3">to</span> <span class="kw2">the</span> <span class="kw1">count</span> <span class="kw3">of</span> <span class="kw1">paragraphs</span> <span class="kw3">of</span> the_login
<span class="co1">--get the list of all the months login data is available for</span>
<span class="kw3">repeat</span> <span class="kw3">with</span> x <span class="kw3">from</span> 1 <span class="kw3">to</span> the_count
	<span class="kw3">if</span> <span class="kw1">paragraph</span> x <span class="kw3">of</span> the_login <span class="kw2">contains</span> <span class="st0">&quot;console&quot;</span> <span class="kw3">then</span>
		<span class="kw3">set</span> month_check <span class="kw3">to</span> <span class="br0">&#40;</span>word 4 <span class="kw3">of</span> <span class="kw1">paragraph</span> x <span class="kw3">of</span> the_login<span class="br0">&#41;</span> <span class="kw2">as</span> <span class="kw1">text</span>
		<span class="kw3">if</span> the_months does <span class="kw2">not</span> contain month_check <span class="kw3">then</span>
			<span class="kw3">set</span> <span class="kw3">end</span> <span class="kw3">of</span> the_months <span class="kw3">to</span> month_check
		<span class="kw3">end</span> <span class="kw3">if</span>
	<span class="kw3">end</span> <span class="kw3">if</span>
<span class="kw3">end</span> <span class="kw3">repeat</span>
<span class="kw3">set</span> selected_month <span class="kw3">to</span> <span class="kw1">choose <span class="kw3">from</span> list</span> the_months <span class="kw3">with</span> prompt <span class="st0">&quot;Select the month:&quot;</span>
<span class="co1">--create the file to write data to</span>
<span class="kw3">if</span> selected_month <span class="kw3">is</span> <span class="kw2">not</span> <span class="kw1">false</span> <span class="kw3">then</span>
	<span class="kw3">tell</span> <span class="kw1">application</span> <span class="st0">&quot;Finder&quot;</span>
		<span class="kw3">set</span> file_name <span class="kw3">to</span> <span class="br0">&#40;</span>the_computer <span class="sy0">&amp;</span> <span class="st0">&quot;-&quot;</span> <span class="sy0">&amp;</span> selected_month <span class="sy0">&amp;</span> <span class="st0">&quot;-&quot;</span> <span class="sy0">&amp;</span> <span class="br0">&#40;</span>year <span class="kw3">of</span> <span class="br0">&#40;</span>current date<span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="sy0">&amp;</span> <span class="st0">&quot; login stats.txt&quot;</span><span class="br0">&#41;</span>
		<span class="kw3">if</span> <span class="kw2">not</span> <span class="br0">&#40;</span><span class="kw1">exists</span> <span class="kw1">file</span> <span class="br0">&#40;</span><span class="br0">&#40;</span><span class="br0">&#40;</span><span class="kw1">path to</span> <span class="kw1">desktop</span> <span class="kw3">from</span> user domain <span class="kw2">as</span> <span class="kw1">text</span><span class="br0">&#41;</span> <span class="sy0">&amp;</span> file_name<span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="kw3">then</span>
			<span class="kw3">set</span> login_file <span class="kw3">to</span> <span class="kw1">make</span> <span class="kw1">file</span> <span class="kw3">with</span> <span class="kw1">properties</span> <span class="br0">&#123;</span><span class="kw1">name</span>:file_name, <span class="kw1">file</span> type:<span class="st0">&quot;TEXT&quot;</span><span class="br0">&#125;</span> at <span class="br0">&#40;</span><span class="kw1">path to</span> <span class="kw1">desktop</span> <span class="kw3">from</span> user domain<span class="br0">&#41;</span>
		<span class="kw3">else</span>
			<span class="kw1">display dialog</span> <span class="st0">&quot;This stats file already exists.  Do you want to overwrite it?&quot;</span> <span class="kw1">buttons</span> <span class="br0">&#123;</span><span class="st0">&quot;Yes&quot;</span>, <span class="st0">&quot;No&quot;</span><span class="br0">&#125;</span> default button 2
			<span class="kw3">set</span> the_answer <span class="kw3">to</span> <span class="kw2">the</span> button returned <span class="kw3">of</span> <span class="kw2">the</span> <span class="kw1">result</span>
			<span class="kw3">if</span> the_answer <span class="kw3">is</span> <span class="st0">&quot;Yes&quot;</span> <span class="kw3">then</span>
				<span class="kw1">delete</span> <span class="kw1">file</span> <span class="br0">&#40;</span><span class="br0">&#40;</span><span class="kw1">path to</span> <span class="kw1">desktop</span> <span class="kw3">from</span> user domain <span class="kw2">as</span> <span class="kw1">text</span><span class="br0">&#41;</span> <span class="sy0">&amp;</span> file_name<span class="br0">&#41;</span>
				<span class="kw3">set</span> login_file <span class="kw3">to</span> <span class="kw1">make</span> <span class="kw1">file</span> <span class="kw3">with</span> <span class="kw1">properties</span> <span class="br0">&#123;</span><span class="kw1">name</span>:file_name, <span class="kw1">file</span> type:<span class="st0">&quot;TEXT&quot;</span><span class="br0">&#125;</span> at <span class="br0">&#40;</span><span class="kw1">path to</span> <span class="kw1">desktop</span> <span class="kw3">from</span> user domain<span class="br0">&#41;</span>
			<span class="kw3">end</span> <span class="kw3">if</span>
		<span class="kw3">end</span> <span class="kw3">if</span>
	<span class="kw3">end</span> <span class="kw3">tell</span>
	<span class="kw3">set</span> login_file <span class="kw3">to</span> <span class="br0">&#40;</span><span class="br0">&#40;</span><span class="kw1">path to</span> <span class="kw1">desktop</span> <span class="kw3">from</span> user domain<span class="br0">&#41;</span> <span class="sy0">&amp;</span> file_name<span class="br0">&#41;</span> <span class="kw2">as</span> <span class="kw1">text</span>
<span class="kw3">end</span> <span class="kw3">if</span>
<span class="co1">--loop through the data and pull out the logins for the selected month</span>
<span class="kw3">repeat</span> <span class="kw3">with</span> x <span class="kw3">from</span> 1 <span class="kw3">to</span> the_count
	<span class="kw3">if</span> <span class="kw1">paragraph</span> x <span class="kw3">of</span> the_login <span class="kw2">contains</span> selected_month <span class="kw3">then</span>
		<span class="kw3">if</span> <span class="kw1">paragraph</span> x <span class="kw3">of</span> the_login <span class="kw2">contains</span> <span class="st0">&quot;console&quot;</span> <span class="kw3">then</span>
			<span class="kw3">set</span> the_user <span class="kw3">to</span> <span class="br0">&#40;</span>word 1 <span class="kw3">of</span> <span class="kw1">paragraph</span> x <span class="kw3">of</span> the_login<span class="br0">&#41;</span>
			<span class="kw3">set</span> the_month <span class="kw3">to</span> <span class="br0">&#40;</span>word 4 <span class="kw3">of</span> <span class="kw1">paragraph</span> x <span class="kw3">of</span> the_login<span class="br0">&#41;</span> <span class="kw2">as</span> <span class="kw1">text</span>
			<span class="kw3">set</span> the_logmonth <span class="kw3">to</span> MonthNumber<span class="br0">&#40;</span>the_month<span class="br0">&#41;</span>
			<span class="kw3">set</span> the_day <span class="kw3">to</span> <span class="br0">&#40;</span>word 5 <span class="kw3">of</span> <span class="kw1">paragraph</span> x <span class="kw3">of</span> the_login<span class="br0">&#41;</span> <span class="kw2">as</span> <span class="kw1">text</span>
			<span class="kw3">if</span> <span class="br0">&#40;</span><span class="kw2">the</span> <span class="br0">&#40;</span><span class="kw1">count</span> <span class="kw3">of</span> characters <span class="kw3">of</span> the_day<span class="br0">&#41;</span> <span class="kw3">is</span> <span class="kw2">less</span> than 2<span class="br0">&#41;</span> <span class="kw3">then</span>
				<span class="kw3">set</span> the_day <span class="kw3">to</span> <span class="br0">&#40;</span><span class="st0">&quot;0&quot;</span> <span class="sy0">&amp;</span> the_day<span class="br0">&#41;</span>
			<span class="kw3">end</span> <span class="kw3">if</span>
			<span class="kw3">set</span> the_year <span class="kw3">to</span> yearCheck<span class="br0">&#40;</span>selected_month, the_months<span class="br0">&#41;</span>
			<span class="kw3">set</span> log_date <span class="kw3">to</span> <span class="br0">&#40;</span>the_logmonth <span class="sy0">&amp;</span> <span class="st0">&quot;/&quot;</span> <span class="sy0">&amp;</span> the_day <span class="sy0">&amp;</span> <span class="st0">&quot;/&quot;</span> <span class="sy0">&amp;</span> the_year<span class="br0">&#41;</span>
			<span class="kw3">set</span> login_time <span class="kw3">to</span> <span class="br0">&#40;</span>word 6 <span class="kw3">of</span> <span class="kw1">paragraph</span> x <span class="kw3">of</span> the_login <span class="sy0">&amp;</span> <span class="st0">&quot;:&quot;</span> <span class="sy0">&amp;</span> word 7 <span class="kw3">of</span> <span class="kw1">paragraph</span> x <span class="kw3">of</span> the_login<span class="br0">&#41;</span>
			<span class="kw3">set</span> logout_time <span class="kw3">to</span> <span class="br0">&#40;</span>word 8 <span class="kw3">of</span> <span class="kw1">paragraph</span> x <span class="kw3">of</span> the_login <span class="sy0">&amp;</span> <span class="st0">&quot;:&quot;</span> <span class="sy0">&amp;</span> word 9 <span class="kw3">of</span> <span class="kw1">paragraph</span> x <span class="kw3">of</span> the_login<span class="br0">&#41;</span>
			<span class="kw3">set</span> old_delims <span class="kw3">to</span> AppleScript<span class="co2">'</span>s <span class="kw1">text</span> <span class="kw1">item</span> <span class="kw1">delimiters</span>
			<span class="kw3">set</span> AppleScript<span class="co2">'</span>s <span class="kw1">text</span> <span class="kw1">item</span> <span class="kw1">delimiters</span> <span class="kw3">to</span> <span class="st0">&quot;(&quot;</span>
			<span class="kw3">try</span>
				<span class="kw3">set</span> the_time1 <span class="kw3">to</span> <span class="kw1">text</span> <span class="kw1">item</span> 2 <span class="kw3">of</span> <span class="kw1">paragraph</span> x <span class="kw3">of</span> the_login
				<span class="kw3">set</span> AppleScript<span class="co2">'</span>s <span class="kw1">text</span> <span class="kw1">item</span> <span class="kw1">delimiters</span> <span class="kw3">to</span> old_delims
				<span class="kw3">set</span> the_time <span class="kw3">to</span> <span class="br0">&#40;</span>characters 1 <span class="kw2">through</span> 5 <span class="kw3">of</span> the_time1<span class="br0">&#41;</span> <span class="kw2">as</span> <span class="kw1">text</span>
			<span class="kw3">on</span> <span class="kw3">error</span>
				<span class="kw3">set</span> AppleScript<span class="co2">'</span>s <span class="kw1">text</span> <span class="kw1">item</span> <span class="kw1">delimiters</span> <span class="kw3">to</span> old_delims
			<span class="kw3">end</span> <span class="kw3">try</span>
			<span class="co1">--write all the date to the file</span>
			write <span class="br0">&#40;</span>the_user <span class="sy0">&amp;</span> <span class="st0">&quot;,&quot;</span> <span class="sy0">&amp;</span> the_computer <span class="sy0">&amp;</span> <span class="st0">&quot;,&quot;</span> <span class="sy0">&amp;</span> log_date <span class="sy0">&amp;</span> <span class="st0">&quot;,&quot;</span> <span class="sy0">&amp;</span> login_time <span class="sy0">&amp;</span> <span class="st0">&quot;,&quot;</span> <span class="sy0">&amp;</span> log_date <span class="sy0">&amp;</span> <span class="st0">&quot;,&quot;</span> <span class="sy0">&amp;</span> logout_time <span class="sy0">&amp;</span> <span class="st0">&quot;,&quot;</span> <span class="sy0">&amp;</span> the_time <span class="sy0">&amp;</span> <span class="kw3">return</span><span class="br0">&#41;</span> <span class="kw3">to</span> <span class="kw1">file</span> login_file starting at eof
		<span class="kw3">end</span> <span class="kw3">if</span>
	<span class="kw3">end</span> <span class="kw3">if</span>
<span class="kw3">end</span> <span class="kw3">repeat</span>
<span class="co1">--if the list contains January see if the selected month comes before or after January.  Adjust the year accordingly.</span>
<span class="kw3">on</span> yearCheck<span class="br0">&#40;</span>selected_month, the_months<span class="br0">&#41;</span>
	<span class="kw3">if</span> the_months <span class="kw2">contains</span> <span class="st0">&quot;Jan&quot;</span> <span class="kw3">then</span>
		<span class="kw3">repeat</span> <span class="kw3">with</span> x <span class="kw3">from</span> 1 <span class="kw3">to</span> <span class="kw1">count</span> <span class="kw3">of</span> the_months
			<span class="kw3">if</span> <span class="kw1">item</span> x <span class="kw3">of</span> the_list <span class="kw2">contains</span> selected_month <span class="kw3">then</span>
				<span class="kw3">set</span> the_num <span class="kw3">to</span> x
			<span class="kw3">else</span>
				<span class="kw3">if</span> <span class="kw1">item</span> x <span class="kw3">of</span> the_list <span class="kw2">contains</span> <span class="st0">&quot;Jan&quot;</span> <span class="kw3">then</span>
					<span class="kw3">set</span> jan_num <span class="kw3">to</span> x
				<span class="kw3">end</span> <span class="kw3">if</span>
			<span class="kw3">end</span> <span class="kw3">if</span>
		<span class="kw3">end</span> <span class="kw3">repeat</span>
		<span class="kw3">set</span> year_check <span class="kw3">to</span> <span class="br0">&#40;</span>the_num <span class="sy0">-</span> jan_num<span class="br0">&#41;</span>
		<span class="kw3">if</span> year_check <span class="kw3">is</span> <span class="kw2">greater</span> than 0 <span class="kw3">then</span>
			<span class="kw3">set</span> the_year <span class="kw3">to</span> <span class="br0">&#40;</span><span class="br0">&#40;</span>year <span class="kw3">of</span> <span class="br0">&#40;</span>current date<span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="sy0">-</span> 1<span class="br0">&#41;</span>
		<span class="kw3">else</span>
			<span class="kw3">set</span> the_year <span class="kw3">to</span> <span class="br0">&#40;</span>year <span class="kw3">of</span> <span class="br0">&#40;</span>current date<span class="br0">&#41;</span><span class="br0">&#41;</span>
		<span class="kw3">end</span> <span class="kw3">if</span>
	<span class="kw3">else</span>
		<span class="kw3">set</span> the_year <span class="kw3">to</span> <span class="br0">&#40;</span>year <span class="kw3">of</span> <span class="br0">&#40;</span>current date<span class="br0">&#41;</span><span class="br0">&#41;</span>
	<span class="kw3">end</span> <span class="kw3">if</span>
	<span class="kw3">return</span> the_year
<span class="kw3">end</span> yearCheck
<span class="kw3">on</span> MonthNumber<span class="br0">&#40;</span>the_month<span class="br0">&#41;</span>
	<span class="kw3">if</span> the_month <span class="sy0">=</span> <span class="st0">&quot;Jan&quot;</span> <span class="kw3">then</span>
		<span class="kw3">set</span> the_month <span class="kw3">to</span> <span class="st0">&quot;01&quot;</span>
	<span class="kw3">else</span>
		<span class="kw3">if</span> the_month <span class="sy0">=</span> <span class="st0">&quot;Feb&quot;</span> <span class="kw3">then</span>
			<span class="kw3">set</span> the_month <span class="kw3">to</span> <span class="st0">&quot;02&quot;</span>
		<span class="kw3">else</span>
			<span class="kw3">if</span> the_month <span class="sy0">=</span> <span class="st0">&quot;Mar&quot;</span> <span class="kw3">then</span>
				<span class="kw3">set</span> the_month <span class="kw3">to</span> <span class="st0">&quot;03&quot;</span>
			<span class="kw3">else</span>
				<span class="kw3">if</span> the_month <span class="sy0">=</span> <span class="st0">&quot;Apr&quot;</span> <span class="kw3">then</span>
					<span class="kw3">set</span> the_month <span class="kw3">to</span> <span class="st0">&quot;04&quot;</span>
				<span class="kw3">else</span>
					<span class="kw3">if</span> the_month <span class="sy0">=</span> <span class="st0">&quot;May&quot;</span> <span class="kw3">then</span>
						<span class="kw3">set</span> the_month <span class="kw3">to</span> <span class="st0">&quot;05&quot;</span>
					<span class="kw3">else</span>
						<span class="kw3">if</span> the_month <span class="sy0">=</span> <span class="st0">&quot;Jun&quot;</span> <span class="kw3">then</span>
							<span class="kw3">set</span> the_month <span class="kw3">to</span> <span class="st0">&quot;06&quot;</span>
						<span class="kw3">else</span>
							<span class="kw3">if</span> the_month <span class="sy0">=</span> <span class="st0">&quot;Jul&quot;</span> <span class="kw3">then</span>
								<span class="kw3">set</span> the_month <span class="kw3">to</span> <span class="st0">&quot;07&quot;</span>
							<span class="kw3">else</span>
								<span class="kw3">if</span> the_month <span class="sy0">=</span> <span class="st0">&quot;Aug&quot;</span> <span class="kw3">then</span>
									<span class="kw3">set</span> the_month <span class="kw3">to</span> <span class="st0">&quot;08&quot;</span>
								<span class="kw3">else</span>
									<span class="kw3">if</span> the_month <span class="sy0">=</span> <span class="st0">&quot;Sep&quot;</span> <span class="kw3">then</span>
										<span class="kw3">set</span> the_month <span class="kw3">to</span> <span class="st0">&quot;09&quot;</span>
									<span class="kw3">else</span>
										<span class="kw3">if</span> the_month <span class="sy0">=</span> <span class="st0">&quot;Oct&quot;</span> <span class="kw3">then</span>
											<span class="kw3">set</span> the_month <span class="kw3">to</span> <span class="st0">&quot;10&quot;</span>
										<span class="kw3">else</span>
											<span class="kw3">if</span> the_month <span class="sy0">=</span> <span class="st0">&quot;Nov&quot;</span> <span class="kw3">then</span>
												<span class="kw3">set</span> the_month <span class="kw3">to</span> <span class="st0">&quot;11&quot;</span>
											<span class="kw3">else</span>
												<span class="kw3">if</span> the_month <span class="sy0">=</span> <span class="st0">&quot;Dec&quot;</span> <span class="kw3">then</span>
													<span class="kw3">set</span> the_month <span class="kw3">to</span> <span class="st0">&quot;12&quot;</span>
												<span class="kw3">end</span> <span class="kw3">if</span>
											<span class="kw3">end</span> <span class="kw3">if</span>
										<span class="kw3">end</span> <span class="kw3">if</span>
									<span class="kw3">end</span> <span class="kw3">if</span>
								<span class="kw3">end</span> <span class="kw3">if</span>
							<span class="kw3">end</span> <span class="kw3">if</span>
						<span class="kw3">end</span> <span class="kw3">if</span>
					<span class="kw3">end</span> <span class="kw3">if</span>
				<span class="kw3">end</span> <span class="kw3">if</span>
			<span class="kw3">end</span> <span class="kw3">if</span>
		<span class="kw3">end</span> <span class="kw3">if</span>
	<span class="kw3">end</span> <span class="kw3">if</span>
	<span class="kw3">return</span> the_month <span class="kw2">as</span> <span class="kw1">string</span>
<span class="kw3">end</span> MonthNumber</pre></div></div>
]]></content:encoded>
			<wfw:commentRss>http://macstuff.beachdogs.org/blog/?feed=rss2&#038;p=141</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

