<?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/"
	xmlns:series="http://unfoldingneurons.com/"
	>

<channel>
	<title>Voodoo Programming &#187; OS X</title>
	<atom:link href="http://www.cneophytou.com/category/os-x/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.cneophytou.com</link>
	<description>Things programmers do that they know shouldn&#039;t work but they try anyway, and which sometimes actually work, such as recompiling everything.</description>
	<lastBuildDate>Tue, 20 Oct 2009 13:54:02 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=abc</generator>
		<item>
		<title>Photo feed as Desktop Background</title>
		<link>http://www.cneophytou.com/2008/04/17/photo-feed-as-desktop-background/</link>
		<comments>http://www.cneophytou.com/2008/04/17/photo-feed-as-desktop-background/#comments</comments>
		<pubDate>Thu, 17 Apr 2008 15:14:57 +0000</pubDate>
		<dc:creator>Constantinos</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Google]]></category>
		<category><![CDATA[OS X]]></category>
		<category><![CDATA[CC Licence]]></category>
		<category><![CDATA[Chromasia]]></category>
		<category><![CDATA[ddoi]]></category>
		<category><![CDATA[Feed]]></category>
		<category><![CDATA[Google Apps]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[RSS]]></category>

		<guid isPermaLink="false">http://www.cneophytou.com/?p=110</guid>
		<description><![CDATA[I first came up with this idea after reading a post on HackerMoJo.com about getting an RSS feed of images as a Screen Saver using a python script. The idea is simple: Take a feed, parse it, and save the photos it links to as numbered images in a folder on the disk, then use [...]]]></description>
			<content:encoded><![CDATA[I first came up with this idea after reading a post on <a href="http://hackermojo.com/mt-static/archives/2008/04/metropulse-launched.html">HackerMoJo.com</a> about getting an RSS feed of images as a Screen Saver using a python script. The idea is simple: Take a feed, parse it, and save the photos it links to as numbered images in a folder on the disk, then use that folder as a Screen Saver. Well, as it turns out you can also use that folder as a desktop background, but there are a few improvements that can be made.<br />
<br />
First, the script only worked with that particular feed. If you wanted to use a different feed, you would have to change the code. Second, the script would always download all the photos linked to from the feed, thus increasing the load placed on the hosting server. I wanted to use the script to download the photos from <a href="http://www.chromasia.com/iblog">Chromasia</a>, which brings me to point number three: some feeds don't link to the large photo, but instead only include a thumbnail. To solve these issues, I created a small application using Google's wonderful <a href="http://code.google.com/appengine/">App Engine</a>, which takes care of everything. More on how to use this after the jump.<br />
<span id="more-110"></span>
<br />
This application takes care of keeping a database of the most recent photos linked to from the provided feeds, thus balancing the load placed on the hosting servers, and also allowing me to serve the feeds in a single standardised format. So far, the script supports the feeds of David Nightingale's <a href="http://www.chromasia.com/iblog">Chromasia</a> who kindly agreed to let me download web-scaled versions of his photos for use with this script and also helped me test early versions of the app, and Sam Javanrouh's <a href="http://wvs.topleftpixel.com/">daily dose of imagery</a>.<br />
<br />
There are several ways to use these feeds. The easiest way is through iPhoto 6 or 7. Just subscribe to the iPhoto photo feed for either chromasia (<a href="http://deskfeed.neophytou.net/feed/chromasia">http://deskfeed.neophytou.net/feed/chromasia</a>) or daily dose of imagery (<a href="http://deskfeed.neophytou.net/feed/ddoi">http://deskfeed.neophytou.net/feed/ddoi</a>). There are three down sides to using this method: You have to open iPhoto every day to refresh the feeds manually, every time iPhoto refreshes it has to download all the photos over again, and you can only use the photos from a single feed, not multiple ones. Also in Tiger, I believe you can only use an iPhoto photo feed as a Screen Saver, not as a Desktop Background.<br />
<br />
The other way to use this application, is through a small Python script which I wrote. To use this, you need to create a folder called DeskFeed inside the Pictures folder located in your Home directory (resulting path: ~/Pictures/DeskFeed, where ~/ is your home directory). Then, <a href='http://www.cneophytou.com/wp-content/uploads/2008/04/deskfeed.py'>download this script</a> into the folder you just created, and run the following commands in the Terminal (found under <code>Applications/Utilities/Terminal</code>):</p>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">chmod</span> a+x ~<span style="color: #000000; font-weight: bold;">/</span>Pictures<span style="color: #000000; font-weight: bold;">/</span>DeskFeed<span style="color: #000000; font-weight: bold;">/</span>deskfeed.py
~<span style="color: #000000; font-weight: bold;">/</span>Pictures<span style="color: #000000; font-weight: bold;">/</span>DeskFeed<span style="color: #000000; font-weight: bold;">/</span>deskfeed.py</pre></div></div>



<p>
This will automatically download the latest photos from the Chromasia and daily dose of imagery blogs, and save them in the DeskFeed folder. To modify which feeds are downloaded (or not), open the deskfeed.py file you just downloaded and comment out / uncomment the photo feeds you want on the first few lines that are clearly marked. You can have as many feeds as you want in the script, but they have to be generated from the App Engine script which I wrote.<br />
<br />
To set this up as a periodic task using <code>cron</code>, create a text file on your desktop called <code>dfcron</code>, and in it place this single line:</p>


<div class="wp_syntax"><div class="code"><pre class="cron" style="font-family:monospace;">5      1       *       *       *       /Users/username/Pictures/DeskFeed/deskfeed.py</pre></div></div>



<p>
Make sure you replace <code>username</code> with your own short username. What this file contains is a command that will tell <code>cron</code> to run the <code>deskfeed.py</code> file every day at 5 minutes past 1am. Then, run this command in the terminal once:</p>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">crontab ~<span style="color: #000000; font-weight: bold;">/</span>Desktop<span style="color: #000000; font-weight: bold;">/</span>dfcron</pre></div></div>



<p>
You can now safely delete dfcron. To set this folder as your desktop background, go to System Preferences / Desktop &amp; Screen Saver, press the little '+' button under the list of folders, navigate to the DeskFeed folder, and select Choose. I found that "Fit to Screen" with a black background works best.<br />
<br />
I am open to suggestions about what other photo feeds to include in this application, it only takes about 10 minutes to add a new feed. Furthermore, I will be creating a more solid application that will be customisable through preferences rather than relying on a Python script. But as this is a first attempt, I'm publishing the code to the script to see if anyone else has any suggestions for improvement. If you just want to look at the code used instead of downloading the above file, here it is:</p>


<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">#!/usr/bin/env python</span>
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">os</span>
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">md5</span>
<span style="color: #ff7700;font-weight:bold;">from</span> <span style="color: #dc143c;">urllib</span> <span style="color: #ff7700;font-weight:bold;">import</span> URLopener
<span style="color: #ff7700;font-weight:bold;">from</span> <span style="color: #dc143c;">urllib2</span> <span style="color: #ff7700;font-weight:bold;">import</span> urlopen
<span style="color: #ff7700;font-weight:bold;">from</span> <span style="color: #dc143c;">xml</span>.<span style="color: black;">dom</span>.<span style="color: black;">minidom</span> <span style="color: #ff7700;font-weight:bold;">import</span> parseString
&nbsp;
rss_feeds = <span style="color: black;">&#123;</span><span style="color: black;">&#125;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">#</span>
<span style="color: #808080; font-style: italic;"># Comment / Uncomment the following lines to use the required feeds</span>
<span style="color: #808080; font-style: italic;">#</span>
rss_feeds<span style="color: black;">&#91;</span><span style="color: #483d8b;">'chromasia'</span><span style="color: black;">&#93;</span> = <span style="color: #483d8b;">'http://deskfeed.neophytou.net/rss/chromasia'</span>
rss_feeds<span style="color: black;">&#91;</span><span style="color: #483d8b;">'ddoi'</span><span style="color: black;">&#93;</span> = <span style="color: #483d8b;">'http://deskfeed.neophytou.net/rss/ddoi'</span>
&nbsp;
dst_dir = <span style="color: #dc143c;">os</span>.<span style="color: black;">path</span>.<span style="color: black;">expanduser</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'~/Pictures/DeskFeed/'</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># Based on script found at HackerMoJo.com</span>
<span style="color: #808080; font-style: italic;"># http://hackermojo.com/mt-static/archives/2008/04/metropulse-launched.html</span>
<span style="color: #ff7700;font-weight:bold;">def</span> parseFeed<span style="color: black;">&#40;</span>rss<span style="color: black;">&#41;</span>:
  <span style="color: #ff7700;font-weight:bold;">try</span>:
    rss_contents = urlopen<span style="color: black;">&#40;</span> rss <span style="color: black;">&#41;</span>
  <span style="color: #ff7700;font-weight:bold;">except</span>:
    <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;Failed to read rss feed %s&quot;</span> <span style="color: #66cc66;">%</span> rss
    <span style="color: #ff7700;font-weight:bold;">return</span>
  rss_src = rss_contents.<span style="color: black;">read</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
  rss_contents.<span style="color: black;">close</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
  dom = parseString<span style="color: black;">&#40;</span> rss_src <span style="color: black;">&#41;</span>
  node_lst = dom.<span style="color: black;">getElementsByTagName</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'item'</span><span style="color: black;">&#41;</span>
  items = <span style="color: #008000;">range</span><span style="color: black;">&#40;</span>node_lst.<span style="color: black;">length</span><span style="color: black;">&#41;</span>
  hashes = <span style="color: black;">&#123;</span><span style="color: black;">&#125;</span>
  group = node_lst.<span style="color: black;">item</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#41;</span>.<span style="color: black;">getElementsByTagName</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'title'</span><span style="color: black;">&#41;</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span>.<span style="color: black;">getAttribute</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'group'</span><span style="color: black;">&#41;</span>
  <span style="color: #808080; font-style: italic;"># Store the md5 hashes of all the saved photos</span>
  <span style="color: #ff7700;font-weight:bold;">for</span> i <span style="color: #ff7700;font-weight:bold;">in</span> items:
    img_filename = <span style="color: #483d8b;">&quot;%s%s_%s.jpg&quot;</span> <span style="color: #66cc66;">%</span> <span style="color: black;">&#40;</span>dst_dir,group,i<span style="color: black;">&#41;</span>
    <span style="color: #ff7700;font-weight:bold;">try</span>:
      image_file = <span style="color: #008000;">open</span><span style="color: black;">&#40;</span>img_filename, <span style="color: #483d8b;">&quot;r&quot;</span><span style="color: black;">&#41;</span>
      hashes<span style="color: black;">&#91;</span>img_filename<span style="color: black;">&#93;</span> = <span style="color: #dc143c;">md5</span>.<span style="color: #dc143c;">md5</span><span style="color: black;">&#40;</span>image_file.<span style="color: black;">read</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>.<span style="color: black;">hexdigest</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
      image_file.<span style="color: black;">close</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
    <span style="color: #ff7700;font-weight:bold;">except</span> <span style="color: #008000;">IOError</span>:
      hashes<span style="color: black;">&#91;</span>img_filename<span style="color: black;">&#93;</span> = <span style="color: #483d8b;">&quot;&quot;</span>
      <span style="color: #ff7700;font-weight:bold;">pass</span>
  <span style="color: #808080; font-style: italic;"># Go through all the photos in the rss feed, in reverse order</span>
  items.<span style="color: black;">reverse</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
  <span style="color: #ff7700;font-weight:bold;">for</span> i <span style="color: #ff7700;font-weight:bold;">in</span> items:
    element = node_lst.<span style="color: black;">item</span><span style="color: black;">&#40;</span>i<span style="color: black;">&#41;</span>
    group = element.<span style="color: black;">getElementsByTagName</span><span style="color: black;">&#40;</span> <span style="color: #483d8b;">'title'</span> <span style="color: black;">&#41;</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span>.<span style="color: black;">getAttribute</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'group'</span><span style="color: black;">&#41;</span>
    link = element.<span style="color: black;">getElementsByTagName</span><span style="color: black;">&#40;</span> <span style="color: #483d8b;">'link'</span> <span style="color: black;">&#41;</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span>.<span style="color: black;">getAttribute</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'source'</span><span style="color: black;">&#41;</span>
    photo_hash = element.<span style="color: black;">getElementsByTagName</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'hash'</span><span style="color: black;">&#41;</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span>.<span style="color: black;">firstChild</span>.<span style="color: black;">data</span>
    img_filename = <span style="color: #483d8b;">&quot;%s%s_%s.jpg&quot;</span> <span style="color: #66cc66;">%</span> <span style="color: black;">&#40;</span>dst_dir, group, i<span style="color: black;">&#41;</span>
    <span style="color: #808080; font-style: italic;"># Check all the saved photos and see if any of them have the same hash</span>
    <span style="color: #ff7700;font-weight:bold;">for</span> j <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">range</span><span style="color: black;">&#40;</span>i<span style="color: black;">&#41;</span>:
      old_img_filename = <span style="color: #483d8b;">&quot;%s%s_%s.jpg&quot;</span> <span style="color: #66cc66;">%</span> <span style="color: black;">&#40;</span>dst_dir, group, j<span style="color: black;">&#41;</span>
      <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#40;</span>hashes<span style="color: black;">&#91;</span>old_img_filename<span style="color: black;">&#93;</span> == photo_hash<span style="color: black;">&#41;</span>:
        <span style="color: #808080; font-style: italic;"># If one does, give it the current photo filename</span>
        <span style="color: #dc143c;">os</span>.<span style="color: black;">system</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;mv %s %s&quot;</span> <span style="color: #66cc66;">%</span> <span style="color: black;">&#40;</span>old_img_filename, img_filename<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
        hashes<span style="color: black;">&#91;</span>old_img_filename<span style="color: black;">&#93;</span> = <span style="color: #483d8b;">&quot;&quot;</span>
        hashes<span style="color: black;">&#91;</span>img_filename<span style="color: black;">&#93;</span> = photo_hash
        <span style="color: #ff7700;font-weight:bold;">break</span>
    <span style="color: #ff7700;font-weight:bold;">try</span>:
      image_file = <span style="color: #008000;">open</span><span style="color: black;">&#40;</span>img_filename, <span style="color: #483d8b;">&quot;r&quot;</span><span style="color: black;">&#41;</span>
      old_hash = <span style="color: #dc143c;">md5</span>.<span style="color: #dc143c;">md5</span><span style="color: black;">&#40;</span>image_file.<span style="color: black;">read</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>.<span style="color: black;">hexdigest</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
      image_file.<span style="color: black;">close</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
      <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#40;</span>old_hash == photo_hash<span style="color: black;">&#41;</span>:
        <span style="color: #ff7700;font-weight:bold;">continue</span>
    <span style="color: #ff7700;font-weight:bold;">except</span> <span style="color: #008000;">IOError</span>:
      <span style="color: #ff7700;font-weight:bold;">pass</span>
    <span style="color: #ff7700;font-weight:bold;">try</span>:
      URLopener<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>.<span style="color: black;">retrieve</span><span style="color: black;">&#40;</span>link, img_filename<span style="color: black;">&#41;</span>
    <span style="color: #ff7700;font-weight:bold;">except</span> <span style="color: #008000;">IOError</span>:
      <span style="color: #ff7700;font-weight:bold;">continue</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> main<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>:
  <span style="color: #ff7700;font-weight:bold;">for</span> key <span style="color: #ff7700;font-weight:bold;">in</span> rss_feeds:
    parseFeed<span style="color: black;">&#40;</span>rss_feeds<span style="color: black;">&#91;</span>key<span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">if</span> __name__ == <span style="color: #483d8b;">&quot;__main__&quot;</span>:
  main<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></pre></div></div>



<p>
<a href='http://www.cneophytou.com/wp-content/uploads/2008/04/deskfeed.py'>Download this script</a><br />
<br />
That's pretty much it. As you can see, the script is not that complicated, and I can very easily modify the way the photos are served to the clients. This code has been tested under Leopard using Python 2.5, but also under Ubuntu using Python 2.4.3, and I believe it should also work under Tiger using Python 2.3, but I could very well be wrong. So as always, I'm open to feedback and suggestions. If anyone knows how to create a Preference pane, please contact me. I know exactly what needs to be done in the Preference pane, but I have no idea how to use Xcode.]]></content:encoded>
			<wfw:commentRss>http://www.cneophytou.com/2008/04/17/photo-feed-as-desktop-background/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Simulating encrypted physical disk in OS X</title>
		<link>http://www.cneophytou.com/2008/01/30/simulating-encrypted-physical-disk-in-os-x/</link>
		<comments>http://www.cneophytou.com/2008/01/30/simulating-encrypted-physical-disk-in-os-x/#comments</comments>
		<pubDate>Wed, 30 Jan 2008 22:01:55 +0000</pubDate>
		<dc:creator>Constantinos</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[OS X]]></category>
		<category><![CDATA[Applescript]]></category>
		<category><![CDATA[CC Licence]]></category>
		<category><![CDATA[Encryption]]></category>
		<category><![CDATA[Finder]]></category>
		<category><![CDATA[Folder Actions]]></category>

		<guid isPermaLink="false">http://www.cneophytou.com/2008/01/30/simulating-encrypted-thumb-drive-in-os-x/</guid>
		<description><![CDATA[I&#8217;ve always wanted to do this: have my personal files on a memory stick, encrypted, and when I insert the memory stick in a USB port then OS X asks me for a password to decrypt the files. Unfortunately, this functionality isn&#8217;t offered directly as you can&#8217;t (at least from what I&#8217;ve tried and read) [...]]]></description>
			<content:encoded><![CDATA[I&#8217;ve always wanted to do this: have my personal files on a memory stick, encrypted, and when I insert the memory stick in a USB port then OS X asks me for a password to decrypt the files. Unfortunately, this functionality isn&#8217;t offered directly as you can&#8217;t (at least from what I&#8217;ve tried and read) encrypt a device directly. What you can do however is create encrypted disk images, and place them in your thumb drive. There are two disadvantages with this method: First the process isn&#8217;t automatic, first the drive mounts, then you have to double-click on the encrypted disk image to mount it, and second after you do that you have two volumes on your Desktop. One for the thumb drive, and one for the encrypted image.<br />
<br />
Obviously, in my obsessive compulsive need to have everything work as I want them, I didn&#8217;t like this. As a result, I created the following scripts (including a folder action) which pretty much simulate the whole experience. These scripts were only tested on 10.5.1, but they should work on at least Tiger.<br />
<span id="more-107"></span>
<br />
<span class="update">Update 2008-02-01:</span> <a href='http://www.cneophytou.com/wp-content/uploads/2008/02/secure_scripts.tgz' title='Applescripts bundle'>Download</a> all the scripts featured on this page in a single archive file.<br />
<br />
<span class="update">Update 2008-02-08:</span> The automount and prepare scripts in the download archive were reversed (my mistake) which is now fixed. I also added compatibility for sparsebundle types, and the password entry when preparing a drive is now hidden (thanks John!)<br />
<br />
There are two steps to the process. The first step is to prepare the memory stick, and the second is to configure the folder action. The first step only has to be applied once, and works best on a freshly formatted memory stick, however it doesn&#8217;t have to be formatted; it will use all the available space to create the encrypted image. Save the following script as an application bundle somewhere, plug in the memory stick you wish to use as your &#8216;encrypted storage&#8217;, and drag-drop the mounted volume on the bundle. It will ask you for a password (which is typed in the clear &#8211; fair warning), then after a few minutes (with the default settings) it will finish creating the encrypted image, mark the entire volume as hidden, and eject the drive.</p>


<div class="wp_syntax"><div class="code"><pre class="applescript" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">(*
    Prepare secure drive droplet
    Part of 'Simulating encrypted physical disk in OS X' by Constantinos Neophytou
    http://www.cneophytou.com/2008/01/30/simulating-encrypted-physical-disk-in-os-x/
&nbsp;
    Version 0.1.1
*)</span>
&nbsp;
<span style="color: #ff0033; font-weight: bold;">property</span> imageType : <span style="color: #009900;">&quot;UDIF&quot;</span> <span style="color: #808080; font-style: italic;">(* one of &quot;UDIF&quot;, &quot;SPARSE&quot; or &quot;SPARSEBUNDLE&quot; - the latter two have faster creation times, but leave empty space on the device *)</span>
<span style="color: #ff0033; font-weight: bold;">property</span> thePass : <span style="color: #009900;">&quot;&quot;</span>
&nbsp;
<span style="color: #ff0033; font-weight: bold;">on</span> <span style="color: #0066ff;">open</span> dropped_item
    <span style="color: #ff0033; font-weight: bold;">set</span> this_vol_alias <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #000000;">&#40;</span>dropped_item <span style="color: #ff0033;">as</span> <span style="color: #0066ff;">alias</span><span style="color: #000000;">&#41;</span>
    <span style="color: #ff0033; font-weight: bold;">try</span>
        <span style="color: #ff0033; font-weight: bold;">tell</span> <span style="color: #0066ff;">application</span> <span style="color: #009900;">&quot;Finder&quot;</span>
            <span style="color: #ff0033; font-weight: bold;">if</span> <span style="color: #ff0033;">the</span> kind <span style="color: #ff0033; font-weight: bold;">of</span> this_vol_alias <span style="color: #ff0033; font-weight: bold;">is</span> <span style="color: #009900;">&quot;Volume&quot;</span> <span style="color: #ff0033; font-weight: bold;">then</span>
                <span style="color: #ff0033; font-weight: bold;">set</span> freeSpace <span style="color: #ff0033; font-weight: bold;">to</span> free <span style="color: #0066ff;">space</span> <span style="color: #ff0033; font-weight: bold;">of</span> this_vol_alias
                <span style="color: #ff0033; font-weight: bold;">set</span> volumeName <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #0066ff;">quoted form</span> <span style="color: #ff0033; font-weight: bold;">of</span> <span style="color: #0066ff;">POSIX path</span> <span style="color: #ff0033; font-weight: bold;">of</span> this_vol_alias
                <span style="color: #ff0033; font-weight: bold;">set</span> imgSize <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #000000;">&#40;</span>round <span style="color: #000000;">&#40;</span>freeSpace <span style="color: #000000;">-</span> <span style="color: #000000;">&#40;</span><span style="color: #000000;">1024</span> <span style="color: #000000;">*</span> <span style="color: #000000;">1024</span> <span style="color: #000000;">*</span> <span style="color: #000000;">1</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">/</span> <span style="color: #000000;">&#40;</span><span style="color: #000000;">1024</span> <span style="color: #000000;">*</span> <span style="color: #000000;">1024</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span> <span style="color: #808080; font-style: italic;">(* leave 1mb of free space, just in case *)</span>
&nbsp;
                <span style="color: #0066ff;">display dialog</span> <span style="color: #009900;">&quot;Enter password for encrypted image:&quot;</span> <span style="color: #0066ff;">default answer</span> thePass <span style="color: #ff0033; font-weight: bold;">with</span> <span style="color: #0066ff;">hidden</span> answer
                <span style="color: #ff0033; font-weight: bold;">set</span> thePass <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #0066ff;">text</span> returned <span style="color: #ff0033; font-weight: bold;">of</span> <span style="color: #0066ff;">result</span> <span style="color: #ff0033;">as</span> <span style="color: #0066ff;">string</span>
&nbsp;
                <span style="color: #ff0033; font-weight: bold;">set</span> createImg <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #009900;">&quot;hdiutil create &quot;</span> <span style="color: #000000;">&amp;</span> volumeName <span style="color: #000000;">&amp;</span> <span style="color: #009900;">&quot;.secure -size &quot;</span> <span style="color: #000000;">&amp;</span> imgSize <span style="color: #000000;">&amp;</span> <span style="color: #009900;">&quot;m -fs HFS+ -type &quot;</span> <span style="color: #000000;">&amp;</span> imageType <span style="color: #000000;">&amp;</span> <span style="color: #009900;">&quot; -encryption -volName Secure -passphrase &quot;</span> <span style="color: #000000;">&amp;</span> thePass
                <span style="color: #ff0033; font-weight: bold;">set</span> thePass <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #009900;">&quot;&quot;</span> <span style="color: #808080; font-style: italic;">(* clear the password from memory *)</span>
                <span style="color: #ff0033; font-weight: bold;">set</span> hideVol <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #009900;">&quot;chflags hidden &quot;</span> <span style="color: #000000;">&amp;</span> volumeName
                <span style="color: #ff0033; font-weight: bold;">with</span> <span style="color: #ff0033; font-weight: bold;">timeout</span> <span style="color: #ff0033; font-weight: bold;">of</span> <span style="color: #000000;">600</span> seconds
                    <span style="color: #0066ff;">do shell script</span> createImg
                    <span style="color: #0066ff;">do shell script</span> hideVol
                    <span style="color: #0066ff;">do shell script</span> <span style="color: #009900;">&quot;hdiutil detach &quot;</span> <span style="color: #000000;">&amp;</span> <span style="color: #0066ff;">quoted form</span> <span style="color: #ff0033; font-weight: bold;">of</span> <span style="color: #0066ff;">POSIX path</span> <span style="color: #ff0033; font-weight: bold;">of</span> this_vol_alias
                <span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">timeout</span>
            <span style="color: #ff0033; font-weight: bold;">else</span>
                display alert <span style="color: #009900;">&quot;This script can only be executed on volumes&quot;</span>
                <span style="color: #ff0033; font-weight: bold;">return</span>
            <span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">if</span>
        <span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">tell</span>
&nbsp;
    <span style="color: #ff0033; font-weight: bold;">on</span> <span style="color: #ff0033; font-weight: bold;">error</span> error_message <span style="color: #0066ff;">number</span> error_number
        <span style="color: #0066ff;">display dialog</span> error_message <span style="color: #0066ff;">buttons</span> <span style="color: #000000;">&#123;</span><span style="color: #009900;">&quot;OK&quot;</span><span style="color: #000000;">&#125;</span> default button <span style="color: #000000;">1</span>
    <span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">try</span>
<span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #0066ff;">open</span></pre></div></div>



<p>
<a href="http://www.cneophytou.com/wp-content/uploads/2008/02/secure_scripts.tgz">Download all scripts</a><br />
<br />
At this point, the memory stick is configured for use with the folder action. Warning: If you remove the drive and plug it back in without the folder action being in place, the disk will mount but it won&#8217;t show up in the Finder. You will have to use Disk Utility or the Terminal to un-mount it. Go ahead and copy the following code, save it as a script under <code>/Library/Scripts/Folder Action Scripts/</code>, and attach it as a folder action to <code>/Volumes</code>.</p>


<div class="wp_syntax"><div class="code"><pre class="applescript" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">(*
    Automount secure drive folder action
    Part of 'Simulating encrypted physical disk in OS X' by Constantinos Neophytou
    http://www.cneophytou.com/2008/01/30/simulating-encrypted-physical-disk-in-os-x/
&nbsp;
    Version 0.1.1
*)</span>
&nbsp;
<span style="color: #ff0033; font-weight: bold;">property</span> secureName : <span style="color: #009900;">&quot;.secure&quot;</span>
&nbsp;
<span style="color: #ff0033; font-weight: bold;">on</span> <span style="color: #0066ff;">adding</span> <span style="color: #0066ff;">folder</span> <span style="color: #0066ff;">items</span> <span style="color: #ff0033; font-weight: bold;">to</span> this_folder <span style="color: #ff0033;">after</span> <span style="color: #0066ff;">receiving</span> these_volumes
    <span style="color: #ff0033; font-weight: bold;">try</span>
        <span style="color: #ff0033; font-weight: bold;">tell</span> <span style="color: #0066ff;">application</span> <span style="color: #009900;">&quot;Finder&quot;</span>
            <span style="color: #ff0033; font-weight: bold;">set</span> <span style="color: #ff0033;">the</span> volume_list <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #ff0033;">every</span> <span style="color: #0066ff;">file</span> <span style="color: #ff0033; font-weight: bold;">of</span> this_folder
            <span style="color: #808080; font-style: italic;">(* go through all entries in /Volumes/ *)</span>
            <span style="color: #ff0033; font-weight: bold;">repeat</span> <span style="color: #ff0033; font-weight: bold;">with</span> i <span style="color: #ff0033; font-weight: bold;">from</span> <span style="color: #000000;">1</span> <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #0066ff;">number</span> <span style="color: #ff0033; font-weight: bold;">of</span> <span style="color: #0066ff;">items</span> <span style="color: #ff0033; font-weight: bold;">in</span> volume_list
                <span style="color: #ff0033; font-weight: bold;">set</span> this_item <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #ff0033;">the</span> original <span style="color: #0066ff;">item</span> <span style="color: #ff0033; font-weight: bold;">of</span> <span style="color: #0066ff;">item</span> i <span style="color: #ff0033; font-weight: bold;">of</span> volume_list
                <span style="color: #ff0033; font-weight: bold;">if</span> <span style="color: #ff0033;">the</span> kind <span style="color: #ff0033; font-weight: bold;">of</span> this_item <span style="color: #ff0033; font-weight: bold;">is</span> <span style="color: #009900;">&quot;Volume&quot;</span> <span style="color: #ff0033; font-weight: bold;">then</span>
                    <span style="color: #ff0033; font-weight: bold;">set</span> this_disk <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #000000;">&#40;</span>this_item <span style="color: #ff0033;">as</span> <span style="color: #0066ff;">alias</span><span style="color: #000000;">&#41;</span>
&nbsp;
                    <span style="color: #808080; font-style: italic;">(* is this item the newly mounted disk? *)</span>
                    <span style="color: #ff0033; font-weight: bold;">if</span> this_disk <span style="color: #ff0033; font-weight: bold;">is</span> <span style="color: #ff0033; font-weight: bold;">in</span> these_volumes <span style="color: #ff0033; font-weight: bold;">then</span>
                        <span style="color: #808080; font-style: italic;">(* iterate through all files in the root of disk *)</span>
                        <span style="color: #ff0033; font-weight: bold;">set</span> searchCmd <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #009900;">&quot;ls -d &quot;</span> <span style="color: #000000;">&amp;</span> <span style="color: #0066ff;">quoted form</span> <span style="color: #ff0033; font-weight: bold;">of</span> <span style="color: #0066ff;">POSIX path</span> <span style="color: #ff0033; font-weight: bold;">of</span> this_disk <span style="color: #000000;">&amp;</span> secureName <span style="color: #000000;">&amp;</span> <span style="color: #009900;">&quot;*&quot;</span>
                        <span style="color: #808080; font-style: italic;">(* check to see if a hidden secure image  is available *)</span>
                        <span style="color: #ff0033; font-weight: bold;">set</span> searchResult <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #009900;">&quot;&quot;</span>
                        <span style="color: #ff0033; font-weight: bold;">try</span>
                            <span style="color: #ff0033; font-weight: bold;">set</span> searchResult <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #0066ff;">do shell script</span> searchCmd
                        <span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">try</span>
                        <span style="color: #808080; font-style: italic;">(* mount the secure image *)</span>
                        <span style="color: #ff0033; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>searchResult starts <span style="color: #ff0033; font-weight: bold;">with</span> <span style="color: #009900;">&quot;/Volumes&quot;</span><span style="color: #000000;">&#41;</span> <span style="color: #ff0033; font-weight: bold;">then</span>
                            <span style="color: #ff0033; font-weight: bold;">set</span> hiddenFile <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #0066ff;">POSIX file</span> searchResult <span style="color: #ff0033;">as</span> <span style="color: #0066ff;">alias</span>
                            <span style="color: #0066ff;">open</span> hiddenFile
                        <span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">if</span>
                    <span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">if</span>
                <span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">if</span>
            <span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">repeat</span>
        <span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">tell</span>
    <span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">try</span>
<span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #0066ff;">adding</span> <span style="color: #0066ff;">folder</span> <span style="color: #0066ff;">items</span> <span style="color: #ff0033; font-weight: bold;">to</span>
&nbsp;
<span style="color: #ff0033; font-weight: bold;">on</span> removing <span style="color: #0066ff;">folder</span> <span style="color: #0066ff;">items</span> <span style="color: #ff0033; font-weight: bold;">from</span> this_folder <span style="color: #ff0033;">after</span> losing these_items
    <span style="color: #ff0033; font-weight: bold;">tell</span> <span style="color: #0066ff;">application</span> <span style="color: #009900;">&quot;Finder&quot;</span>
        <span style="color: #ff0033; font-weight: bold;">try</span>
            <span style="color: #ff0033; font-weight: bold;">set</span> <span style="color: #ff0033;">the</span> volume_list <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #ff0033;">every</span> <span style="color: #0066ff;">file</span> <span style="color: #ff0033; font-weight: bold;">of</span> this_folder
            <span style="color: #808080; font-style: italic;">(* go through all entries in /Volumes/ *)</span>
            <span style="color: #ff0033; font-weight: bold;">repeat</span> <span style="color: #ff0033; font-weight: bold;">with</span> i <span style="color: #ff0033; font-weight: bold;">from</span> <span style="color: #000000;">1</span> <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #0066ff;">number</span> <span style="color: #ff0033; font-weight: bold;">of</span> <span style="color: #0066ff;">items</span> <span style="color: #ff0033; font-weight: bold;">in</span> volume_list
                <span style="color: #ff0033; font-weight: bold;">set</span> this_item <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #ff0033;">the</span> original <span style="color: #0066ff;">item</span> <span style="color: #ff0033; font-weight: bold;">of</span> <span style="color: #0066ff;">item</span> i <span style="color: #ff0033; font-weight: bold;">of</span> volume_list
                <span style="color: #ff0033; font-weight: bold;">if</span> <span style="color: #ff0033;">the</span> kind <span style="color: #ff0033; font-weight: bold;">of</span> this_item <span style="color: #ff0033; font-weight: bold;">is</span> <span style="color: #009900;">&quot;Volume&quot;</span> <span style="color: #ff0033; font-weight: bold;">then</span>
                    <span style="color: #ff0033; font-weight: bold;">set</span> this_disk <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #000000;">&#40;</span>this_item <span style="color: #ff0033;">as</span> <span style="color: #0066ff;">alias</span><span style="color: #000000;">&#41;</span>
&nbsp;
                    <span style="color: #ff0033; font-weight: bold;">set</span> searchCmd <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #009900;">&quot;ls -d &quot;</span> <span style="color: #000000;">&amp;</span> <span style="color: #0066ff;">quoted form</span> <span style="color: #ff0033; font-weight: bold;">of</span> <span style="color: #0066ff;">POSIX path</span> <span style="color: #ff0033; font-weight: bold;">of</span> this_disk <span style="color: #000000;">&amp;</span> secureName <span style="color: #000000;">&amp;</span> <span style="color: #009900;">&quot;*&quot;</span>
                    <span style="color: #808080; font-style: italic;">(* check to see if a hidden secure image  is available *)</span>
                    <span style="color: #ff0033; font-weight: bold;">set</span> searchResult <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #009900;">&quot;&quot;</span>
                    <span style="color: #ff0033; font-weight: bold;">try</span>
                        <span style="color: #ff0033; font-weight: bold;">set</span> searchResult <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #0066ff;">do shell script</span> searchCmd
                    <span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">try</span>
                    <span style="color: #ff0033; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>searchResult starts <span style="color: #ff0033; font-weight: bold;">with</span> <span style="color: #009900;">&quot;/Volumes&quot;</span><span style="color: #000000;">&#41;</span> <span style="color: #ff0033; font-weight: bold;">then</span>
                        <span style="color: #808080; font-style: italic;">(* eject the volume *)</span>
                        <span style="color: #0066ff;">do shell script</span> <span style="color: #009900;">&quot;hdiutil detach &quot;</span> <span style="color: #000000;">&amp;</span> <span style="color: #0066ff;">quoted form</span> <span style="color: #ff0033; font-weight: bold;">of</span> <span style="color: #0066ff;">POSIX path</span> <span style="color: #ff0033; font-weight: bold;">of</span> this_disk
                        <span style="color: #808080; font-style: italic;">(* eject this_disk *)</span>
                        delay <span style="color: #000000;">1</span>
                        display alert <span style="color: #009900;">&quot;It is now safe to remove the encrypted disk&quot;</span>
                        <span style="color: #ff0033; font-weight: bold;">return</span>
                    <span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">if</span>
                <span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">if</span>
            <span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">repeat</span>
        <span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">try</span>
    <span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">tell</span>
<span style="color: #ff0033; font-weight: bold;">end</span> removing <span style="color: #0066ff;">folder</span> <span style="color: #0066ff;">items</span> <span style="color: #ff0033; font-weight: bold;">from</span></pre></div></div>



<p>
<a href="http://www.cneophytou.com/wp-content/uploads/2008/02/secure_scripts.tgz">Download all scripts</a><br />
<br />
Now whenever you plug in the thumb drive, this script will kick in and try to open the encrypted image which will in turn make the Finder ask you for a password. Additionally, when you un-mount the encrypted image, it will find the thumb drive and un-mount it as well. You should wait for the confirmation dialog saying it&#8217;s safe to remove the device before doing so, as ejecting the encrypted image is not the same as ejecting the drive, the folder action has to kick in and do that for you.<br />
<br />
There are a couple of issues with this. The first one, I haven&#8217;t been able to find a decent solution for. If after you plug in the memory stick and you&#8217;re asked for a password for the encrypted device, you either enter the wrong password three times or press &#8216;Cancel&#8217;, then the encrypted image will not mount, but the memory stick will remain mounted. To eject it, you will have to use Disk Utility or the Terminal. The second one, is reverting the memory stick to its proper state. To do that, I created another script which you can just run by itself, after plugging in the memory stick and pressing &#8216;Cancel&#8217; when asked for the encrypted image password (i.e. it uses the &#8216;bad&#8217; state described in the previous problem). When run, the script will find the memory stick that contains the encrypted image and ask if you wish to revert it. If you press &#8216;Yes&#8217;, it will then ask if you wish to preserve the secure image. Pressing &#8216;Yes&#8217; will move the secure image on your Desktop (under the name <code>secure.dmg</code>), otherwise it will just delete it from the drive. It will also restore the hidden status of the thumb drive and eject it, so the next time you plug it in it will behave normally:</p>


<div class="wp_syntax"><div class="code"><pre class="applescript" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">(*
    Restore secure drive
    Part of 'Simulating encrypted physical disk in OS X' by Constantinos Neophytou
    http://www.cneophytou.com/2008/01/30/simulating-encrypted-physical-disk-in-os-x/
&nbsp;
    Version 0.1.1
*)</span>
&nbsp;
<span style="color: #ff0033; font-weight: bold;">property</span> secureName : <span style="color: #009900;">&quot;.secure&quot;</span>
<span style="color: #ff0033; font-weight: bold;">tell</span> <span style="color: #0066ff;">application</span> <span style="color: #009900;">&quot;Finder&quot;</span>
    <span style="color: #ff0033; font-weight: bold;">try</span>
        <span style="color: #ff0033; font-weight: bold;">set</span> <span style="color: #ff0033;">the</span> volume_list <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #ff0033;">every</span> <span style="color: #0066ff;">file</span> <span style="color: #ff0033; font-weight: bold;">of</span> <span style="color: #000000;">&#40;</span><span style="color: #0066ff;">POSIX file</span> <span style="color: #009900;">&quot;/Volumes/&quot;</span> <span style="color: #ff0033;">as</span> <span style="color: #0066ff;">alias</span><span style="color: #000000;">&#41;</span>
        <span style="color: #ff0033; font-weight: bold;">repeat</span> <span style="color: #ff0033; font-weight: bold;">with</span> i <span style="color: #ff0033; font-weight: bold;">from</span> <span style="color: #000000;">1</span> <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #0066ff;">number</span> <span style="color: #ff0033; font-weight: bold;">of</span> <span style="color: #0066ff;">items</span> <span style="color: #ff0033; font-weight: bold;">in</span> volume_list
            <span style="color: #ff0033; font-weight: bold;">set</span> this_item <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #ff0033;">the</span> original <span style="color: #0066ff;">item</span> <span style="color: #ff0033; font-weight: bold;">of</span> <span style="color: #0066ff;">item</span> i <span style="color: #ff0033; font-weight: bold;">of</span> volume_list
            <span style="color: #ff0033; font-weight: bold;">if</span> <span style="color: #ff0033;">the</span> kind <span style="color: #ff0033; font-weight: bold;">of</span> this_item <span style="color: #ff0033; font-weight: bold;">is</span> <span style="color: #009900;">&quot;Volume&quot;</span> <span style="color: #ff0033; font-weight: bold;">then</span>
                <span style="color: #ff0033; font-weight: bold;">set</span> this_disk <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #000000;">&#40;</span>this_item <span style="color: #ff0033;">as</span> <span style="color: #0066ff;">alias</span><span style="color: #000000;">&#41;</span>
&nbsp;
                <span style="color: #ff0033; font-weight: bold;">set</span> searchCmd <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #009900;">&quot;ls -d &quot;</span> <span style="color: #000000;">&amp;</span> <span style="color: #0066ff;">quoted form</span> <span style="color: #ff0033; font-weight: bold;">of</span> <span style="color: #0066ff;">POSIX path</span> <span style="color: #ff0033; font-weight: bold;">of</span> this_disk <span style="color: #000000;">&amp;</span> secureName <span style="color: #000000;">&amp;</span> <span style="color: #009900;">&quot;*&quot;</span>
                <span style="color: #808080; font-style: italic;">(* check to see if a hidden secure image  is available *)</span>
                <span style="color: #ff0033; font-weight: bold;">set</span> searchResult <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #009900;">&quot;&quot;</span>
                <span style="color: #ff0033; font-weight: bold;">try</span>
                    <span style="color: #ff0033; font-weight: bold;">set</span> searchResult <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #0066ff;">do shell script</span> searchCmd
                <span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">try</span>
                <span style="color: #ff0033; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>searchResult starts <span style="color: #ff0033; font-weight: bold;">with</span> <span style="color: #009900;">&quot;/Volumes&quot;</span><span style="color: #000000;">&#41;</span> <span style="color: #ff0033; font-weight: bold;">then</span>
                    <span style="color: #0066ff;">display dialog</span> <span style="color: #009900;">&quot;Restore secure disk &quot;</span> <span style="color: #000000;">&amp;</span> <span style="color: #000000;">&#40;</span><span style="color: #0066ff;">name</span> <span style="color: #ff0033; font-weight: bold;">of</span> this_disk<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&amp;</span> <span style="color: #009900;">&quot;?&quot;</span> <span style="color: #0066ff;">buttons</span> <span style="color: #000000;">&#91;</span><span style="color: #009900;">&quot;No&quot;</span>, <span style="color: #009900;">&quot;Yes&quot;</span><span style="color: #000000;">&#93;</span> default button <span style="color: #000000;">2</span>
                    <span style="color: #ff0033; font-weight: bold;">set</span> the_button <span style="color: #ff0033; font-weight: bold;">to</span> button returned <span style="color: #ff0033; font-weight: bold;">of</span> <span style="color: #0066ff;">result</span>
                    <span style="color: #ff0033; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>the_button <span style="color: #ff0033; font-weight: bold;">is</span> <span style="color: #009900;">&quot;Yes&quot;</span><span style="color: #000000;">&#41;</span> <span style="color: #ff0033; font-weight: bold;">then</span>
                        <span style="color: #0066ff;">display dialog</span> <span style="color: #009900;">&quot;Preserve copy of secure data on Desktop?&quot;</span> <span style="color: #0066ff;">buttons</span> <span style="color: #000000;">&#91;</span><span style="color: #009900;">&quot;No&quot;</span>, <span style="color: #009900;">&quot;Yes&quot;</span><span style="color: #000000;">&#93;</span> default button <span style="color: #000000;">2</span>
                        <span style="color: #ff0033; font-weight: bold;">set</span> the_button <span style="color: #ff0033; font-weight: bold;">to</span> button returned <span style="color: #ff0033; font-weight: bold;">of</span> <span style="color: #0066ff;">result</span>
                        <span style="color: #ff0033; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>the_button <span style="color: #ff0033; font-weight: bold;">is</span> <span style="color: #009900;">&quot;Yes&quot;</span><span style="color: #000000;">&#41;</span> <span style="color: #ff0033; font-weight: bold;">then</span>
                            <span style="color: #ff0033; font-weight: bold;">with</span> <span style="color: #ff0033; font-weight: bold;">timeout</span> <span style="color: #ff0033; font-weight: bold;">of</span> <span style="color: #000000;">600</span> seconds
                                <span style="color: #0066ff;">do shell script</span> <span style="color: #009900;">&quot;mv &quot;</span> <span style="color: #000000;">&amp;</span> <span style="color: #0066ff;">quoted form</span> <span style="color: #ff0033; font-weight: bold;">of</span> searchResult <span style="color: #000000;">&amp;</span> <span style="color: #009900;">&quot; ~/Desktop/secure.dmg&quot;</span>
                            <span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">timeout</span>
                        <span style="color: #ff0033; font-weight: bold;">else</span>
                            <span style="color: #0066ff;">do shell script</span> <span style="color: #009900;">&quot;rm -f &quot;</span> <span style="color: #000000;">&amp;</span> <span style="color: #0066ff;">quoted form</span> <span style="color: #ff0033; font-weight: bold;">of</span> searchResult
                        <span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">if</span>
                        <span style="color: #ff0033; font-weight: bold;">set</span> volumeName <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #0066ff;">quoted form</span> <span style="color: #ff0033; font-weight: bold;">of</span> <span style="color: #0066ff;">POSIX path</span> <span style="color: #ff0033; font-weight: bold;">of</span> this_disk
                        <span style="color: #0066ff;">do shell script</span> <span style="color: #009900;">&quot;chflags nohidden &quot;</span> <span style="color: #000000;">&amp;</span> volumeName
                        <span style="color: #0066ff;">do shell script</span> <span style="color: #009900;">&quot;hdiutil detach &quot;</span> <span style="color: #000000;">&amp;</span> volumeName
                        delay <span style="color: #000000;">1</span>
                        display alert <span style="color: #009900;">&quot;Device restored. It is now safe to unplug the device.&quot;</span>
                        <span style="color: #ff0033; font-weight: bold;">return</span>
                    <span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">if</span>
                <span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">if</span>
            <span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">if</span>
        <span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">repeat</span>
&nbsp;
    <span style="color: #ff0033; font-weight: bold;">on</span> <span style="color: #ff0033; font-weight: bold;">error</span> error_message <span style="color: #0066ff;">number</span> error_number
        <span style="color: #0066ff;">display dialog</span> error_message <span style="color: #0066ff;">buttons</span> <span style="color: #000000;">&#123;</span><span style="color: #009900;">&quot;OK&quot;</span><span style="color: #000000;">&#125;</span> default button <span style="color: #000000;">1</span>
    <span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">try</span>
<span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">tell</span></pre></div></div>



<p>
<a href="http://www.cneophytou.com/wp-content/uploads/2008/02/secure_scripts.tgz">Download all scripts</a><br />
<br />
As always, these scripts are provided without any warranty, and any suggested improvements are more than welcome!]]></content:encoded>
			<wfw:commentRss>http://www.cneophytou.com/2008/01/30/simulating-encrypted-physical-disk-in-os-x/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Spoofing Leopard&#8217;s MAC address</title>
		<link>http://www.cneophytou.com/2008/01/19/spoofing-leopards-mac-address/</link>
		<comments>http://www.cneophytou.com/2008/01/19/spoofing-leopards-mac-address/#comments</comments>
		<pubDate>Sat, 19 Jan 2008 19:34:50 +0000</pubDate>
		<dc:creator>Constantinos</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[OS X]]></category>
		<category><![CDATA[Terminal]]></category>
		<category><![CDATA[Ethernet]]></category>
		<category><![CDATA[Leopard]]></category>
		<category><![CDATA[MAC Address]]></category>
		<category><![CDATA[Unix]]></category>

		<guid isPermaLink="false">http://www.cneophytou.com/2008/01/19/spoofing-leopards-mac-address/</guid>
		<description><![CDATA[There are many legitimate reasons why someone would want to spoof a system&#8217;s MAC address. In my case, my University binds our network ports to a specific computer&#8217;s MAC address, and only allows you to reset that address once a week. My problems start when I want to switch my two computers for whatever reason, [...]]]></description>
			<content:encoded><![CDATA[There are many legitimate reasons why someone would want to spoof a system&#8217;s MAC address. In my case, my University binds our network ports to a specific computer&#8217;s MAC address, and only allows you to reset that address once a week. My problems start when I want to switch my two computers for whatever reason, and connect my smaller iBook to the wall (let&#8217;s say I want to keep a web server online, but wish to take my MacBook Pro on the road).<br />
<span id="more-106"></span>
<br />
In Tiger, it was very easy to spoof a MAC address:<br />
</p>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">ifconfig</span> en0 ether 00:00:00:00:00:00</pre></div></div>



<p>
where <code>en0</code> is the network interface you wish to change the MAC address of, and <code>00:00:00:00:00:00</code> is the target MAC address. With Leopard, that line no longer works. No matter how much I searched, I couldn&#8217;t find a solid alternative. Turns out, it&#8217;s extremely simple:<br />
</p>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">ifconfig</span> en0 lladdr 00:00:00:00:00:00</pre></div></div>



<p>
That&#8217;s it!<br />
<strong>Note:</strong> This has been tested under 10.5.1 with both en0 and en1, and at least for the wired interface it works as advertised.]]></content:encoded>
			<wfw:commentRss>http://www.cneophytou.com/2008/01/19/spoofing-leopards-mac-address/feed/</wfw:commentRss>
		<slash:comments>62</slash:comments>
		</item>
		<item>
		<title>Bandwidth throttling in OS X</title>
		<link>http://www.cneophytou.com/2008/01/19/bandwidth-throttling-in-os-x/</link>
		<comments>http://www.cneophytou.com/2008/01/19/bandwidth-throttling-in-os-x/#comments</comments>
		<pubDate>Sat, 19 Jan 2008 14:27:52 +0000</pubDate>
		<dc:creator>Constantinos</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[OS X]]></category>
		<category><![CDATA[Terminal]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[Script]]></category>
		<category><![CDATA[Unix]]></category>

		<guid isPermaLink="false">http://www.cneophytou.com/2008/01/19/bandwidth-throttling-in-os-x/</guid>
		<description><![CDATA[It&#8217;s been a while since my last post, and that&#8217;s because I&#8217;ve been busy with coursework, so I haven&#8217;t had time to mess around with OS X. However there was one feature I needed to figure out out of necessity if anything else. I have certain files I wish to freely share with some friends [...]]]></description>
			<content:encoded><![CDATA[It&#8217;s been a while since my last post, and that&#8217;s because I&#8217;ve been busy with coursework, so I haven&#8217;t had time to mess around with OS X. However there was one feature I needed to figure out out of necessity if anything else. I have certain files I wish to freely share with some friends of mine, and the easiest way for me to do that was put them on my local web server and serve them over http. The only problem with this approach, is that the university has a weekly data transfer limit of 5Gb per week during peak hours, those being between 6pm and midnight. Additionally, local traffic doesn&#8217;t count towards that limit, and if that limit is exceeded then my Internet would be blocked and limited to only the local network for the remainder of that week.<br />
<br />
Therefore, the solution I was looking for would not require me to turn off my web server (as I&#8217;d like to still access it locally), and would ideally simply limit the outgoing traffic automatically between those two times.<br />
<span id="more-105"></span>
<br />
One aspect that made this particular solution usable, was the fact that port 80 is firewalled from the external world. This means that if I want to run a web server on my local machine accessible from the outside, I have to do it on a different port. Therefore I use port 80 to access the web server locally, and port 8080 to access it from the outside. This gives me a dedicated point of entry for the traffic that I wish to limit the bandwidth.<br />
<br />
The solution is fairly simple, and involves only two tools: <code>cron</code>, for enabling and disabling the filter at specific times, and <code>ipfw</code> for actually setting up the filters. The idea is this: create a <code>pipe</code> using <code>ipfw</code> that limits outgoing traffic on port 8080 to a specified rate (let&#8217;s say 15KByte/s), and using a cron job add the pipe to my network interface at 6pm, and delete it at midnight. That&#8217;s it! Theoretically you only have to create the pipe once, but in order to have this survive across restarts, I added another cron job at 5:59pm that re-creates the pipe. The full contents of the crontab file (located at <code>/etc/crontab</code>) are as follows:<br />
</p>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># Set the bandwidth limit at 5:59pm</span>
<span style="color: #000000;">59</span> <span style="color: #000000;">17</span>	<span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000; font-weight: bold;">*</span>	root	<span style="color: #000000; font-weight: bold;">/</span>sbin<span style="color: #000000; font-weight: bold;">/</span>ipfw pipe <span style="color: #000000;">1</span> config bw 15KByte<span style="color: #000000; font-weight: bold;">/</span>s
<span style="color: #666666; font-style: italic;"># Add the bandwidth limit to the specified port at 6:00pm</span>
<span style="color: #000000;">0</span> <span style="color: #000000;">18</span>	<span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000; font-weight: bold;">*</span>	root	<span style="color: #000000; font-weight: bold;">/</span>sbin<span style="color: #000000; font-weight: bold;">/</span>ipfw add <span style="color: #000000;">1</span> pipe <span style="color: #000000;">1</span> src-port <span style="color: #000000;">8080</span>
<span style="color: #666666; font-style: italic;"># Lift the bandwidth limit at 12:00am</span>
<span style="color: #000000;">0</span> <span style="color: #000000;">0</span>	<span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000; font-weight: bold;">*</span>	root	<span style="color: #000000; font-weight: bold;">/</span>sbin<span style="color: #000000; font-weight: bold;">/</span>ipfw delete <span style="color: #000000;">1</span></pre></div></div>



<p>
The problem with this is if the computer boots up or reboots after 6pm and before midnight, the filters will not be set. The solution is to use <code>anacron</code> for executing the ipfw commands, But as I rarely shut down or reboot my computer, it wasn&#8217;t worth it for me to make that happen. If I do make those modifications, I will post an update here. Also note that the ipfw commands need to be executed as root.<br />]]></content:encoded>
			<wfw:commentRss>http://www.cneophytou.com/2008/01/19/bandwidth-throttling-in-os-x/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Automatically restart crashed applications</title>
		<link>http://www.cneophytou.com/2007/10/14/automatically-restart-crashed-applications/</link>
		<comments>http://www.cneophytou.com/2007/10/14/automatically-restart-crashed-applications/#comments</comments>
		<pubDate>Sun, 14 Oct 2007 21:31:07 +0000</pubDate>
		<dc:creator>Constantinos</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[OS X]]></category>
		<category><![CDATA[Applescript]]></category>
		<category><![CDATA[CC Licence]]></category>
		<category><![CDATA[Folder Actions]]></category>
		<category><![CDATA[Quicksilver]]></category>

		<guid isPermaLink="false">http://www.cneophytou.com/2007/10/15/automatically-restart-crashed-applications/</guid>
		<description><![CDATA[I love Quicksilver. If I ever sit on a machine without it, I feel handicapped, like something extremely important is missing. My major gripe with Quicksilver (and, this might just be my setup, I&#8217;m not sure), is that it likes to crash a lot. At least 2-3 times a week. And when it crashes, it&#8217;s [...]]]></description>
			<content:encoded><![CDATA[I love Quicksilver. If I ever sit on a machine without it, I feel handicapped, like something extremely important is missing. My major gripe with Quicksilver (and, this might just be my setup, I&#8217;m not sure), is that it likes to crash a lot. At least 2-3 times a week. And when it crashes, it&#8217;s extremely annoying because when I need to start a program up I use, well, Quicksilver!<br />
<br />
<span class='update'>Updated 2008-01-11:</span> Modified script for Leopard. New script at end of post.<br />
<br />
<span id="more-103"></span>
I&#8217;ve found a couple of different methods for relaunching Quicksilver easily or automatically. One was to keep an alias to Quicksilver on the bottom-left part of your desktop with no icon, and named as &#8221; &#8221; (i.e. a space). So when Quicksilver is off and you want to start it, you cmd-tab to the Finder, hit space, and cmd-o. Quick, easy, does the job, but hardly clean (or nerdy!).<br />
<br />
The other approach which I loved was playing around with launchd (found on <a href='http://www.macworld.com/weblogs/macosxhints/2007/04/autorestart/index.php'>MacWorld</a> and <a href='http://www.macosxhints.com/article.php?story=20060927132601570'>macosxhints.com</a>). With this service we can monitor a file for modifications, and when the file is modified we can perform an action. In this case, we would monitor the file <code>/Users/username/Library/Logs/CrashReporter/Quicksilver.crash.log</code>, and once its modified, launch Quicksilver. Clean, fully automated, but hardly simple. To make the task easier, <a href='http://lingon.sourceforge.net/'>Lingon</a> can be used to deal with launchd. However, I was never able to make this to work, and I don&#8217;t have the patience to sit down and figure out what the problem is.<br />
<br />
I did like the idea of monitoring Quicksilver.crash.log since that&#8217;s a direct indication that the application has crashed, but other than launchd I&#8217;m not familiar with any other automated service that can monitor for modifications in a file. I am however familiar with an automated service that monitors for modifications in a folder, courtesy of OS X, and that&#8217;s folder actions.<br />
<br />
I can therefore build a folder action which will monitor  <code>/Users/username/Library/Logs/CrashReporter/</code> for changes, see what files were added, and if a &#8216;marked&#8217; file was added then relaunch the relevant application and (this part is critical) delete the crash log so the script can work again. It took a couple of tries, but I think I found the most robust solution for this approach.<br />
</p>


<div class="wp_syntax"><div class="code"><pre class="applescript" style="font-family:monospace;"><span style="color: #ff0033; font-weight: bold;">property</span> restartLog : <span style="color: #000000;">&#123;</span><span style="color: #009900;">&quot;Quicksilver.crash.log&quot;</span><span style="color: #000000;">&#125;</span>
<span style="color: #ff0033; font-weight: bold;">property</span> restartID : <span style="color: #000000;">&#123;</span><span style="color: #009900;">&quot;daed&quot;</span><span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #ff0033; font-weight: bold;">on</span> <span style="color: #0066ff;">adding</span> <span style="color: #0066ff;">folder</span> <span style="color: #0066ff;">items</span> <span style="color: #ff0033; font-weight: bold;">to</span> this_folder <span style="color: #ff0033;">after</span> <span style="color: #0066ff;">receiving</span> these_items
    <span style="color: #ff0033; font-weight: bold;">repeat</span> <span style="color: #ff0033; font-weight: bold;">with</span> i <span style="color: #ff0033; font-weight: bold;">from</span> <span style="color: #000000;">1</span> <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #0066ff;">number</span> <span style="color: #ff0033; font-weight: bold;">of</span> <span style="color: #0066ff;">items</span> <span style="color: #ff0033; font-weight: bold;">in</span> these_items
        <span style="color: #ff0033; font-weight: bold;">set</span> fileAlias <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #0066ff;">item</span> i <span style="color: #ff0033; font-weight: bold;">of</span> these_items <span style="color: #ff0033;">as</span> <span style="color: #0066ff;">alias</span>
        <span style="color: #ff0033; font-weight: bold;">set</span> fileInfo <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #0066ff;">info for</span> fileAlias
        <span style="color: #ff0033; font-weight: bold;">set</span> fileName <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #0066ff;">name</span> <span style="color: #ff0033; font-weight: bold;">of</span> fileInfo <span style="color: #ff0033;">as</span> <span style="color: #0066ff;">text</span>
        <span style="color: #ff0033; font-weight: bold;">if</span> fileName <span style="color: #ff0033; font-weight: bold;">is</span> <span style="color: #ff0033; font-weight: bold;">in</span> restartLog <span style="color: #ff0033; font-weight: bold;">then</span>
            <span style="color: #0066ff;">beep</span>
            <span style="color: #ff0033; font-weight: bold;">set</span> itm <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #ff0033; font-weight: bold;">my</span> list_position<span style="color: #000000;">&#40;</span>fileName, restartLog<span style="color: #000000;">&#41;</span>
            <span style="color: #ff0033; font-weight: bold;">tell</span> <span style="color: #0066ff;">application</span> <span style="color: #009900;">&quot;Finder&quot;</span>
                <span style="color: #0066ff;">open</span> <span style="color: #0066ff;">application</span> <span style="color: #0066ff;">file</span> <span style="color: #0066ff;">id</span> <span style="color: #000000;">&#40;</span><span style="color: #0066ff;">item</span> itm <span style="color: #ff0033; font-weight: bold;">of</span> restartID<span style="color: #000000;">&#41;</span>
                <span style="color: #0066ff;">delete</span> <span style="color: #0066ff;">item</span> fileAlias
            <span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">tell</span>
        <span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">if</span>
    <span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">repeat</span>
<span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #0066ff;">adding</span> <span style="color: #0066ff;">folder</span> <span style="color: #0066ff;">items</span> <span style="color: #ff0033; font-weight: bold;">to</span>
&nbsp;
<span style="color: #ff0033; font-weight: bold;">on</span> list_position<span style="color: #000000;">&#40;</span>this_item, this_list<span style="color: #000000;">&#41;</span>
    <span style="color: #ff0033; font-weight: bold;">repeat</span> <span style="color: #ff0033; font-weight: bold;">with</span> i <span style="color: #ff0033; font-weight: bold;">from</span> <span style="color: #000000;">1</span> <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #ff0033;">the</span> <span style="color: #0066ff;">count</span> <span style="color: #ff0033; font-weight: bold;">of</span> this_list
        <span style="color: #ff0033; font-weight: bold;">if</span> <span style="color: #0066ff;">item</span> i <span style="color: #ff0033; font-weight: bold;">of</span> this_list <span style="color: #ff0033; font-weight: bold;">is</span> this_item <span style="color: #ff0033; font-weight: bold;">then</span> <span style="color: #ff0033; font-weight: bold;">return</span> i
    <span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">repeat</span>
    <span style="color: #ff0033; font-weight: bold;">return</span> <span style="color: #000000;">0</span>
<span style="color: #ff0033; font-weight: bold;">end</span> list_position</pre></div></div>



<p>
<a href="http://www.cneophytou.com/wp-content/uploads/2007/10/restartcrashedapp.scpt">Download this script</a><br />
<br />
Note that to get this to work initially, you&#8217;ll have to open that folder and delete the existing Quicksilver.crash.log, otherwise this folder action will never kick in for Quicksilver!<br />
<br />
The critical part are the two properties at the top. The first property contains the name of the file to watch for, and the second property contains (in the same order as in the first property) the application file id for the related application. The reason for using the application file id is that this will remain constant on every system even if the application is renamed by the user.<br />
<br />
This script can be expanded to listen for any number of applications simply by adding the two parameters for each application to these properties. To get the application file id of the application you wish to monitor, simply run this code once in Script Editor while the target application is running:<br />
</p>


<div class="wp_syntax"><div class="code"><pre class="applescript" style="font-family:monospace;"><span style="color: #ff0033; font-weight: bold;">tell</span> <span style="color: #0066ff;">application</span> <span style="color: #009900;">&quot;Finder&quot;</span> <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #ff0033; font-weight: bold;">return</span> creator type <span style="color: #ff0033; font-weight: bold;">of</span> process <span style="color: #009900;">&quot;Process Name&quot;</span></pre></div></div>



<p>
and watch the output.<br />
<br />
As a side note, with this method you can chose to do any number of things instead of just relaunching the crashed application since it&#8217;s straight forward applescript. In my version I chose to &#8216;beep&#8217; as well, to let me know something went wrong (and the file trash sound is also a giveaway), but you really could do anything you want here.<br />
<br />
<span class='update'>Leopard Update:</span><br />
<br />
There have been a few changes in the way Leopard handles the crash log files, which simplifies the use of this script. Instead of using a single crash log file for each application and appending to it, Leopard simply creates a new timestamped crash log in the form <code>Name_YYYY-MM-DD-TIME_Hostname.crash</code>. This is easier, because we no longer have to worry about deleting the crash log, we can simply check if the newly added log starts with *Name*. Therefore, a simpler version of the above applescript (that can only work with a single app, but switching to lists shouldn&#8217;t be too hard), follows:<br />
</p>


<div class="wp_syntax"><div class="code"><pre class="applescript" style="font-family:monospace;"><span style="color: #ff0033; font-weight: bold;">property</span> restartName : <span style="color: #009900;">&quot;Quicksilver&quot;</span>
<span style="color: #ff0033; font-weight: bold;">property</span> restartID : <span style="color: #009900;">&quot;daed&quot;</span>
&nbsp;
<span style="color: #ff0033; font-weight: bold;">on</span> <span style="color: #0066ff;">adding</span> <span style="color: #0066ff;">folder</span> <span style="color: #0066ff;">items</span> <span style="color: #ff0033; font-weight: bold;">to</span> this_folder <span style="color: #ff0033;">after</span> <span style="color: #0066ff;">receiving</span> these_items
    <span style="color: #ff0033; font-weight: bold;">repeat</span> <span style="color: #ff0033; font-weight: bold;">with</span> i <span style="color: #ff0033; font-weight: bold;">from</span> <span style="color: #000000;">1</span> <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #0066ff;">number</span> <span style="color: #ff0033; font-weight: bold;">of</span> <span style="color: #0066ff;">items</span> <span style="color: #ff0033; font-weight: bold;">in</span> these_items
        <span style="color: #ff0033; font-weight: bold;">set</span> fileAlias <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #0066ff;">item</span> i <span style="color: #ff0033; font-weight: bold;">of</span> these_items <span style="color: #ff0033;">as</span> <span style="color: #0066ff;">alias</span>
        <span style="color: #ff0033; font-weight: bold;">set</span> fileInfo <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #0066ff;">info for</span> fileAlias
        <span style="color: #ff0033; font-weight: bold;">set</span> fileName <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #0066ff;">name</span> <span style="color: #ff0033; font-weight: bold;">of</span> fileInfo <span style="color: #ff0033;">as</span> <span style="color: #0066ff;">text</span>
        <span style="color: #ff0033; font-weight: bold;">if</span> fileName starts <span style="color: #ff0033; font-weight: bold;">with</span> restartName <span style="color: #ff0033; font-weight: bold;">then</span>
            <span style="color: #0066ff;">beep</span>
            <span style="color: #ff0033; font-weight: bold;">tell</span> <span style="color: #0066ff;">application</span> <span style="color: #009900;">&quot;Finder&quot;</span>
                <span style="color: #0066ff;">open</span> <span style="color: #0066ff;">application</span> <span style="color: #0066ff;">file</span> <span style="color: #0066ff;">id</span> restartID
            <span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">tell</span>
        <span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">if</span>
    <span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">repeat</span>
<span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #0066ff;">adding</span> <span style="color: #0066ff;">folder</span> <span style="color: #0066ff;">items</span> <span style="color: #ff0033; font-weight: bold;">to</span></pre></div></div>



<p>
<a href="http://www.cneophytou.com/wp-content/uploads/2007/10/restartcrashedapp_10.5.scpt">Download this script</a><br />
<br />
If anyone can figure out how to use applescript instead of the shell commands and still have it work, please let me know.]]></content:encoded>
			<wfw:commentRss>http://www.cneophytou.com/2007/10/14/automatically-restart-crashed-applications/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>iTunes scripts I can&#8217;t live without</title>
		<link>http://www.cneophytou.com/2007/07/24/itunes-scripts-i-cant-live-without/</link>
		<comments>http://www.cneophytou.com/2007/07/24/itunes-scripts-i-cant-live-without/#comments</comments>
		<pubDate>Tue, 24 Jul 2007 18:04:22 +0000</pubDate>
		<dc:creator>Constantinos</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[OS X]]></category>
		<category><![CDATA[Applescript]]></category>
		<category><![CDATA[iTunes]]></category>
		<category><![CDATA[Quicksilver]]></category>
		<category><![CDATA[Shortcuts]]></category>

		<guid isPermaLink="false">http://www.cneophytou.com/2007/07/24/itunes-scripts-i-cant-live-without/</guid>
		<description><![CDATA[I have few obsessions in my life, and one of those happens to be keeping my iTunes library in some form (and definition) of &#8216;order&#8217;, without having me go completely insane. This involves keeping the ID3 data as accurate as I can make it (very tedious process as I had about 100 songs named Track [...]]]></description>
			<content:encoded><![CDATA[I have few obsessions in my life, and one of those happens to be keeping my iTunes library in some form (and definition) of &#8216;order&#8217;, without having me go completely insane. This involves keeping the ID3 data as accurate as I can make it (very tedious process as I had about 100 songs named Track 3 &#8211; Unknown Artist), but that is more or less under control. What I&#8217;m working on now is rating all of my music (I&#8217;m sure every one has their own rating scheme, and there&#8217;s no need to share mine here&#8230; Just suffice to say that a 0-star rating means the song hasn&#8217;t been reviewed), and also getting as much album artwork to go with iTune&#8217;s cover flow so I can use it without looking at the same default image every time&#8230;<br />
<br />
Doing all this manually would pretty much take up all my time, so over a period of few months (back when I first started dealing with my iTunes library), I built a few applescripts which help me manage all these tasks, and which are bound to keyboard shortcuts in Quicksilver.<br />
<span id="more-96"></span>
</p>
<h1>Rating</h1>
<p>
I have all the standard 0-5 star rating scripts, which are bound to cmd-opt-0 through cmd-opt-5 respectively. Since I use Growl, I wanted a notification to come up for this fact, and use the album artwork (if any) as the notification icon. This is the script for the 5 star rating, where for every other (0-4 stars) script the only modification is the actual rating (commented in the script)<br />
</p>


<div class="wp_syntax"><div class="code"><pre class="applescript" style="font-family:monospace;"><span style="color: #ff0033; font-weight: bold;">property</span> emdash : «data utxt2014» <span style="color: #ff0033;">as</span> Unicode <span style="color: #0066ff;">text</span>
<span style="color: #ff0033; font-weight: bold;">property</span> black_star : «data utxt272F» <span style="color: #ff0033;">as</span> Unicode <span style="color: #0066ff;">text</span>
<span style="color: #ff0033; font-weight: bold;">property</span> white_star : «data utxt2606» <span style="color: #ff0033;">as</span> Unicode <span style="color: #0066ff;">text</span>
<span style="color: #ff0033; font-weight: bold;">property</span> dot : «data utxt00B7» <span style="color: #ff0033;">as</span> Unicode <span style="color: #0066ff;">text</span>
&nbsp;
<span style="color: #ff0033; font-weight: bold;">set</span> appName <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #009900;">&quot;GrowlHelperApp&quot;</span>
<span style="color: #ff0033; font-weight: bold;">set</span> app2Name <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #009900;">&quot;iTunes&quot;</span>
&nbsp;
<span style="color: #ff0033; font-weight: bold;">tell</span> <span style="color: #0066ff;">application</span> <span style="color: #009900;">&quot;System Events&quot;</span>
    <span style="color: #ff0033; font-weight: bold;">set</span> appIsRunning <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #000000;">&#40;</span><span style="color: #0066ff;">name</span> <span style="color: #ff0033; font-weight: bold;">of</span> processes <span style="color: #ff0033;">contains</span> appName<span style="color: #000000;">&#41;</span> <span style="color: #ff0033;">and</span> <span style="color: #000000;">&#40;</span><span style="color: #0066ff;">name</span> <span style="color: #ff0033; font-weight: bold;">of</span> processes <span style="color: #ff0033;">contains</span> app2Name<span style="color: #000000;">&#41;</span>
<span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">tell</span>
&nbsp;
<span style="color: #ff0033; font-weight: bold;">if</span> appIsRunning <span style="color: #ff0033; font-weight: bold;">then</span>
    <span style="color: #ff0033; font-weight: bold;">tell</span> <span style="color: #0066ff;">application</span> <span style="color: #009900;">&quot;iTunes&quot;</span>
        <span style="color: #ff0033; font-weight: bold;">if</span> class <span style="color: #ff0033; font-weight: bold;">of</span> current track <span style="color: #ff0033; font-weight: bold;">is</span> <span style="color: #ff0033; font-weight: bold;">in</span> <span style="color: #000000;">&#123;</span>track, <span style="color: #0066ff;">file</span> track, URL track, device track, shared track, audio CD<span style="color: #000000;">&#125;</span> <span style="color: #ff0033; font-weight: bold;">then</span>
            <span style="color: #808080; font-style: italic;">(* Increments of 20, from 0 to 100 for 0 - 5 stars *)</span>
            <span style="color: #ff0033; font-weight: bold;">set</span> rating <span style="color: #ff0033; font-weight: bold;">of</span> current track <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #000000;">100</span>
        <span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">if</span>
        <span style="color: #ff0033; font-weight: bold;">my</span> notifyTrack<span style="color: #000000;">&#40;</span>current track, player position, <span style="color: #009900;">&quot;5 Stars&quot;</span><span style="color: #000000;">&#41;</span> <span style="color: #808080; font-style: italic;">(* or whatever else you want *)</span>
    <span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">tell</span>
<span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">if</span>
&nbsp;
<span style="color: #ff0033; font-weight: bold;">on</span> notifyTrack<span style="color: #000000;">&#40;</span>myTrack, pos, txt<span style="color: #000000;">&#41;</span>
    <span style="color: #ff0033; font-weight: bold;">tell</span> <span style="color: #0066ff;">application</span> <span style="color: #009900;">&quot;iTunes&quot;</span>
        <span style="color: #ff0033; font-weight: bold;">set</span> trkName <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #0066ff;">name</span> <span style="color: #ff0033; font-weight: bold;">of</span> myTrack
        <span style="color: #ff0033; font-weight: bold;">set</span> trkArtist <span style="color: #ff0033; font-weight: bold;">to</span> artist <span style="color: #ff0033; font-weight: bold;">of</span> myTrack
        <span style="color: #ff0033; font-weight: bold;">set</span> trkAlbum <span style="color: #ff0033; font-weight: bold;">to</span> album <span style="color: #ff0033; font-weight: bold;">of</span> myTrack
        <span style="color: #ff0033; font-weight: bold;">set</span> trkTime <span style="color: #ff0033; font-weight: bold;">to</span> time <span style="color: #ff0033; font-weight: bold;">of</span> myTrack
        <span style="color: #ff0033; font-weight: bold;">set</span> trkRating <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #000000;">&#40;</span>rating <span style="color: #ff0033; font-weight: bold;">of</span> myTrack<span style="color: #000000;">&#41;</span> <span style="color: #000000;">/</span> <span style="color: #000000;">20</span>
        <span style="color: #ff0033; font-weight: bold;">set</span> trkPos <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #ff0033; font-weight: bold;">my</span> getTimeString<span style="color: #000000;">&#40;</span>pos<span style="color: #000000;">&#41;</span>
        <span style="color: #ff0033; font-weight: bold;">set</span> artworkCount <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #0066ff;">count</span> <span style="color: #ff0033; font-weight: bold;">of</span> artwork <span style="color: #ff0033; font-weight: bold;">of</span> myTrack
        <span style="color: #ff0033; font-weight: bold;">if</span> artworkCount &gt; <span style="color: #000000;">0</span> <span style="color: #ff0033; font-weight: bold;">then</span>
            <span style="color: #ff0033; font-weight: bold;">tell</span> myTrack
                <span style="color: #ff0033; font-weight: bold;">set</span> trkArt <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #000000;">&#40;</span>data <span style="color: #ff0033; font-weight: bold;">of</span> artwork <span style="color: #000000;">1</span><span style="color: #000000;">&#41;</span>
            <span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">tell</span>
        <span style="color: #ff0033; font-weight: bold;">else</span>
            <span style="color: #ff0033; font-weight: bold;">set</span> iTunesIcon <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #009900;">&quot;Macintosh HD:Applications:iTunes.app:Contents:Resources:iTunes.icns&quot;</span>
            <span style="color: #ff0033; font-weight: bold;">set</span> trkArt <span style="color: #ff0033; font-weight: bold;">to</span> read <span style="color: #000000;">&#40;</span><span style="color: #0066ff;">file</span> iTunesIcon<span style="color: #000000;">&#41;</span> <span style="color: #ff0033;">as</span> picture
        <span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">if</span>
        <span style="color: #ff0033; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>txt <span style="color: #ff0033; font-weight: bold;">is</span> <span style="color: #ff0033;">equal</span> <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #0066ff;">false</span><span style="color: #000000;">&#41;</span> <span style="color: #ff0033; font-weight: bold;">then</span>
            <span style="color: #ff0033; font-weight: bold;">set</span> txt <span style="color: #ff0033; font-weight: bold;">to</span> trkName
            <span style="color: #ff0033; font-weight: bold;">set</span> trkInfo <span style="color: #ff0033; font-weight: bold;">to</span> trkPos <span style="color: #000000;">&amp;</span> <span style="color: #009900;">&quot;/&quot;</span> <span style="color: #000000;">&amp;</span> trkTime <span style="color: #000000;">&amp;</span> <span style="color: #009900;">&quot; &quot;</span> <span style="color: #000000;">&amp;</span> emdash <span style="color: #000000;">&amp;</span> <span style="color: #009900;">&quot; &quot;</span> <span style="color: #000000;">&amp;</span> <span style="color: #ff0033; font-weight: bold;">my</span> showStars<span style="color: #000000;">&#40;</span>trkRating<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&amp;</span> <span style="color: #ff0033; font-weight: bold;">return</span> <span style="color: #000000;">&amp;</span> trkArtist <span style="color: #000000;">&amp;</span> <span style="color: #ff0033; font-weight: bold;">return</span> <span style="color: #000000;">&amp;</span> trkAlbum
        <span style="color: #ff0033; font-weight: bold;">else</span>
            <span style="color: #ff0033; font-weight: bold;">set</span> trkInfo <span style="color: #ff0033; font-weight: bold;">to</span> trkName <span style="color: #000000;">&amp;</span> <span style="color: #ff0033; font-weight: bold;">return</span> <span style="color: #000000;">&amp;</span> trkPos <span style="color: #000000;">&amp;</span> <span style="color: #009900;">&quot;/&quot;</span> <span style="color: #000000;">&amp;</span> trkTime <span style="color: #000000;">&amp;</span> <span style="color: #009900;">&quot; &quot;</span> <span style="color: #000000;">&amp;</span> emdash <span style="color: #000000;">&amp;</span> <span style="color: #009900;">&quot; &quot;</span> <span style="color: #000000;">&amp;</span> <span style="color: #ff0033; font-weight: bold;">my</span> showStars<span style="color: #000000;">&#40;</span>trkRating<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&amp;</span> <span style="color: #ff0033; font-weight: bold;">return</span> <span style="color: #000000;">&amp;</span> trkArtist
            <span style="color: #ff0033; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>trkAlbum <span style="color: #ff0033; font-weight: bold;">is</span> <span style="color: #ff0033;">not</span> <span style="color: #ff0033;">equal</span> <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #009900;">&quot;&quot;</span><span style="color: #000000;">&#41;</span> <span style="color: #ff0033; font-weight: bold;">then</span>
                <span style="color: #ff0033; font-weight: bold;">set</span> trkInfo <span style="color: #ff0033; font-weight: bold;">to</span> trkInfo <span style="color: #000000;">&amp;</span> <span style="color: #009900;">&quot; (&quot;</span> <span style="color: #000000;">&amp;</span> trkAlbum <span style="color: #000000;">&amp;</span> <span style="color: #009900;">&quot;)&quot;</span>
            <span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">if</span>
        <span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">if</span>
    <span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">tell</span>
    <span style="color: #ff0033; font-weight: bold;">my</span> showQSNotify<span style="color: #000000;">&#40;</span>txt, trkArt, trkInfo<span style="color: #000000;">&#41;</span>
<span style="color: #ff0033; font-weight: bold;">end</span> notifyTrack
&nbsp;
<span style="color: #ff0033; font-weight: bold;">on</span> showStars<span style="color: #000000;">&#40;</span>trkRating<span style="color: #000000;">&#41;</span>
    <span style="color: #ff0033; font-weight: bold;">set</span> stars <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #009900;">&quot;&quot;</span>
    <span style="color: #ff0033; font-weight: bold;">repeat</span> trkRating <span style="color: #ff0033; font-weight: bold;">times</span>
        <span style="color: #ff0033; font-weight: bold;">set</span> stars <span style="color: #ff0033; font-weight: bold;">to</span> stars <span style="color: #000000;">&amp;</span> black_star
    <span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">repeat</span>
    <span style="color: #ff0033; font-weight: bold;">repeat</span> <span style="color: #000000;">&#40;</span><span style="color: #000000;">5</span> <span style="color: #000000;">-</span> trkRating<span style="color: #000000;">&#41;</span> <span style="color: #ff0033; font-weight: bold;">times</span>
        <span style="color: #ff0033; font-weight: bold;">set</span> stars <span style="color: #ff0033; font-weight: bold;">to</span> stars <span style="color: #000000;">&amp;</span> <span style="color: #009900;">&quot; &quot;</span> <span style="color: #000000;">&amp;</span> dot
    <span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">repeat</span>
    <span style="color: #ff0033; font-weight: bold;">return</span> stars
<span style="color: #ff0033; font-weight: bold;">end</span> showStars
&nbsp;
<span style="color: #ff0033; font-weight: bold;">on</span> showQSNotify<span style="color: #000000;">&#40;</span>txt, trkArt, trkInfo<span style="color: #000000;">&#41;</span>
    <span style="color: #ff0033; font-weight: bold;">tell</span> <span style="color: #0066ff;">application</span> <span style="color: #009900;">&quot;GrowlHelperApp&quot;</span>
        <span style="color: #ff0033; font-weight: bold;">set</span> <span style="color: #ff0033;">the</span> allNotificationsList <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #000000;">&#123;</span><span style="color: #009900;">&quot;Rating Change&quot;</span>, <span style="color: #009900;">&quot;Song Skipping&quot;</span>, <span style="color: #009900;">&quot;Song Info&quot;</span><span style="color: #000000;">&#125;</span>
        register <span style="color: #ff0033;">as</span> <span style="color: #0066ff;">application</span> ¬
            <span style="color: #009900;">&quot;Hotkey iTunes Notification&quot;</span> all notifications allNotificationsList default notifications allNotificationsList ¬
            icon <span style="color: #ff0033; font-weight: bold;">of</span> <span style="color: #0066ff;">application</span> <span style="color: #009900;">&quot;iTunes&quot;</span>
&nbsp;
        <span style="color: #ff0033; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>trkArt <span style="color: #ff0033; font-weight: bold;">is</span> <span style="color: #ff0033;">equal</span> <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #0066ff;">missing value</span><span style="color: #000000;">&#41;</span> <span style="color: #ff0033; font-weight: bold;">then</span>
            notify <span style="color: #ff0033; font-weight: bold;">with</span> <span style="color: #0066ff;">name</span> <span style="color: #009900;">&quot;Rating Change&quot;</span> title txt description trkInfo <span style="color: #0066ff;">application</span> <span style="color: #0066ff;">name</span> <span style="color: #009900;">&quot;Hotkey iTunes Notification&quot;</span>
        <span style="color: #ff0033; font-weight: bold;">else</span>
            notify <span style="color: #ff0033; font-weight: bold;">with</span> <span style="color: #0066ff;">name</span> <span style="color: #009900;">&quot;Rating Change&quot;</span> title txt description trkInfo <span style="color: #0066ff;">application</span> <span style="color: #0066ff;">name</span> <span style="color: #009900;">&quot;Hotkey iTunes Notification&quot;</span> pictImage <span style="color: #ff0033;">the</span> trkArt
        <span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">if</span>
    <span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">tell</span>
<span style="color: #ff0033; font-weight: bold;">end</span> showQSNotify
&nbsp;
<span style="color: #ff0033; font-weight: bold;">on</span> showTrackInfo<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
    <span style="color: #ff0033; font-weight: bold;">try</span>
        <span style="color: #ff0033; font-weight: bold;">tell</span> <span style="color: #0066ff;">application</span> <span style="color: #009900;">&quot;GrowlTunes&quot;</span>
            show current track
        <span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">tell</span>
    <span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">try</span>
<span style="color: #ff0033; font-weight: bold;">end</span> showTrackInfo
&nbsp;
<span style="color: #ff0033; font-weight: bold;">on</span> getTimeString<span style="color: #000000;">&#40;</span>secs<span style="color: #000000;">&#41;</span>
    <span style="color: #ff0033; font-weight: bold;">set</span> no_seconds <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #ff0033;">the</span> secs <span style="color: #ff0033;">as</span> <span style="color: #0066ff;">number</span>
    <span style="color: #ff0033; font-weight: bold;">set</span> no_minutes <span style="color: #ff0033; font-weight: bold;">to</span> no_seconds <span style="color: #ff0033;">div</span> <span style="color: #000000;">60</span>
    <span style="color: #ff0033; font-weight: bold;">set</span> no_seconds <span style="color: #ff0033; font-weight: bold;">to</span> no_seconds <span style="color: #ff0033;">mod</span> <span style="color: #000000;">60</span>
    <span style="color: #ff0033; font-weight: bold;">if</span> no_seconds <span style="color: #000000;">&lt;</span> <span style="color: #000000;">10</span> <span style="color: #ff0033; font-weight: bold;">then</span>
        <span style="color: #ff0033; font-weight: bold;">set</span> seconds_text <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #009900;">&quot;0&quot;</span> <span style="color: #000000;">&amp;</span> <span style="color: #000000;">&#40;</span>no_seconds <span style="color: #ff0033;">as</span> <span style="color: #0066ff;">string</span><span style="color: #000000;">&#41;</span>
    <span style="color: #ff0033; font-weight: bold;">else</span>
        <span style="color: #ff0033; font-weight: bold;">set</span> seconds_text <span style="color: #ff0033; font-weight: bold;">to</span> no_seconds <span style="color: #ff0033;">as</span> <span style="color: #0066ff;">string</span>
    <span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">if</span>
    <span style="color: #ff0033; font-weight: bold;">if</span> no_minutes ≥ <span style="color: #000000;">60</span> <span style="color: #ff0033; font-weight: bold;">then</span>
        <span style="color: #ff0033; font-weight: bold;">set</span> no_hours <span style="color: #ff0033; font-weight: bold;">to</span> no_minutes <span style="color: #ff0033;">div</span> <span style="color: #000000;">60</span>
        <span style="color: #ff0033; font-weight: bold;">set</span> no_minutes <span style="color: #ff0033; font-weight: bold;">to</span> no_minutes <span style="color: #ff0033;">mod</span> <span style="color: #000000;">60</span>
        <span style="color: #ff0033; font-weight: bold;">if</span> no_minutes <span style="color: #000000;">&lt;</span> <span style="color: #000000;">10</span> <span style="color: #ff0033; font-weight: bold;">then</span>
            <span style="color: #ff0033; font-weight: bold;">set</span> no_minutes <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #009900;">&quot;0&quot;</span> <span style="color: #000000;">&amp;</span> <span style="color: #000000;">&#40;</span>no_minutes <span style="color: #ff0033;">as</span> <span style="color: #0066ff;">string</span><span style="color: #000000;">&#41;</span>
        <span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">if</span>
        <span style="color: #ff0033; font-weight: bold;">set</span> minutes_text <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #000000;">&#40;</span>no_hours <span style="color: #ff0033;">as</span> <span style="color: #0066ff;">string</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&amp;</span> <span style="color: #009900;">&quot;:&quot;</span> <span style="color: #000000;">&amp;</span> <span style="color: #000000;">&#40;</span>no_minutes <span style="color: #ff0033;">as</span> <span style="color: #0066ff;">string</span><span style="color: #000000;">&#41;</span>
    <span style="color: #ff0033; font-weight: bold;">else</span>
        <span style="color: #ff0033; font-weight: bold;">set</span> minutes_text <span style="color: #ff0033; font-weight: bold;">to</span> no_minutes <span style="color: #ff0033;">as</span> <span style="color: #0066ff;">string</span>
    <span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">if</span>
&nbsp;
    <span style="color: #ff0033; font-weight: bold;">return</span> minutes_text <span style="color: #000000;">&amp;</span> <span style="color: #009900;">&quot;:&quot;</span> <span style="color: #000000;">&amp;</span> seconds_text
<span style="color: #ff0033; font-weight: bold;">end</span> getTimeString</pre></div></div>



<p><a href="http://www.cneophytou.com/wp-content/uploads/2007/07/rating.scpt">Download this script</a></p>
<h1>Skipping</h1>
<p>
Sometimes, I find myself having a few hours of free time, where I want to just sit down and rate all my unrated songs. Instead of using the mouse to skip through every song (since I&#8217;ve already heard all of them, I just haven&#8217;t considered a rating for them), I have a script that skips a quarter of the song on each press, and places the playhead at 3 seconds from the end on the 4th activation. Useful for quickly skipping through a song.<br />
</p>


<div class="wp_syntax"><div class="code"><pre class="applescript" style="font-family:monospace;"><span style="color: #ff0033; font-weight: bold;">property</span> emdash : «data utxt2014» <span style="color: #ff0033;">as</span> Unicode <span style="color: #0066ff;">text</span>
<span style="color: #ff0033; font-weight: bold;">property</span> black_star : «data utxt272F» <span style="color: #ff0033;">as</span> Unicode <span style="color: #0066ff;">text</span>
<span style="color: #ff0033; font-weight: bold;">property</span> white_star : «data utxt2606» <span style="color: #ff0033;">as</span> Unicode <span style="color: #0066ff;">text</span>
<span style="color: #ff0033; font-weight: bold;">property</span> dot : «data utxt00B7» <span style="color: #ff0033;">as</span> Unicode <span style="color: #0066ff;">text</span>
&nbsp;
<span style="color: #ff0033; font-weight: bold;">set</span> appName <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #009900;">&quot;GrowlHelperApp&quot;</span>
<span style="color: #ff0033; font-weight: bold;">set</span> app2Name <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #009900;">&quot;iTunes&quot;</span>
&nbsp;
<span style="color: #ff0033; font-weight: bold;">tell</span> <span style="color: #0066ff;">application</span> <span style="color: #009900;">&quot;System Events&quot;</span>
    <span style="color: #ff0033; font-weight: bold;">set</span> appIsRunning <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #000000;">&#40;</span><span style="color: #0066ff;">name</span> <span style="color: #ff0033; font-weight: bold;">of</span> processes <span style="color: #ff0033;">contains</span> appName<span style="color: #000000;">&#41;</span> <span style="color: #ff0033;">and</span> <span style="color: #000000;">&#40;</span><span style="color: #0066ff;">name</span> <span style="color: #ff0033; font-weight: bold;">of</span> processes <span style="color: #ff0033;">contains</span> app2Name<span style="color: #000000;">&#41;</span>
<span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">tell</span>
&nbsp;
<span style="color: #ff0033; font-weight: bold;">if</span> appIsRunning <span style="color: #ff0033; font-weight: bold;">then</span>
    <span style="color: #ff0033; font-weight: bold;">try</span>
        <span style="color: #ff0033; font-weight: bold;">tell</span> <span style="color: #0066ff;">application</span> <span style="color: #009900;">&quot;iTunes&quot;</span>
            <span style="color: #ff0033; font-weight: bold;">set</span> myTrack <span style="color: #ff0033; font-weight: bold;">to</span> current track
            <span style="color: #ff0033; font-weight: bold;">set</span> dur <span style="color: #ff0033; font-weight: bold;">to</span> duration <span style="color: #ff0033; font-weight: bold;">of</span> myTrack
            <span style="color: #ff0033; font-weight: bold;">set</span> q1 <span style="color: #ff0033; font-weight: bold;">to</span> dur <span style="color: #000000;">/</span> <span style="color: #000000;">4</span>
            <span style="color: #ff0033; font-weight: bold;">set</span> q2 <span style="color: #ff0033; font-weight: bold;">to</span> q1 <span style="color: #000000;">*</span> <span style="color: #000000;">2</span>
            <span style="color: #ff0033; font-weight: bold;">set</span> q3 <span style="color: #ff0033; font-weight: bold;">to</span> q1 <span style="color: #000000;">*</span> <span style="color: #000000;">3</span>
            <span style="color: #ff0033; font-weight: bold;">set</span> q4 <span style="color: #ff0033; font-weight: bold;">to</span> dur <span style="color: #000000;">-</span> <span style="color: #000000;">3</span>
            <span style="color: #ff0033; font-weight: bold;">set</span> curPos <span style="color: #ff0033; font-weight: bold;">to</span> player position
            <span style="color: #ff0033; font-weight: bold;">set</span> counter <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #000000;">0</span>
            <span style="color: #ff0033; font-weight: bold;">set</span> theList <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #000000;">&#123;</span>q1, q2, q3, q4, dur<span style="color: #000000;">&#125;</span>
            <span style="color: #ff0033; font-weight: bold;">set</span> pos <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #000000;">0</span>
            <span style="color: #ff0033; font-weight: bold;">repeat</span> <span style="color: #ff0033; font-weight: bold;">while</span> pos <span style="color: #ff0033; font-weight: bold;">is</span> <span style="color: #ff0033;">less</span> than <span style="color: #ff0033;">or</span> <span style="color: #ff0033;">equal</span> <span style="color: #ff0033; font-weight: bold;">to</span> curPos
                <span style="color: #ff0033; font-weight: bold;">set</span> counter <span style="color: #ff0033; font-weight: bold;">to</span> counter <span style="color: #000000;">+</span> <span style="color: #000000;">1</span>
                <span style="color: #ff0033; font-weight: bold;">set</span> pos <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #0066ff;">item</span> counter <span style="color: #ff0033; font-weight: bold;">of</span> theList
            <span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">repeat</span>
            <span style="color: #ff0033; font-weight: bold;">if</span> pos <span style="color: #ff0033; font-weight: bold;">is</span> <span style="color: #ff0033;">less</span> than <span style="color: #000000;">1</span> <span style="color: #ff0033; font-weight: bold;">then</span> <span style="color: #ff0033; font-weight: bold;">set</span> pos <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #000000;">1</span>
            <span style="color: #ff0033; font-weight: bold;">set</span> player position <span style="color: #ff0033; font-weight: bold;">to</span> pos
&nbsp;
            <span style="color: #ff0033; font-weight: bold;">if</span> counter <span style="color: #ff0033; font-weight: bold;">is</span> <span style="color: #ff0033;">greater</span> than <span style="color: #000000;">3</span> <span style="color: #ff0033; font-weight: bold;">then</span>
                <span style="color: #ff0033; font-weight: bold;">my</span> notifyTrack<span style="color: #000000;">&#40;</span>myTrack, player position, <span style="color: #009900;">&quot;Ending Song&quot;</span><span style="color: #000000;">&#41;</span>
            <span style="color: #ff0033; font-weight: bold;">else</span>
                <span style="color: #ff0033; font-weight: bold;">my</span> notifyTrack<span style="color: #000000;">&#40;</span>myTrack, player position, <span style="color: #009900;">&quot;Song Skip&quot;</span><span style="color: #000000;">&#41;</span>
            <span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">if</span>
            <span style="color: #808080; font-style: italic;">(* my showTrackInfo() *)</span>
        <span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">tell</span>
    <span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">try</span>
<span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">if</span>
&nbsp;
<span style="color: #ff0033; font-weight: bold;">on</span> notifyTrack<span style="color: #000000;">&#40;</span>myTrack, pos, txt<span style="color: #000000;">&#41;</span>
    <span style="color: #ff0033; font-weight: bold;">tell</span> <span style="color: #0066ff;">application</span> <span style="color: #009900;">&quot;iTunes&quot;</span>
        <span style="color: #ff0033; font-weight: bold;">set</span> trkName <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #0066ff;">name</span> <span style="color: #ff0033; font-weight: bold;">of</span> myTrack
        <span style="color: #ff0033; font-weight: bold;">set</span> trkArtist <span style="color: #ff0033; font-weight: bold;">to</span> artist <span style="color: #ff0033; font-weight: bold;">of</span> myTrack
        <span style="color: #ff0033; font-weight: bold;">set</span> trkAlbum <span style="color: #ff0033; font-weight: bold;">to</span> album <span style="color: #ff0033; font-weight: bold;">of</span> myTrack
        <span style="color: #ff0033; font-weight: bold;">set</span> trkTime <span style="color: #ff0033; font-weight: bold;">to</span> time <span style="color: #ff0033; font-weight: bold;">of</span> myTrack
        <span style="color: #ff0033; font-weight: bold;">set</span> trkRating <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #000000;">&#40;</span>rating <span style="color: #ff0033; font-weight: bold;">of</span> myTrack<span style="color: #000000;">&#41;</span> <span style="color: #000000;">/</span> <span style="color: #000000;">20</span>
        <span style="color: #ff0033; font-weight: bold;">set</span> trkPos <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #ff0033; font-weight: bold;">my</span> getTimeString<span style="color: #000000;">&#40;</span>pos<span style="color: #000000;">&#41;</span>
        <span style="color: #ff0033; font-weight: bold;">set</span> artworkCount <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #0066ff;">count</span> <span style="color: #ff0033; font-weight: bold;">of</span> artwork <span style="color: #ff0033; font-weight: bold;">of</span> myTrack
        <span style="color: #ff0033; font-weight: bold;">if</span> artworkCount &gt; <span style="color: #000000;">0</span> <span style="color: #ff0033; font-weight: bold;">then</span>
            <span style="color: #ff0033; font-weight: bold;">tell</span> myTrack
                <span style="color: #ff0033; font-weight: bold;">set</span> trkArt <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #000000;">&#40;</span>data <span style="color: #ff0033; font-weight: bold;">of</span> artwork <span style="color: #000000;">1</span><span style="color: #000000;">&#41;</span>
            <span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">tell</span>
        <span style="color: #ff0033; font-weight: bold;">else</span>
            <span style="color: #ff0033; font-weight: bold;">set</span> iTunesIcon <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #009900;">&quot;Macintosh HD:Applications:iTunes.app:Contents:Resources:iTunes.icns&quot;</span>
            <span style="color: #ff0033; font-weight: bold;">set</span> trkArt <span style="color: #ff0033; font-weight: bold;">to</span> read <span style="color: #000000;">&#40;</span><span style="color: #0066ff;">file</span> iTunesIcon<span style="color: #000000;">&#41;</span> <span style="color: #ff0033;">as</span> picture
        <span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">if</span>
        <span style="color: #ff0033; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>txt <span style="color: #ff0033; font-weight: bold;">is</span> <span style="color: #ff0033;">equal</span> <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #0066ff;">false</span><span style="color: #000000;">&#41;</span> <span style="color: #ff0033; font-weight: bold;">then</span>
            <span style="color: #ff0033; font-weight: bold;">set</span> txt <span style="color: #ff0033; font-weight: bold;">to</span> trkName
            <span style="color: #ff0033; font-weight: bold;">set</span> trkInfo <span style="color: #ff0033; font-weight: bold;">to</span> trkPos <span style="color: #000000;">&amp;</span> <span style="color: #009900;">&quot;/&quot;</span> <span style="color: #000000;">&amp;</span> trkTime <span style="color: #000000;">&amp;</span> <span style="color: #009900;">&quot; &quot;</span> <span style="color: #000000;">&amp;</span> emdash <span style="color: #000000;">&amp;</span> <span style="color: #009900;">&quot; &quot;</span> <span style="color: #000000;">&amp;</span> <span style="color: #ff0033; font-weight: bold;">my</span> showStars<span style="color: #000000;">&#40;</span>trkRating<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&amp;</span> <span style="color: #ff0033; font-weight: bold;">return</span> <span style="color: #000000;">&amp;</span> trkArtist <span style="color: #000000;">&amp;</span> <span style="color: #ff0033; font-weight: bold;">return</span> <span style="color: #000000;">&amp;</span> trkAlbum
        <span style="color: #ff0033; font-weight: bold;">else</span>
            <span style="color: #ff0033; font-weight: bold;">set</span> trkInfo <span style="color: #ff0033; font-weight: bold;">to</span> trkName <span style="color: #000000;">&amp;</span> <span style="color: #ff0033; font-weight: bold;">return</span> <span style="color: #000000;">&amp;</span> trkPos <span style="color: #000000;">&amp;</span> <span style="color: #009900;">&quot;/&quot;</span> <span style="color: #000000;">&amp;</span> trkTime <span style="color: #000000;">&amp;</span> <span style="color: #009900;">&quot; &quot;</span> <span style="color: #000000;">&amp;</span> emdash <span style="color: #000000;">&amp;</span> <span style="color: #009900;">&quot; &quot;</span> <span style="color: #000000;">&amp;</span> <span style="color: #ff0033; font-weight: bold;">my</span> showStars<span style="color: #000000;">&#40;</span>trkRating<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&amp;</span> <span style="color: #ff0033; font-weight: bold;">return</span> <span style="color: #000000;">&amp;</span> trkArtist
            <span style="color: #ff0033; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>trkAlbum <span style="color: #ff0033; font-weight: bold;">is</span> <span style="color: #ff0033;">not</span> <span style="color: #ff0033;">equal</span> <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #009900;">&quot;&quot;</span><span style="color: #000000;">&#41;</span> <span style="color: #ff0033; font-weight: bold;">then</span>
                <span style="color: #ff0033; font-weight: bold;">set</span> trkInfo <span style="color: #ff0033; font-weight: bold;">to</span> trkInfo <span style="color: #000000;">&amp;</span> <span style="color: #009900;">&quot; (&quot;</span> <span style="color: #000000;">&amp;</span> trkAlbum <span style="color: #000000;">&amp;</span> <span style="color: #009900;">&quot;)&quot;</span>
            <span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">if</span>
        <span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">if</span>
    <span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">tell</span>
    <span style="color: #ff0033; font-weight: bold;">my</span> showQSNotify<span style="color: #000000;">&#40;</span>txt, trkArt, trkInfo<span style="color: #000000;">&#41;</span>
<span style="color: #ff0033; font-weight: bold;">end</span> notifyTrack
&nbsp;
<span style="color: #ff0033; font-weight: bold;">on</span> showStars<span style="color: #000000;">&#40;</span>trkRating<span style="color: #000000;">&#41;</span>
    <span style="color: #ff0033; font-weight: bold;">set</span> stars <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #009900;">&quot;&quot;</span>
    <span style="color: #ff0033; font-weight: bold;">repeat</span> trkRating <span style="color: #ff0033; font-weight: bold;">times</span>
        <span style="color: #ff0033; font-weight: bold;">set</span> stars <span style="color: #ff0033; font-weight: bold;">to</span> stars <span style="color: #000000;">&amp;</span> black_star
    <span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">repeat</span>
    <span style="color: #ff0033; font-weight: bold;">repeat</span> <span style="color: #000000;">&#40;</span><span style="color: #000000;">5</span> <span style="color: #000000;">-</span> trkRating<span style="color: #000000;">&#41;</span> <span style="color: #ff0033; font-weight: bold;">times</span>
        <span style="color: #ff0033; font-weight: bold;">set</span> stars <span style="color: #ff0033; font-weight: bold;">to</span> stars <span style="color: #000000;">&amp;</span> <span style="color: #009900;">&quot; &quot;</span> <span style="color: #000000;">&amp;</span> dot
    <span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">repeat</span>
    <span style="color: #ff0033; font-weight: bold;">return</span> stars
<span style="color: #ff0033; font-weight: bold;">end</span> showStars
&nbsp;
<span style="color: #ff0033; font-weight: bold;">on</span> showQSNotify<span style="color: #000000;">&#40;</span>txt, trkArt, trkInfo<span style="color: #000000;">&#41;</span>
    <span style="color: #ff0033; font-weight: bold;">tell</span> <span style="color: #0066ff;">application</span> <span style="color: #009900;">&quot;GrowlHelperApp&quot;</span>
        <span style="color: #ff0033; font-weight: bold;">set</span> <span style="color: #ff0033;">the</span> allNotificationsList <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #000000;">&#123;</span><span style="color: #009900;">&quot;Rating Change&quot;</span>, <span style="color: #009900;">&quot;Song Skipping&quot;</span>, <span style="color: #009900;">&quot;Song Info&quot;</span><span style="color: #000000;">&#125;</span>
        register <span style="color: #ff0033;">as</span> <span style="color: #0066ff;">application</span> ¬
            <span style="color: #009900;">&quot;Hotkey iTunes Notification&quot;</span> all notifications allNotificationsList default notifications allNotificationsList ¬
            icon <span style="color: #ff0033; font-weight: bold;">of</span> <span style="color: #0066ff;">application</span> <span style="color: #009900;">&quot;iTunes&quot;</span>
&nbsp;
        <span style="color: #ff0033; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>trkArt <span style="color: #ff0033; font-weight: bold;">is</span> <span style="color: #ff0033;">equal</span> <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #0066ff;">missing value</span><span style="color: #000000;">&#41;</span> <span style="color: #ff0033; font-weight: bold;">then</span>
            notify <span style="color: #ff0033; font-weight: bold;">with</span> <span style="color: #0066ff;">name</span> <span style="color: #009900;">&quot;Song Skipping&quot;</span> title txt description trkInfo <span style="color: #0066ff;">application</span> <span style="color: #0066ff;">name</span> <span style="color: #009900;">&quot;Hotkey iTunes Notification&quot;</span>
        <span style="color: #ff0033; font-weight: bold;">else</span>
            notify <span style="color: #ff0033; font-weight: bold;">with</span> <span style="color: #0066ff;">name</span> <span style="color: #009900;">&quot;Song Skipping&quot;</span> title txt description trkInfo <span style="color: #0066ff;">application</span> <span style="color: #0066ff;">name</span> <span style="color: #009900;">&quot;Hotkey iTunes Notification&quot;</span> pictImage <span style="color: #ff0033;">the</span> trkArt
        <span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">if</span>
    <span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">tell</span>
<span style="color: #ff0033; font-weight: bold;">end</span> showQSNotify
&nbsp;
<span style="color: #ff0033; font-weight: bold;">on</span> showTrackInfo<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
    <span style="color: #ff0033; font-weight: bold;">try</span>
        <span style="color: #ff0033; font-weight: bold;">tell</span> <span style="color: #0066ff;">application</span> <span style="color: #009900;">&quot;GrowlTunes&quot;</span>
            show current track
        <span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">tell</span>
    <span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">try</span>
<span style="color: #ff0033; font-weight: bold;">end</span> showTrackInfo
&nbsp;
<span style="color: #ff0033; font-weight: bold;">on</span> getTimeString<span style="color: #000000;">&#40;</span>secs<span style="color: #000000;">&#41;</span>
    <span style="color: #ff0033; font-weight: bold;">set</span> no_seconds <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #ff0033;">the</span> secs <span style="color: #ff0033;">as</span> <span style="color: #0066ff;">number</span>
    <span style="color: #ff0033; font-weight: bold;">set</span> no_minutes <span style="color: #ff0033; font-weight: bold;">to</span> no_seconds <span style="color: #ff0033;">div</span> <span style="color: #000000;">60</span>
    <span style="color: #ff0033; font-weight: bold;">set</span> no_seconds <span style="color: #ff0033; font-weight: bold;">to</span> no_seconds <span style="color: #ff0033;">mod</span> <span style="color: #000000;">60</span>
    <span style="color: #ff0033; font-weight: bold;">if</span> no_seconds <span style="color: #000000;">&lt;</span> <span style="color: #000000;">10</span> <span style="color: #ff0033; font-weight: bold;">then</span>
        <span style="color: #ff0033; font-weight: bold;">set</span> seconds_text <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #009900;">&quot;0&quot;</span> <span style="color: #000000;">&amp;</span> <span style="color: #000000;">&#40;</span>no_seconds <span style="color: #ff0033;">as</span> <span style="color: #0066ff;">string</span><span style="color: #000000;">&#41;</span>
    <span style="color: #ff0033; font-weight: bold;">else</span>
        <span style="color: #ff0033; font-weight: bold;">set</span> seconds_text <span style="color: #ff0033; font-weight: bold;">to</span> no_seconds <span style="color: #ff0033;">as</span> <span style="color: #0066ff;">string</span>
    <span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">if</span>
    <span style="color: #ff0033; font-weight: bold;">if</span> no_minutes ≥ <span style="color: #000000;">60</span> <span style="color: #ff0033; font-weight: bold;">then</span>
        <span style="color: #ff0033; font-weight: bold;">set</span> no_hours <span style="color: #ff0033; font-weight: bold;">to</span> no_minutes <span style="color: #ff0033;">div</span> <span style="color: #000000;">60</span>
        <span style="color: #ff0033; font-weight: bold;">set</span> no_minutes <span style="color: #ff0033; font-weight: bold;">to</span> no_minutes <span style="color: #ff0033;">mod</span> <span style="color: #000000;">60</span>
        <span style="color: #ff0033; font-weight: bold;">if</span> no_minutes <span style="color: #000000;">&lt;</span> <span style="color: #000000;">10</span> <span style="color: #ff0033; font-weight: bold;">then</span>
            <span style="color: #ff0033; font-weight: bold;">set</span> no_minutes <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #009900;">&quot;0&quot;</span> <span style="color: #000000;">&amp;</span> <span style="color: #000000;">&#40;</span>no_minutes <span style="color: #ff0033;">as</span> <span style="color: #0066ff;">string</span><span style="color: #000000;">&#41;</span>
        <span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">if</span>
        <span style="color: #ff0033; font-weight: bold;">set</span> minutes_text <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #000000;">&#40;</span>no_hours <span style="color: #ff0033;">as</span> <span style="color: #0066ff;">string</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&amp;</span> <span style="color: #009900;">&quot;:&quot;</span> <span style="color: #000000;">&amp;</span> <span style="color: #000000;">&#40;</span>no_minutes <span style="color: #ff0033;">as</span> <span style="color: #0066ff;">string</span><span style="color: #000000;">&#41;</span>
    <span style="color: #ff0033; font-weight: bold;">else</span>
        <span style="color: #ff0033; font-weight: bold;">set</span> minutes_text <span style="color: #ff0033; font-weight: bold;">to</span> no_minutes <span style="color: #ff0033;">as</span> <span style="color: #0066ff;">string</span>
    <span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">if</span>
&nbsp;
    <span style="color: #ff0033; font-weight: bold;">return</span> minutes_text <span style="color: #000000;">&amp;</span> <span style="color: #009900;">&quot;:&quot;</span> <span style="color: #000000;">&amp;</span> seconds_text
<span style="color: #ff0033; font-weight: bold;">end</span> getTimeString</pre></div></div>



<p>
<a href="http://www.cneophytou.com/wp-content/uploads/2007/07/skipping.scpt">Download this script</a><br />
<br />
This method works well with a couple of smart playlists and clever manipulation of the Party Shuffle feature. I have two smart playlists (one of them is used to filter out tv shows and movies, but not video clips). One is named &#8220;Other Video&#8221;, and has the following rules:</p>
<ul><li>Match <strong>any</strong> of the following:</li>
<li>Video kind is Movie</li>
<li>Video kind is TV Show</li>
</ul>
<p>
The other is named &#8220;All Unrated&#8221;, and has the following rules:<br /></p>
<ul>
<li>Match <strong>all</strong> of the following:</li>
<li>My rating is less than 1 star</li>
<li>Podcast is false</li>
<li>Playlist is not Other Video</li>
</ul>
<p>
Finally, in Party Shuffle, at the bottom, I have Source: &#8220;All Unrated&#8221;, Display 5 recently played songs, and 15 upcoming songs. This way, even though the song I just rate will be removed from the &#8220;All Unrated&#8221; smart playlist, it won&#8217;t stop playing as it&#8217;s in the Party Shuffle playlist.<br />
</p>
<h1>Artwork</h1>
<p>
I first ran &#8220;Get Album Artwork&#8221; in iTunes, but obviously that had a fairly limited success as a lot of my music has vital information like Album missing, and also a lot of the music I listen to isn&#8217;t even in the iTunes store. To cover the gap, I&#8217;m a fanatic <a href='http://growl.info/documentation/growltunes.php'>GrowlTunes</a> user, which does all the heavy work of fetching album covers (sometimes more successfully than others). GrowlTunes first looks for album artwork in the song itself, and if it doesn&#8217;t find any it then fetches it from the internet to display the Growl alert. What it does NOT do is save it with the song, but it DOES save it locally so it doesn&#8217;t have to fetch it again (in my opinion this is a very good thing as anything under a 95% success ratio you&#8217;ll want to review, and GrowlTunes is more like 70%). So what I&#8217;ve done is prepared a script that, for the current track, looks at the default GrowlTunes location, and if it finds an album cover it adds it to the song (to run it, you will need to replace your own short user name at the first line of the script):<br />
</p>


<div class="wp_syntax"><div class="code"><pre class="applescript" style="font-family:monospace;"><span style="color: #ff0033; font-weight: bold;">property</span> myUserName : <span style="color: #009900;">&quot;Constantinos&quot;</span>
<span style="color: #ff0033; font-weight: bold;">property</span> appName : <span style="color: #009900;">&quot;iTunes&quot;</span>
&nbsp;
<span style="color: #ff0033; font-weight: bold;">tell</span> <span style="color: #0066ff;">application</span> <span style="color: #009900;">&quot;System Events&quot;</span> <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #ff0033; font-weight: bold;">set</span> appIsRunning <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #0066ff;">name</span> <span style="color: #ff0033; font-weight: bold;">of</span> processes <span style="color: #ff0033;">contains</span> appName
&nbsp;
<span style="color: #ff0033; font-weight: bold;">if</span> appIsRunning <span style="color: #ff0033; font-weight: bold;">then</span>
    <span style="color: #ff0033; font-weight: bold;">tell</span> <span style="color: #0066ff;">application</span> <span style="color: #009900;">&quot;iTunes&quot;</span>
        <span style="color: #ff0033; font-weight: bold;">try</span>
            <span style="color: #ff0033; font-weight: bold;">set</span> myTrack <span style="color: #ff0033; font-weight: bold;">to</span> current track
            <span style="color: #ff0033; font-weight: bold;">set</span> trackName <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #0066ff;">name</span> <span style="color: #ff0033; font-weight: bold;">of</span> myTrack
            <span style="color: #ff0033; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>trackName <span style="color: #ff0033; font-weight: bold;">is</span> <span style="color: #ff0033;">equal</span> <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #009900;">&quot;&quot;</span><span style="color: #000000;">&#41;</span> <span style="color: #ff0033; font-weight: bold;">then</span>
                <span style="color: #ff0033; font-weight: bold;">set</span> trackName <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #009900;">&quot;Unknown Track&quot;</span>
            <span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">if</span>
            <span style="color: #ff0033; font-weight: bold;">set</span> trackArtist <span style="color: #ff0033; font-weight: bold;">to</span> artist <span style="color: #ff0033; font-weight: bold;">of</span> myTrack
            <span style="color: #ff0033; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>trackArtist <span style="color: #ff0033; font-weight: bold;">is</span> <span style="color: #ff0033;">equal</span> <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #009900;">&quot;&quot;</span><span style="color: #000000;">&#41;</span> <span style="color: #ff0033; font-weight: bold;">then</span>
                <span style="color: #ff0033; font-weight: bold;">set</span> trackArtist <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #009900;">&quot;Unknown Artist&quot;</span>
            <span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">if</span>
            <span style="color: #ff0033; font-weight: bold;">set</span> trackAlbum <span style="color: #ff0033; font-weight: bold;">to</span> album <span style="color: #ff0033; font-weight: bold;">of</span> myTrack
            <span style="color: #ff0033; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>trackAlbum <span style="color: #ff0033; font-weight: bold;">is</span> <span style="color: #ff0033;">equal</span> <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #009900;">&quot;&quot;</span><span style="color: #000000;">&#41;</span> <span style="color: #ff0033; font-weight: bold;">then</span>
                <span style="color: #ff0033; font-weight: bold;">set</span> trackAlbum <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #009900;">&quot;Unknown Album&quot;</span>
            <span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">if</span>
        <span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">try</span>
    <span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">tell</span>
&nbsp;
    <span style="color: #ff0033; font-weight: bold;">set</span> artworkFilename <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #009900;">&quot;/Users/&quot;</span> <span style="color: #000000;">&amp;</span> myUserName <span style="color: #000000;">&amp;</span> <span style="color: #009900;">&quot;/Library/Images/Music/&quot;</span> <span style="color: #000000;">&amp;</span> trackArtist <span style="color: #000000;">&amp;</span> <span style="color: #009900;">&quot;/&quot;</span> <span style="color: #000000;">&amp;</span> trackAlbum <span style="color: #000000;">&amp;</span> <span style="color: #009900;">&quot;/Tracks/&quot;</span> <span style="color: #000000;">&amp;</span> trackName <span style="color: #000000;">&amp;</span> <span style="color: #009900;">&quot;/Track.png&quot;</span>
    <span style="color: #ff0033; font-weight: bold;">set</span> deleteFilename <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #009900;">&quot;Macintosh HD:Users:&quot;</span> <span style="color: #000000;">&amp;</span> myUserName <span style="color: #000000;">&amp;</span> <span style="color: #009900;">&quot;:Library:Images:Music:&quot;</span> <span style="color: #000000;">&amp;</span> trackArtist <span style="color: #000000;">&amp;</span> <span style="color: #009900;">&quot;:&quot;</span> <span style="color: #000000;">&amp;</span> trackAlbum <span style="color: #000000;">&amp;</span> <span style="color: #009900;">&quot;:Tracks:&quot;</span> <span style="color: #000000;">&amp;</span> trackName <span style="color: #000000;">&amp;</span> <span style="color: #009900;">&quot;:Track.png&quot;</span>
&nbsp;
    <span style="color: #ff0033; font-weight: bold;">set</span> deleteCoverFilename <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #009900;">&quot;Macintosh HD:Users:&quot;</span> <span style="color: #000000;">&amp;</span> myUserName <span style="color: #000000;">&amp;</span> <span style="color: #009900;">&quot;:Library:Images:Music:&quot;</span> <span style="color: #000000;">&amp;</span> trackArtist <span style="color: #000000;">&amp;</span> <span style="color: #009900;">&quot;:&quot;</span> <span style="color: #000000;">&amp;</span> trackAlbum <span style="color: #000000;">&amp;</span> <span style="color: #009900;">&quot;:Cover.png&quot;</span>
    <span style="color: #ff0033; font-weight: bold;">set</span> albumCoverFilename <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #009900;">&quot;/Users/&quot;</span> <span style="color: #000000;">&amp;</span> myUserName <span style="color: #000000;">&amp;</span> <span style="color: #009900;">&quot;/Library/Images/Music/&quot;</span> <span style="color: #000000;">&amp;</span> trackArtist <span style="color: #000000;">&amp;</span> <span style="color: #009900;">&quot;/&quot;</span> <span style="color: #000000;">&amp;</span> trackAlbum <span style="color: #000000;">&amp;</span> <span style="color: #009900;">&quot;/Cover.png&quot;</span>
&nbsp;
    <span style="color: #ff0033; font-weight: bold;">set</span> tempfile <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #009900;">&quot;Macintosh HD:tmp:temporary.pict&quot;</span>
&nbsp;
    <span style="color: #ff0033; font-weight: bold;">tell</span> <span style="color: #0066ff;">application</span> <span style="color: #009900;">&quot;Image Events&quot;</span>
        <span style="color: #808080; font-style: italic;">(* set artworkFile to (POSIX file artworkFilename)
        set myImage to open (artworkFile as alias) *)</span>
        <span style="color: #ff0033; font-weight: bold;">set</span> myImage <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #0066ff;">open</span> artworkFilename
        <span style="color: #ff0033; font-weight: bold;">try</span>
            <span style="color: #0066ff;">save</span> myImage <span style="color: #ff0033;">as</span> PICT <span style="color: #ff0033; font-weight: bold;">in</span> <span style="color: #000000;">&#40;</span><span style="color: #0066ff;">file</span> tempfile<span style="color: #000000;">&#41;</span>
        <span style="color: #ff0033; font-weight: bold;">on</span> <span style="color: #ff0033; font-weight: bold;">error</span>
            <span style="color: #ff0033; font-weight: bold;">try</span>
                <span style="color: #ff0033; font-weight: bold;">set</span> deleteFilename <span style="color: #ff0033; font-weight: bold;">to</span> deleteCoverFilename
                <span style="color: #ff0033; font-weight: bold;">set</span> myImage <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #0066ff;">open</span> albumCoverFilename
                <span style="color: #0066ff;">save</span> myImage <span style="color: #ff0033;">as</span> PICT <span style="color: #ff0033; font-weight: bold;">in</span> <span style="color: #000000;">&#40;</span><span style="color: #0066ff;">file</span> tempfile<span style="color: #000000;">&#41;</span>
            <span style="color: #ff0033; font-weight: bold;">on</span> <span style="color: #ff0033; font-weight: bold;">error</span>
                <span style="color: #ff0033; font-weight: bold;">return</span>
            <span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">try</span>
        <span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">try</span>
        <span style="color: #0066ff;">close</span> myImage
    <span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">tell</span>
&nbsp;
    <span style="color: #ff0033; font-weight: bold;">tell</span> <span style="color: #0066ff;">application</span> <span style="color: #009900;">&quot;iTunes&quot;</span>
        <span style="color: #ff0033; font-weight: bold;">set</span> myTrack <span style="color: #ff0033; font-weight: bold;">to</span> current track
        <span style="color: #ff0033; font-weight: bold;">set</span> artworkCount <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #0066ff;">count</span> <span style="color: #ff0033; font-weight: bold;">of</span> artwork <span style="color: #ff0033; font-weight: bold;">of</span> myTrack
        <span style="color: #ff0033; font-weight: bold;">set</span> myArt <span style="color: #ff0033; font-weight: bold;">to</span> read <span style="color: #000000;">&#40;</span><span style="color: #0066ff;">file</span> tempfile<span style="color: #000000;">&#41;</span> <span style="color: #ff0033; font-weight: bold;">from</span> <span style="color: #000000;">513</span> <span style="color: #ff0033;">as</span> picture
        <span style="color: #ff0033; font-weight: bold;">if</span> artworkCount &gt; <span style="color: #000000;">0</span> <span style="color: #ff0033; font-weight: bold;">then</span>
            <span style="color: #ff0033; font-weight: bold;">set</span> data <span style="color: #ff0033; font-weight: bold;">of</span> artwork <span style="color: #000000;">&#40;</span>artworkCount <span style="color: #000000;">+</span> <span style="color: #000000;">1</span><span style="color: #000000;">&#41;</span> <span style="color: #ff0033; font-weight: bold;">of</span> current track <span style="color: #ff0033; font-weight: bold;">to</span> myArt
        <span style="color: #ff0033; font-weight: bold;">else</span>
            <span style="color: #ff0033; font-weight: bold;">set</span> data <span style="color: #ff0033; font-weight: bold;">of</span> artwork <span style="color: #000000;">1</span> <span style="color: #ff0033; font-weight: bold;">of</span> current track <span style="color: #ff0033; font-weight: bold;">to</span> myArt
        <span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">if</span>
    <span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">tell</span>
&nbsp;
    <span style="color: #ff0033; font-weight: bold;">tell</span> <span style="color: #0066ff;">application</span> <span style="color: #009900;">&quot;Image Events&quot;</span>
        <span style="color: #0066ff;">delete</span> <span style="color: #000000;">&#40;</span><span style="color: #0066ff;">file</span> tempfile<span style="color: #000000;">&#41;</span>
        <span style="color: #0066ff;">delete</span> <span style="color: #000000;">&#40;</span><span style="color: #0066ff;">file</span> deleteFilename<span style="color: #000000;">&#41;</span>
    <span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">tell</span>
&nbsp;
<span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">if</span></pre></div></div>



<p><a href="http://www.cneophytou.com/wp-content/uploads/2007/07/artwork.scpt">Download this script</a></p>
<h1>Notifications</h1>
<p>
The first two scripts use the same &#8220;Hotkey iTunes Notification&#8221; application name to register with Growl, with three types of notification: &#8220;Rating Change&#8221;, &#8220;Song Skipping&#8221; and &#8220;Song Info&#8221;. The last one simply brings up a detailed notification dialog with the current song&#8217;s playhead position, title, artist, rating, album and album art, which can all fit in the small &#8220;Smoke&#8221; style notification window. If you&#8217;re interested in that, the script follows:<br />
</p>


<div class="wp_syntax"><div class="code"><pre class="applescript" style="font-family:monospace;"><span style="color: #ff0033; font-weight: bold;">property</span> emdash : «data utxt2014» <span style="color: #ff0033;">as</span> Unicode <span style="color: #0066ff;">text</span>
<span style="color: #ff0033; font-weight: bold;">property</span> black_star : «data utxt272F» <span style="color: #ff0033;">as</span> Unicode <span style="color: #0066ff;">text</span>
<span style="color: #ff0033; font-weight: bold;">property</span> white_star : «data utxt2606» <span style="color: #ff0033;">as</span> Unicode <span style="color: #0066ff;">text</span>
<span style="color: #ff0033; font-weight: bold;">property</span> dot : «data utxt00B7» <span style="color: #ff0033;">as</span> Unicode <span style="color: #0066ff;">text</span>
&nbsp;
<span style="color: #ff0033; font-weight: bold;">set</span> appName <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #009900;">&quot;GrowlHelperApp&quot;</span>
<span style="color: #ff0033; font-weight: bold;">set</span> app2Name <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #009900;">&quot;iTunes&quot;</span>
&nbsp;
<span style="color: #ff0033; font-weight: bold;">tell</span> <span style="color: #0066ff;">application</span> <span style="color: #009900;">&quot;System Events&quot;</span>
    <span style="color: #ff0033; font-weight: bold;">set</span> appIsRunning <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #000000;">&#40;</span><span style="color: #0066ff;">name</span> <span style="color: #ff0033; font-weight: bold;">of</span> processes <span style="color: #ff0033;">contains</span> appName<span style="color: #000000;">&#41;</span> <span style="color: #ff0033;">and</span> <span style="color: #000000;">&#40;</span><span style="color: #0066ff;">name</span> <span style="color: #ff0033; font-weight: bold;">of</span> processes <span style="color: #ff0033;">contains</span> app2Name<span style="color: #000000;">&#41;</span>
<span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">tell</span>
&nbsp;
<span style="color: #ff0033; font-weight: bold;">if</span> appIsRunning <span style="color: #ff0033; font-weight: bold;">then</span>
    <span style="color: #ff0033; font-weight: bold;">tell</span> <span style="color: #0066ff;">application</span> <span style="color: #009900;">&quot;iTunes&quot;</span>
        <span style="color: #ff0033; font-weight: bold;">my</span> notifyTrack<span style="color: #000000;">&#40;</span>current track, player position, <span style="color: #0066ff;">false</span><span style="color: #000000;">&#41;</span>
    <span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">tell</span>
<span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">if</span>
&nbsp;
<span style="color: #ff0033; font-weight: bold;">on</span> notifyTrack<span style="color: #000000;">&#40;</span>myTrack, pos, txt<span style="color: #000000;">&#41;</span>
    <span style="color: #ff0033; font-weight: bold;">tell</span> <span style="color: #0066ff;">application</span> <span style="color: #009900;">&quot;iTunes&quot;</span>
        <span style="color: #ff0033; font-weight: bold;">set</span> trkName <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #0066ff;">name</span> <span style="color: #ff0033; font-weight: bold;">of</span> myTrack
        <span style="color: #ff0033; font-weight: bold;">set</span> trkArtist <span style="color: #ff0033; font-weight: bold;">to</span> artist <span style="color: #ff0033; font-weight: bold;">of</span> myTrack
        <span style="color: #ff0033; font-weight: bold;">set</span> trkAlbum <span style="color: #ff0033; font-weight: bold;">to</span> album <span style="color: #ff0033; font-weight: bold;">of</span> myTrack
        <span style="color: #ff0033; font-weight: bold;">set</span> trkTime <span style="color: #ff0033; font-weight: bold;">to</span> time <span style="color: #ff0033; font-weight: bold;">of</span> myTrack
        <span style="color: #ff0033; font-weight: bold;">set</span> trkRating <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #000000;">&#40;</span>rating <span style="color: #ff0033; font-weight: bold;">of</span> myTrack<span style="color: #000000;">&#41;</span> <span style="color: #000000;">/</span> <span style="color: #000000;">20</span>
        <span style="color: #ff0033; font-weight: bold;">set</span> trkPos <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #ff0033; font-weight: bold;">my</span> getTimeString<span style="color: #000000;">&#40;</span>pos<span style="color: #000000;">&#41;</span>
        <span style="color: #ff0033; font-weight: bold;">set</span> artworkCount <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #0066ff;">count</span> <span style="color: #ff0033; font-weight: bold;">of</span> artwork <span style="color: #ff0033; font-weight: bold;">of</span> myTrack
        <span style="color: #ff0033; font-weight: bold;">if</span> artworkCount &gt; <span style="color: #000000;">0</span> <span style="color: #ff0033; font-weight: bold;">then</span>
            <span style="color: #ff0033; font-weight: bold;">tell</span> myTrack
                <span style="color: #ff0033; font-weight: bold;">set</span> trkArt <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #000000;">&#40;</span>data <span style="color: #ff0033; font-weight: bold;">of</span> artwork <span style="color: #000000;">1</span><span style="color: #000000;">&#41;</span>
            <span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">tell</span>
        <span style="color: #ff0033; font-weight: bold;">else</span>
            <span style="color: #ff0033; font-weight: bold;">set</span> iTunesIcon <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #009900;">&quot;Macintosh HD:Applications:iTunes.app:Contents:Resources:iTunes.icns&quot;</span>
            <span style="color: #ff0033; font-weight: bold;">set</span> trkArt <span style="color: #ff0033; font-weight: bold;">to</span> read <span style="color: #000000;">&#40;</span><span style="color: #0066ff;">file</span> iTunesIcon<span style="color: #000000;">&#41;</span> <span style="color: #ff0033;">as</span> picture
        <span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">if</span>
        <span style="color: #ff0033; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>txt <span style="color: #ff0033; font-weight: bold;">is</span> <span style="color: #ff0033;">equal</span> <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #0066ff;">false</span><span style="color: #000000;">&#41;</span> <span style="color: #ff0033; font-weight: bold;">then</span>
            <span style="color: #ff0033; font-weight: bold;">set</span> txt <span style="color: #ff0033; font-weight: bold;">to</span> trkName
            <span style="color: #ff0033; font-weight: bold;">set</span> trkInfo <span style="color: #ff0033; font-weight: bold;">to</span> trkPos <span style="color: #000000;">&amp;</span> <span style="color: #009900;">&quot;/&quot;</span> <span style="color: #000000;">&amp;</span> trkTime <span style="color: #000000;">&amp;</span> <span style="color: #009900;">&quot; &quot;</span> <span style="color: #000000;">&amp;</span> emdash <span style="color: #000000;">&amp;</span> <span style="color: #009900;">&quot; &quot;</span> <span style="color: #000000;">&amp;</span> <span style="color: #ff0033; font-weight: bold;">my</span> showStars<span style="color: #000000;">&#40;</span>trkRating<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&amp;</span> <span style="color: #ff0033; font-weight: bold;">return</span> <span style="color: #000000;">&amp;</span> trkArtist <span style="color: #000000;">&amp;</span> <span style="color: #ff0033; font-weight: bold;">return</span> <span style="color: #000000;">&amp;</span> trkAlbum
        <span style="color: #ff0033; font-weight: bold;">else</span>
            <span style="color: #ff0033; font-weight: bold;">set</span> trkInfo <span style="color: #ff0033; font-weight: bold;">to</span> trkName <span style="color: #000000;">&amp;</span> <span style="color: #ff0033; font-weight: bold;">return</span> <span style="color: #000000;">&amp;</span> trkPos <span style="color: #000000;">&amp;</span> <span style="color: #009900;">&quot;/&quot;</span> <span style="color: #000000;">&amp;</span> trkTime <span style="color: #000000;">&amp;</span> <span style="color: #009900;">&quot; &quot;</span> <span style="color: #000000;">&amp;</span> emdash <span style="color: #000000;">&amp;</span> <span style="color: #009900;">&quot; &quot;</span> <span style="color: #000000;">&amp;</span> <span style="color: #ff0033; font-weight: bold;">my</span> showStars<span style="color: #000000;">&#40;</span>trkRating<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&amp;</span> <span style="color: #ff0033; font-weight: bold;">return</span> <span style="color: #000000;">&amp;</span> trkArtist
            <span style="color: #ff0033; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>trkAlbum <span style="color: #ff0033; font-weight: bold;">is</span> <span style="color: #ff0033;">not</span> <span style="color: #ff0033;">equal</span> <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #009900;">&quot;&quot;</span><span style="color: #000000;">&#41;</span> <span style="color: #ff0033; font-weight: bold;">then</span>
                <span style="color: #ff0033; font-weight: bold;">set</span> trkInfo <span style="color: #ff0033; font-weight: bold;">to</span> trkInfo <span style="color: #000000;">&amp;</span> <span style="color: #009900;">&quot; (&quot;</span> <span style="color: #000000;">&amp;</span> trkAlbum <span style="color: #000000;">&amp;</span> <span style="color: #009900;">&quot;)&quot;</span>
            <span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">if</span>
        <span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">if</span>
    <span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">tell</span>
    <span style="color: #ff0033; font-weight: bold;">my</span> showQSNotify<span style="color: #000000;">&#40;</span>txt, trkArt, trkInfo<span style="color: #000000;">&#41;</span>
<span style="color: #ff0033; font-weight: bold;">end</span> notifyTrack
&nbsp;
<span style="color: #ff0033; font-weight: bold;">on</span> showStars<span style="color: #000000;">&#40;</span>trkRating<span style="color: #000000;">&#41;</span>
    <span style="color: #ff0033; font-weight: bold;">set</span> stars <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #009900;">&quot;&quot;</span>
    <span style="color: #ff0033; font-weight: bold;">repeat</span> trkRating <span style="color: #ff0033; font-weight: bold;">times</span>
        <span style="color: #ff0033; font-weight: bold;">set</span> stars <span style="color: #ff0033; font-weight: bold;">to</span> stars <span style="color: #000000;">&amp;</span> black_star
    <span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">repeat</span>
    <span style="color: #ff0033; font-weight: bold;">repeat</span> <span style="color: #000000;">&#40;</span><span style="color: #000000;">5</span> <span style="color: #000000;">-</span> trkRating<span style="color: #000000;">&#41;</span> <span style="color: #ff0033; font-weight: bold;">times</span>
        <span style="color: #ff0033; font-weight: bold;">set</span> stars <span style="color: #ff0033; font-weight: bold;">to</span> stars <span style="color: #000000;">&amp;</span> <span style="color: #009900;">&quot; &quot;</span> <span style="color: #000000;">&amp;</span> dot
    <span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">repeat</span>
    <span style="color: #ff0033; font-weight: bold;">return</span> stars
<span style="color: #ff0033; font-weight: bold;">end</span> showStars
&nbsp;
<span style="color: #ff0033; font-weight: bold;">on</span> showQSNotify<span style="color: #000000;">&#40;</span>txt, trkArt, trkInfo<span style="color: #000000;">&#41;</span>
    <span style="color: #ff0033; font-weight: bold;">tell</span> <span style="color: #0066ff;">application</span> <span style="color: #009900;">&quot;GrowlHelperApp&quot;</span>
        <span style="color: #ff0033; font-weight: bold;">set</span> <span style="color: #ff0033;">the</span> allNotificationsList <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #000000;">&#123;</span><span style="color: #009900;">&quot;Rating Change&quot;</span>, <span style="color: #009900;">&quot;Song Skipping&quot;</span>, <span style="color: #009900;">&quot;Song Info&quot;</span><span style="color: #000000;">&#125;</span>
        register <span style="color: #ff0033;">as</span> <span style="color: #0066ff;">application</span> ¬
            <span style="color: #009900;">&quot;Hotkey iTunes Notification&quot;</span> all notifications allNotificationsList default notifications allNotificationsList ¬
            icon <span style="color: #ff0033; font-weight: bold;">of</span> <span style="color: #0066ff;">application</span> <span style="color: #009900;">&quot;iTunes&quot;</span>
&nbsp;
        <span style="color: #ff0033; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>trkArt <span style="color: #ff0033; font-weight: bold;">is</span> <span style="color: #ff0033;">equal</span> <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #0066ff;">missing value</span><span style="color: #000000;">&#41;</span> <span style="color: #ff0033; font-weight: bold;">then</span>
            notify <span style="color: #ff0033; font-weight: bold;">with</span> <span style="color: #0066ff;">name</span> <span style="color: #009900;">&quot;Song Info&quot;</span> title txt description trkInfo <span style="color: #0066ff;">application</span> <span style="color: #0066ff;">name</span> <span style="color: #009900;">&quot;Hotkey iTunes Notification&quot;</span>
        <span style="color: #ff0033; font-weight: bold;">else</span>
            notify <span style="color: #ff0033; font-weight: bold;">with</span> <span style="color: #0066ff;">name</span> <span style="color: #009900;">&quot;Song Info&quot;</span> title txt description trkInfo <span style="color: #0066ff;">application</span> <span style="color: #0066ff;">name</span> <span style="color: #009900;">&quot;Hotkey iTunes Notification&quot;</span> pictImage <span style="color: #ff0033;">the</span> trkArt
        <span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">if</span>
    <span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">tell</span>
<span style="color: #ff0033; font-weight: bold;">end</span> showQSNotify
&nbsp;
<span style="color: #ff0033; font-weight: bold;">on</span> showTrackInfo<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
    <span style="color: #ff0033; font-weight: bold;">try</span>
        <span style="color: #ff0033; font-weight: bold;">tell</span> <span style="color: #0066ff;">application</span> <span style="color: #009900;">&quot;GrowlTunes&quot;</span>
            show current track
        <span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">tell</span>
    <span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">try</span>
<span style="color: #ff0033; font-weight: bold;">end</span> showTrackInfo
&nbsp;
<span style="color: #ff0033; font-weight: bold;">on</span> getTimeString<span style="color: #000000;">&#40;</span>secs<span style="color: #000000;">&#41;</span>
    <span style="color: #ff0033; font-weight: bold;">set</span> no_seconds <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #ff0033;">the</span> secs <span style="color: #ff0033;">as</span> <span style="color: #0066ff;">number</span>
    <span style="color: #ff0033; font-weight: bold;">set</span> no_minutes <span style="color: #ff0033; font-weight: bold;">to</span> no_seconds <span style="color: #ff0033;">div</span> <span style="color: #000000;">60</span>
    <span style="color: #ff0033; font-weight: bold;">set</span> no_seconds <span style="color: #ff0033; font-weight: bold;">to</span> no_seconds <span style="color: #ff0033;">mod</span> <span style="color: #000000;">60</span>
    <span style="color: #ff0033; font-weight: bold;">if</span> no_seconds <span style="color: #000000;">&lt;</span> <span style="color: #000000;">10</span> <span style="color: #ff0033; font-weight: bold;">then</span>
        <span style="color: #ff0033; font-weight: bold;">set</span> seconds_text <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #009900;">&quot;0&quot;</span> <span style="color: #000000;">&amp;</span> <span style="color: #000000;">&#40;</span>no_seconds <span style="color: #ff0033;">as</span> <span style="color: #0066ff;">string</span><span style="color: #000000;">&#41;</span>
    <span style="color: #ff0033; font-weight: bold;">else</span>
        <span style="color: #ff0033; font-weight: bold;">set</span> seconds_text <span style="color: #ff0033; font-weight: bold;">to</span> no_seconds <span style="color: #ff0033;">as</span> <span style="color: #0066ff;">string</span>
    <span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">if</span>
    <span style="color: #ff0033; font-weight: bold;">if</span> no_minutes ≥ <span style="color: #000000;">60</span> <span style="color: #ff0033; font-weight: bold;">then</span>
        <span style="color: #ff0033; font-weight: bold;">set</span> no_hours <span style="color: #ff0033; font-weight: bold;">to</span> no_minutes <span style="color: #ff0033;">div</span> <span style="color: #000000;">60</span>
        <span style="color: #ff0033; font-weight: bold;">set</span> no_minutes <span style="color: #ff0033; font-weight: bold;">to</span> no_minutes <span style="color: #ff0033;">mod</span> <span style="color: #000000;">60</span>
        <span style="color: #ff0033; font-weight: bold;">if</span> no_minutes <span style="color: #000000;">&lt;</span> <span style="color: #000000;">10</span> <span style="color: #ff0033; font-weight: bold;">then</span>
            <span style="color: #ff0033; font-weight: bold;">set</span> no_minutes <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #009900;">&quot;0&quot;</span> <span style="color: #000000;">&amp;</span> <span style="color: #000000;">&#40;</span>no_minutes <span style="color: #ff0033;">as</span> <span style="color: #0066ff;">string</span><span style="color: #000000;">&#41;</span>
        <span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">if</span>
        <span style="color: #ff0033; font-weight: bold;">set</span> minutes_text <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #000000;">&#40;</span>no_hours <span style="color: #ff0033;">as</span> <span style="color: #0066ff;">string</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&amp;</span> <span style="color: #009900;">&quot;:&quot;</span> <span style="color: #000000;">&amp;</span> <span style="color: #000000;">&#40;</span>no_minutes <span style="color: #ff0033;">as</span> <span style="color: #0066ff;">string</span><span style="color: #000000;">&#41;</span>
    <span style="color: #ff0033; font-weight: bold;">else</span>
        <span style="color: #ff0033; font-weight: bold;">set</span> minutes_text <span style="color: #ff0033; font-weight: bold;">to</span> no_minutes <span style="color: #ff0033;">as</span> <span style="color: #0066ff;">string</span>
    <span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">if</span>
&nbsp;
    <span style="color: #ff0033; font-weight: bold;">return</span> minutes_text <span style="color: #000000;">&amp;</span> <span style="color: #009900;">&quot;:&quot;</span> <span style="color: #000000;">&amp;</span> seconds_text
<span style="color: #ff0033; font-weight: bold;">end</span> getTimeString</pre></div></div>



<p>
<a href="http://www.cneophytou.com/wp-content/uploads/2007/07/notifications.scpt">Download this script</a><br />
<br />
That&#8217;s pretty much it&#8230; Enjoy!]]></content:encoded>
			<wfw:commentRss>http://www.cneophytou.com/2007/07/24/itunes-scripts-i-cant-live-without/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Share Windows XP license between Parallels and Boot Camp</title>
		<link>http://www.cneophytou.com/2007/07/18/share-windows-xp-license-between-parallels-and-boot-camp/</link>
		<comments>http://www.cneophytou.com/2007/07/18/share-windows-xp-license-between-parallels-and-boot-camp/#comments</comments>
		<pubDate>Tue, 17 Jul 2007 19:46:40 +0000</pubDate>
		<dc:creator>Constantinos</dc:creator>
				<category><![CDATA[OS X]]></category>
		<category><![CDATA[Windows]]></category>
		<category><![CDATA[Boot Camp]]></category>
		<category><![CDATA[Parallels]]></category>

		<guid isPermaLink="false">http://www.cneophytou.com/2007/07/18/share-windows-xp-license-in-parallels-and-boot-camp/</guid>
		<description><![CDATA[Since my first installation of Boot Camp and Parallels, I&#8217;ve kept two separate Windows XP installations on my drive. One on Boot Camp, used for gaming and other resource-intensive tasks, and the other exclusively on Parallels, used for running some random software I come across and also to test the websites I build in IE. [...]]]></description>
			<content:encoded><![CDATA[Since my first installation of <a href='http://www.apple.com/bootcamp/'>Boot Camp</a> and <a href='http://www.parallels.com/'>Parallels</a>, I&#8217;ve kept two separate Windows XP installations on my drive. One on Boot Camp, used for gaming and other resource-intensive tasks, and the other exclusively on Parallels, used for running some random software I come across and also to test the websites I build in IE. The reason I&#8217;ve been doing this is because even though Parallels touts being able to <a href='http://lifehacker.com/software/geek-to-live/virtualize-and-dual+boot-the-same-windows-on-your-mac-267905.php'>run a boot camped windows installation</a> [via <a href='http://www.lifehacker.com'>lifehacker</a>], you can&#8217;t do BOTH (at least not off the shelf). You have a Boot Camp installation that you either run through Parallels, or by itself. The reason for this is that Parallels has to create a new hardware profile which XP picks up as a different machine, and invalidates your installation.<br />
<br />
<span id="more-95"></span>
No matter how much I searched I couldn&#8217;t find a way to use the same installation under both circumstances. Thus, when Parallels 3 came out I immediately paid for the upgrade (even before the release) for the much promised &#8217;3D&#8217; support, which, I believed, would enable me to play at least some of my games under Parallels, thus relatively eliminating the need to boot into XP. Alas, as most others, I was frustrated to find out that Parallels&#8217; so-called 3D support was actually marginal support for DirectX 8.1, and absolutely NO support for DX9 or greater.<br />
<br />
After all but giving up hope, I came across <a href='http://lifehacker.com/software/geek-to-live/virtualize-and-dual+boot-the-same-windows-on-your-mac-267905.php#c1816617'>this comment</a> on the afore-mentioned lifehacker post, which pointed me to a <a href='http://forum.parallels.com/showthread.php?t=13394'>Parallels&#8217; forum thread</a>. To cut a long story short, I am now able to boot the same Boot Camp installation of XP both directly AND via Parallels without having WGA complain and invalidate my copy!<br />
<br />
The process (reiterated from the above thread), is very simple:<br />
</p>
<ol>
<li>Find the MAC address of your Apples&#8217;s &#8220;en0&#8243; adaptor. To do that, either:<ul><li>Open Terminal.app and type <code>ifconfig en0</code>, the MAC address should be located on the line that says &#8220;ether 00:00:00:00:00:00&#8243;, where &#8217;00:00:00:00:00:00&#8242; would be the code you&#8217;re looking for</li><li>OR open &#8220;System Preferences&#8221;, click on the &#8220;Network&#8221; icon, from the &#8220;show&#8221; drop down select &#8220;Built-in Ethernet&#8221;, click the &#8220;Ethernet&#8221; tab, and the MAC address should be listed under &#8216;Ethernet ID:&#8217;</li></ul></li>
<li>Start up Parallels and select your Boot Camp installation (do NOT start the virtual machine)</li>
<li>Go to &#8220;Edit&#8221;/&#8221;Virtual Machine&#8221;</li>
<li>Select &#8220;Network Adapter 1&#8243; on the left, and the &#8220;Advanced&#8221; tab on the right</li>
<li>In the &#8220;MAC address&#8221; field replace the entry with the MAC address of en0 which you lifted above, minus the colons.</li>
</ol>
<p>
<br />
That&#8217;s it! No more complaining by that damned WGA <img src='http://www.cneophytou.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />]]></content:encoded>
			<wfw:commentRss>http://www.cneophytou.com/2007/07/18/share-windows-xp-license-between-parallels-and-boot-camp/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Automating backup of Flash drives</title>
		<link>http://www.cneophytou.com/2007/03/06/automating-backup-of-flash-drives/</link>
		<comments>http://www.cneophytou.com/2007/03/06/automating-backup-of-flash-drives/#comments</comments>
		<pubDate>Mon, 05 Mar 2007 21:32:26 +0000</pubDate>
		<dc:creator>Constantinos</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[OS X]]></category>
		<category><![CDATA[Applescript]]></category>
		<category><![CDATA[CC Licence]]></category>
		<category><![CDATA[Folder Actions]]></category>

		<guid isPermaLink="false">http://www.cneophytou.com/2007/03/06/automating-backup-of-flash-drives/</guid>
		<description><![CDATA[I have a lot of my critical work on a few flash drives which I carry around with me constantly, mainly because I work on a number of machines and would like to have a central repository of my work. After losing one of the drives recently though (bound to happen sooner or later), I [...]]]></description>
			<content:encoded><![CDATA[I have a lot of my critical work on a few flash drives which I carry around with me constantly, mainly because I work on a number of machines and would like to have a central repository of my work. After losing one of the drives recently though (bound to happen sooner or later), I looked further into automating the backup process (I had lost about 2 days of work). That&#8217;s when I stumbled accross <a href='http://www.macosxhints.com/article.php?story=2007022112171245'>this hint</a> on <a href='http://www.macosxhints.com/'>macosxhints.com</a>, but the script didn&#8217;t exactly fulfil what I had imagined my automated process to do.<br />
<br />
Ideally, the automated backup process would have these features:</p>
<ol>
<li>Not require installation of any third party app</li>
<li>Have the ability to somewhat customize the backup script for each thumb drive</li>
<li>Have the backup script silently run whenever the thumb drive is mounted</li>
<li>Require little to no set up for each new thumb drive that I want to backup</li>
<li>Support spaces in Volume names</li>
<li>Not try to backup the boot drive under any circumstances (don&#8217;t ask&#8230;)</li>
</ol>
<p><span class='update'>Updated 2007-03-10:</span> I updated the backup script to include automated handling of archives, and keeps an arbitrary number (specified in the preferences of the script) of incremental archives using rsync's <code>--link-dest</code> parameter, as recommended by John in the comments. This creates what functionally amounts to FULL backups, but with a fraction of the space needed for an actual <code>tar</code> backup. Also it can be configured to keep at most one backup per day, or with minor editing at most one backup for any period of time.</p>
<p><span class='update'>Updated 2007-03-18:</span> I've created a second script which can be used as a drag-n-drop solution. Simply save the script as an application bundle, save it somewhere handy, and drag it to your dock. Now you can drag your thumb drive on the script which will perform the backup, and then eject your drive!</p>
<p><span class='update'>Updated 2008-03-10:</span> Folder action modified to work with Leopard. Well, more like hacked at this point, but it seems to work.</p>
<p>
<span id="more-85"></span>
<br />
Now to satisfy the first parameter, using <a href='http://www.azarhi.com/Projects/DSW/index.php'>Do Something When</a> was out of the question, even though it seems like a good piece of software. That&#8217;s when I turned to Fodler Actions, and found <a href='http://www.macosxhints.com/article.php?story=2007011207351342'>this hint</a> again on macosxhints.com. I then proceeded to read the <a href='http://www.apple.com/applescript/folderactions/05.html'>Apple-published Folder Action</a> for automating backups (which, again, didn&#8217;t do quite what I wanted), so I came up with this:<br />
<br />
A folder action that scans the root folder of the mounted volume, and looks for (one of) a specified file name.</p>


<div class="wp_syntax"><div class="code"><pre class="applescript" style="font-family:monospace;"><span style="color: #ff0033; font-weight: bold;">property</span> backup_script : <span style="color: #009900;">&quot;rsync.app&quot;</span> <span style="color: #808080; font-style: italic;">(* add/change this string to match the name of your script *)</span>
&nbsp;
<span style="color: #ff0033; font-weight: bold;">on</span> <span style="color: #0066ff;">adding</span> <span style="color: #0066ff;">folder</span> <span style="color: #0066ff;">items</span> <span style="color: #ff0033; font-weight: bold;">to</span> this_folder <span style="color: #ff0033;">after</span> <span style="color: #0066ff;">receiving</span> these_volumes
    <span style="color: #ff0033; font-weight: bold;">tell</span> <span style="color: #0066ff;">application</span> <span style="color: #009900;">&quot;Finder&quot;</span>
        <span style="color: #ff0033; font-weight: bold;">try</span>
            <span style="color: #ff0033; font-weight: bold;">set</span> <span style="color: #ff0033;">the</span> volume_list <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #ff0033;">every</span> <span style="color: #0066ff;">file</span> <span style="color: #ff0033; font-weight: bold;">of</span> this_folder
&nbsp;
            <span style="color: #808080; font-style: italic;">(* go through all entries in /Volumes/ *)</span>
            <span style="color: #ff0033; font-weight: bold;">repeat</span> <span style="color: #ff0033; font-weight: bold;">with</span> i <span style="color: #ff0033; font-weight: bold;">from</span> <span style="color: #000000;">1</span> <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #0066ff;">number</span> <span style="color: #ff0033; font-weight: bold;">of</span> <span style="color: #0066ff;">items</span> <span style="color: #ff0033; font-weight: bold;">in</span> volume_list
                <span style="color: #ff0033; font-weight: bold;">set</span> this_item <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #ff0033;">the</span> original <span style="color: #0066ff;">item</span> <span style="color: #ff0033; font-weight: bold;">of</span> <span style="color: #0066ff;">item</span> i <span style="color: #ff0033; font-weight: bold;">of</span> volume_list
                <span style="color: #ff0033; font-weight: bold;">if</span> <span style="color: #ff0033;">the</span> kind <span style="color: #ff0033; font-weight: bold;">of</span> this_item <span style="color: #ff0033; font-weight: bold;">is</span> <span style="color: #009900;">&quot;Volume&quot;</span> <span style="color: #ff0033; font-weight: bold;">then</span>
                    <span style="color: #ff0033; font-weight: bold;">set</span> this_disk <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #000000;">&#40;</span>this_item <span style="color: #ff0033;">as</span> <span style="color: #0066ff;">alias</span><span style="color: #000000;">&#41;</span>
&nbsp;
                    <span style="color: #808080; font-style: italic;">(* is this item the newly mounted disk? *)</span>
                    <span style="color: #ff0033; font-weight: bold;">if</span> this_disk <span style="color: #ff0033; font-weight: bold;">is</span> <span style="color: #ff0033; font-weight: bold;">in</span> these_volumes <span style="color: #ff0033; font-weight: bold;">then</span>
&nbsp;
                        <span style="color: #808080; font-style: italic;">(* iterate through all files in the root of disk *)</span>
                        <span style="color: #ff0033; font-weight: bold;">set</span> searchCmd <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #009900;">&quot;ls -d &quot;</span> <span style="color: #000000;">&amp;</span> <span style="color: #0066ff;">quoted form</span> <span style="color: #ff0033; font-weight: bold;">of</span> <span style="color: #0066ff;">POSIX path</span> <span style="color: #ff0033; font-weight: bold;">of</span> this_disk <span style="color: #000000;">&amp;</span> backup_script
                        <span style="color: #808080; font-style: italic;">(* check to see if a backup script is available *)</span>
                        <span style="color: #ff0033; font-weight: bold;">set</span> searchResult <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #009900;">&quot;&quot;</span>
                        <span style="color: #ff0033; font-weight: bold;">try</span>
                            <span style="color: #ff0033; font-weight: bold;">set</span> searchResult <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #0066ff;">do shell script</span> searchCmd
                        <span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">try</span>
                        <span style="color: #808080; font-style: italic;">(* run the backup script *)</span>
                        <span style="color: #ff0033; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>searchResult starts <span style="color: #ff0033; font-weight: bold;">with</span> <span style="color: #009900;">&quot;/Volumes&quot;</span><span style="color: #000000;">&#41;</span> <span style="color: #ff0033; font-weight: bold;">then</span>
                            <span style="color: #ff0033; font-weight: bold;">set</span> backupFile <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #0066ff;">POSIX file</span> searchResult <span style="color: #ff0033;">as</span> <span style="color: #0066ff;">alias</span>
                            <span style="color: #0066ff;">open</span> backupFile
                        <span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">if</span>
&nbsp;
                    <span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">if</span>
                <span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">if</span>
            <span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">repeat</span>
        <span style="color: #ff0033; font-weight: bold;">on</span> <span style="color: #ff0033; font-weight: bold;">error</span> error_message <span style="color: #0066ff;">number</span> error_number
            <span style="color: #ff0033; font-weight: bold;">if</span> <span style="color: #ff0033;">the</span> error_number <span style="color: #ff0033; font-weight: bold;">is</span> <span style="color: #ff0033;">not</span> <span style="color: #000000;">-</span><span style="color: #000000;">128</span> <span style="color: #ff0033; font-weight: bold;">then</span>
                <span style="color: #0066ff;">display dialog</span> error_message <span style="color: #0066ff;">buttons</span> <span style="color: #000000;">&#123;</span><span style="color: #009900;">&quot;OK&quot;</span><span style="color: #000000;">&#125;</span> default button <span style="color: #000000;">1</span>
            <span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">if</span>
        <span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">try</span>
    <span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">tell</span>
<span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #0066ff;">adding</span> <span style="color: #0066ff;">folder</span> <span style="color: #0066ff;">items</span> <span style="color: #ff0033; font-weight: bold;">to</span></pre></div></div>



<p>
<a href="http://www.cneophytou.com/wp-content/uploads/2007/03/auto_backup.scpt">Download this script</a><br />
<br />
If you already know how to apply folder actions, just save the script above and apply it as a folder action to the <code>/Volumes/</code> folder. If you don&#8217;t know (or don&#8217;t remember) how to do that, re-iterating the instructions from <a href='http://www.apple.com/applescript/folderactions/05.html'>this Apple page</a>, follow these steps to do it:</p>
<ol>
<li>Copy the above code in Script Editor</li>
<li>Save it as a script in <code>/Library/Scripts/Folder Action Scripts/</code>, and give it a descriptive name</li>
<li>In Finder, click <strong>Go</strong> -> <strong>Go to Folder</strong> (or just press cmd-shift-G), and type <code>/Volumes/</code>.</li>
<li>Launch the <code>Folder Actions Setup</code> utility (probably located in <code>/Applications/Apple Script/</code> folder)</li>
<li>Click the Add Folder Action (round plus) button at the bottom left</li>
<li>Drag the small folder icon from the Finder window title bar into the Choose Folder sheet dialog, and click ok.</li>
<li>From the dialog that comes up, chose the script you just saved.</li>
<li>You&#8217;re done.</li>
</ol>
<p>
Alternatively (or additionally), you can save this script as an application bundle, save it somewhere handy, and drag it to your dock. When you drag a thumb drive on this application the backup process will start, and as soon as it's done the drive will eject.
</p>


<div class="wp_syntax"><div class="code"><pre class="applescript" style="font-family:monospace;"><span style="color: #ff0033; font-weight: bold;">property</span> backup_script : <span style="color: #009900;">&quot;rsync&quot;</span> <span style="color: #808080; font-style: italic;">(* add/change this to match the name of your script *)</span>
&nbsp;
<span style="color: #ff0033; font-weight: bold;">on</span> <span style="color: #0066ff;">open</span> dropped_item
    <span style="color: #ff0033; font-weight: bold;">set</span> this_vol_alias <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #000000;">&#40;</span>dropped_item <span style="color: #ff0033;">as</span> <span style="color: #0066ff;">alias</span><span style="color: #000000;">&#41;</span>
    <span style="color: #ff0033; font-weight: bold;">try</span>
        <span style="color: #ff0033; font-weight: bold;">tell</span> <span style="color: #0066ff;">application</span> <span style="color: #009900;">&quot;Finder&quot;</span>
            <span style="color: #ff0033; font-weight: bold;">if</span> <span style="color: #ff0033;">the</span> kind <span style="color: #ff0033; font-weight: bold;">of</span> this_vol_alias <span style="color: #ff0033; font-weight: bold;">is</span> <span style="color: #009900;">&quot;Volume&quot;</span> <span style="color: #ff0033; font-weight: bold;">then</span>
                <span style="color: #ff0033; font-weight: bold;">set</span> <span style="color: #ff0033;">the</span> file_list <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #ff0033;">every</span> <span style="color: #0066ff;">file</span> <span style="color: #ff0033; font-weight: bold;">of</span> this_vol_alias
                <span style="color: #ff0033; font-weight: bold;">repeat</span> <span style="color: #ff0033; font-weight: bold;">with</span> j <span style="color: #ff0033; font-weight: bold;">from</span> <span style="color: #000000;">1</span> <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #0066ff;">number</span> <span style="color: #ff0033; font-weight: bold;">of</span> <span style="color: #0066ff;">items</span> <span style="color: #ff0033; font-weight: bold;">in</span> file_list
                    <span style="color: #808080; font-style: italic;">(* check to see if a backup script is available *)</span>
                    <span style="color: #ff0033; font-weight: bold;">set</span> this_file <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #0066ff;">name</span> <span style="color: #ff0033; font-weight: bold;">of</span> <span style="color: #0066ff;">item</span> j <span style="color: #ff0033; font-weight: bold;">of</span> file_list
                    <span style="color: #ff0033; font-weight: bold;">if</span> this_file <span style="color: #ff0033; font-weight: bold;">is</span> <span style="color: #ff0033;">equal</span> <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #000000;">&#40;</span>backup_script <span style="color: #000000;">&amp;</span> <span style="color: #009900;">&quot;.app&quot;</span><span style="color: #000000;">&#41;</span> <span style="color: #ff0033; font-weight: bold;">then</span>
                        <span style="color: #0066ff;">open</span> <span style="color: #0066ff;">item</span> j <span style="color: #ff0033; font-weight: bold;">of</span> file_list <span style="color: #808080; font-style: italic;">(* run the backup script *)</span>
                    <span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">if</span>
                <span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">repeat</span>
            <span style="color: #ff0033; font-weight: bold;">else</span>
                display alert <span style="color: #009900;">&quot;This script can only be executed on volumes&quot;</span>
                <span style="color: #ff0033; font-weight: bold;">return</span>
            <span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">if</span>
        <span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">tell</span>
&nbsp;
        delay <span style="color: #000000;">2</span> <span style="color: #808080; font-style: italic;">(* give some time for the backup script to actually launch *)</span>
        <span style="color: #ff0033; font-weight: bold;">tell</span> <span style="color: #0066ff;">application</span> <span style="color: #009900;">&quot;Finder&quot;</span>
            <span style="color: #ff0033; font-weight: bold;">try</span>
                <span style="color: #ff0033; font-weight: bold;">set</span> bakapp <span style="color: #ff0033; font-weight: bold;">to</span> creator type <span style="color: #ff0033; font-weight: bold;">of</span> process backup_script
                <span style="color: #ff0033; font-weight: bold;">repeat</span> <span style="color: #ff0033; font-weight: bold;">while</span> bakapp <span style="color: #ff0033; font-weight: bold;">is</span> <span style="color: #ff0033;">not</span> <span style="color: #ff0033;">equal</span> <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #009900;">&quot;&quot;</span>
                    delay <span style="color: #000000;">1</span> <span style="color: #808080; font-style: italic;">(* the backup is still running, we can check again in a second *)</span>
                    <span style="color: #ff0033; font-weight: bold;">set</span> bakapp <span style="color: #ff0033; font-weight: bold;">to</span> creator type <span style="color: #ff0033; font-weight: bold;">of</span> process backup_script
                <span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">repeat</span>
            <span style="color: #ff0033; font-weight: bold;">on</span> <span style="color: #ff0033; font-weight: bold;">error</span>
                <span style="color: #ff0033; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>ejectable <span style="color: #ff0033; font-weight: bold;">of</span> this_vol_alias <span style="color: #ff0033; font-weight: bold;">is</span> <span style="color: #0066ff;">true</span><span style="color: #000000;">&#41;</span> <span style="color: #ff0033; font-weight: bold;">then</span>
                    <span style="color: #808080; font-style: italic;">(* display alert POSIX path of dropped_item *)</span>
                    <span style="color: #0066ff;">eject</span> this_vol_alias
                <span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">if</span>
            <span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">try</span>
        <span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">tell</span>
&nbsp;
    <span style="color: #ff0033; font-weight: bold;">on</span> <span style="color: #ff0033; font-weight: bold;">error</span> error_message <span style="color: #0066ff;">number</span> error_number
        <span style="color: #ff0033; font-weight: bold;">if</span> <span style="color: #ff0033;">the</span> error_number <span style="color: #ff0033; font-weight: bold;">is</span> <span style="color: #ff0033;">not</span> <span style="color: #000000;">-</span><span style="color: #000000;">128</span> <span style="color: #ff0033; font-weight: bold;">then</span>
            <span style="color: #0066ff;">display dialog</span> error_message <span style="color: #0066ff;">buttons</span> <span style="color: #000000;">&#123;</span><span style="color: #009900;">&quot;OK&quot;</span><span style="color: #000000;">&#125;</span> default button <span style="color: #000000;">1</span>
        <span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">if</span>
    <span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">try</span>
<span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #0066ff;">open</span></pre></div></div>



<p>
<a href="http://www.cneophytou.com/wp-content/uploads/2007/03/auto_backup.zip">Download this script</a><br />
<br />
Now, for the modified backup script. The properties at the top can be modified on a per copy basis to customize the function of the script.</p>


<div class="wp_syntax"><div class="code"><pre class="applescript" style="font-family:monospace;"><span style="color: #ff0033; font-weight: bold;">property</span> archive_backup : <span style="color: #0066ff;">true</span>
<span style="color: #ff0033; font-weight: bold;">property</span> number_of_archives : <span style="color: #000000;">3</span> <span style="color: #808080; font-style: italic;">(* 0 for unlimited *)</span>
<span style="color: #ff0033; font-weight: bold;">property</span> with_administrator_privileges : <span style="color: #0066ff;">false</span>
<span style="color: #ff0033; font-weight: bold;">property</span> one_archive_per_day : <span style="color: #0066ff;">true</span>
&nbsp;
<span style="color: #ff0033; font-weight: bold;">property</span> display_notification : <span style="color: #0066ff;">false</span>
<span style="color: #ff0033; font-weight: bold;">property</span> backup_target : <span style="color: #009900;">&quot;Backups/&quot;</span> <span style="color: #808080; font-style: italic;">(* MUST be a folder location with trailing slash! Always relative to home folder *)</span>
&nbsp;
<span style="color: #ff0033; font-weight: bold;">property</span> rsync_params : <span style="color: #009900;">&quot;-aEz --delete-excluded&quot;</span>
<span style="color: #808080; font-style: italic;">(* END OF PREFERENCES *)</span>
&nbsp;
<span style="color: #ff0033; font-weight: bold;">set</span> WhereImRunningFrom <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #0066ff;">path to</span> <span style="color: #0066ff;">me</span>
<span style="color: #ff0033; font-weight: bold;">tell</span> <span style="color: #0066ff;">application</span> <span style="color: #009900;">&quot;Finder&quot;</span>
    <span style="color: #808080; font-style: italic;">(* can't run from the script editor *)</span>
    <span style="color: #ff0033; font-weight: bold;">set</span> AppCreator <span style="color: #ff0033; font-weight: bold;">to</span> creator type <span style="color: #ff0033; font-weight: bold;">of</span> WhereImRunningFrom
    <span style="color: #ff0033; font-weight: bold;">if</span> AppCreator <span style="color: #ff0033; font-weight: bold;">is</span> <span style="color: #009900;">&quot;ToyS&quot;</span> <span style="color: #ff0033; font-weight: bold;">then</span>
        <span style="color: #0066ff;">activate</span> <span style="color: #ff0033; font-weight: bold;">of</span> <span style="color: #0066ff;">me</span>
        <span style="color: #0066ff;">beep</span>
        display alert <span style="color: #009900;">&quot;This script cannot run directly from ScriptEditor&quot;</span>
        <span style="color: #ff0033; font-weight: bold;">return</span>
    <span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">if</span>
&nbsp;
    <span style="color: #808080; font-style: italic;">(* NEVER run from the hard drive! *)</span>
    <span style="color: #ff0033; font-weight: bold;">set</span> bootVolume <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #0066ff;">name</span> <span style="color: #ff0033; font-weight: bold;">of</span> <span style="color: #0066ff;">disk</span> <span style="color: #ff0033; font-weight: bold;">of</span> home <span style="color: #808080; font-style: italic;">(* safety feature! *)</span>
    <span style="color: #ff0033; font-weight: bold;">set</span> NameOfDisk <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #0066ff;">name</span> <span style="color: #ff0033; font-weight: bold;">of</span> <span style="color: #0066ff;">disk</span> <span style="color: #ff0033; font-weight: bold;">of</span> WhereImRunningFrom
    <span style="color: #ff0033; font-weight: bold;">if</span> NameOfDisk <span style="color: #ff0033; font-weight: bold;">is</span> bootVolume <span style="color: #ff0033; font-weight: bold;">then</span>
        <span style="color: #0066ff;">beep</span>
        display alert <span style="color: #009900;">&quot;Should not run this script from the boot volume!&quot;</span>
        <span style="color: #ff0033; font-weight: bold;">return</span>
    <span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">if</span>
&nbsp;
    <span style="color: #808080; font-style: italic;">(* setup backup dir *)</span>
    <span style="color: #ff0033; font-weight: bold;">set</span> homeDir <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #0066ff;">path to</span> home <span style="color: #0066ff;">folder</span> <span style="color: #ff0033; font-weight: bold;">from</span> user domain
    <span style="color: #ff0033; font-weight: bold;">set</span> backup_folder <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #0066ff;">POSIX path</span> <span style="color: #ff0033; font-weight: bold;">of</span> homeDir <span style="color: #000000;">&amp;</span> backup_target
    <span style="color: #ff0033; font-weight: bold;">try</span>
        <span style="color: #808080; font-style: italic;">(* quick and dirty check to see if folder exists - must be a good way to do this in applescript? *)</span>
        <span style="color: #0066ff;">do shell script</span> <span style="color: #009900;">&quot;cd &quot;</span> <span style="color: #000000;">&amp;</span> backup_folder
    <span style="color: #ff0033; font-weight: bold;">on</span> <span style="color: #ff0033; font-weight: bold;">error</span>
        <span style="color: #ff0033; font-weight: bold;">try</span>
            <span style="color: #0066ff;">do shell script</span> <span style="color: #009900;">&quot;mkdir &quot;</span> <span style="color: #000000;">&amp;</span> backup_folder
        <span style="color: #ff0033; font-weight: bold;">on</span> <span style="color: #ff0033; font-weight: bold;">error</span>
            display alert <span style="color: #009900;">&quot;There was an error creating the backup folder &quot;</span> <span style="color: #000000;">&amp;</span> backup_folder
            <span style="color: #ff0033; font-weight: bold;">return</span>
        <span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">try</span>
    <span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">try</span>
&nbsp;
    <span style="color: #808080; font-style: italic;">(* find source and target *)</span>
    <span style="color: #ff0033; font-weight: bold;">set</span> backupBase <span style="color: #ff0033; font-weight: bold;">to</span> NameOfDisk <span style="color: #000000;">&amp;</span> <span style="color: #009900;">&quot;-Backup&quot;</span>
    <span style="color: #ff0033; font-weight: bold;">set</span> targetDir <span style="color: #ff0033; font-weight: bold;">to</span> backup_folder <span style="color: #000000;">&amp;</span> <span style="color: #0066ff;">quoted form</span> <span style="color: #ff0033; font-weight: bold;">of</span> backupBase
    <span style="color: #ff0033; font-weight: bold;">set</span> sourceDir <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #0066ff;">quoted form</span> <span style="color: #ff0033; font-weight: bold;">of</span> <span style="color: #000000;">&#40;</span><span style="color: #009900;">&quot;/Volumes/&quot;</span> <span style="color: #000000;">&amp;</span> NameOfDisk <span style="color: #000000;">&amp;</span> <span style="color: #009900;">&quot;/&quot;</span><span style="color: #000000;">&#41;</span>
&nbsp;
    <span style="color: #808080; font-style: italic;">(* set up archive filename *)</span>
    <span style="color: #ff0033; font-weight: bold;">if</span> archive_backup <span style="color: #ff0033; font-weight: bold;">then</span>
        <span style="color: #ff0033; font-weight: bold;">set</span> thedate <span style="color: #ff0033; font-weight: bold;">to</span> current date
        <span style="color: #ff0033; font-weight: bold;">set</span> theday <span style="color: #ff0033; font-weight: bold;">to</span> day <span style="color: #ff0033; font-weight: bold;">of</span> thedate
        <span style="color: #ff0033; font-weight: bold;">set</span> themonth <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #0066ff;">month</span> <span style="color: #ff0033; font-weight: bold;">of</span> thedate
        <span style="color: #ff0033; font-weight: bold;">set</span> theyear <span style="color: #ff0033; font-weight: bold;">to</span> year <span style="color: #ff0033; font-weight: bold;">of</span> thedate
        <span style="color: #ff0033; font-weight: bold;">set</span> thetime <span style="color: #ff0033; font-weight: bold;">to</span> time <span style="color: #ff0033; font-weight: bold;">of</span> thedate
&nbsp;
        <span style="color: #ff0033; font-weight: bold;">set</span> thedate <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #009900;">&quot;-&quot;</span> <span style="color: #000000;">&amp;</span> theyear <span style="color: #000000;">&amp;</span> <span style="color: #009900;">&quot;-&quot;</span> <span style="color: #000000;">&amp;</span> shortMonth<span style="color: #000000;">&#40;</span>themonth<span style="color: #000000;">&#41;</span> <span style="color: #ff0033; font-weight: bold;">of</span> <span style="color: #0066ff;">me</span> <span style="color: #000000;">&amp;</span> <span style="color: #009900;">&quot;-&quot;</span> <span style="color: #000000;">&amp;</span> theday <span style="color: #ff0033;">as</span> <span style="color: #0066ff;">string</span>
        <span style="color: #ff0033; font-weight: bold;">if</span> <span style="color: #ff0033;">not</span> one_archive_per_day <span style="color: #ff0033; font-weight: bold;">then</span> <span style="color: #ff0033; font-weight: bold;">set</span> thedate <span style="color: #ff0033; font-weight: bold;">to</span> thedate <span style="color: #000000;">&amp;</span> <span style="color: #009900;">&quot;-&quot;</span> <span style="color: #000000;">&amp;</span> thetime <span style="color: #ff0033;">as</span> <span style="color: #0066ff;">string</span>
&nbsp;
        <span style="color: #ff0033; font-weight: bold;">set</span> backupFolder <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #0066ff;">quoted form</span> <span style="color: #ff0033; font-weight: bold;">of</span> <span style="color: #000000;">&#40;</span>backup_folder <span style="color: #000000;">&amp;</span> backupBase <span style="color: #000000;">&amp;</span> thedate  <span style="color: #000000;">&amp;</span> <span style="color: #009900;">&quot;/&quot;</span><span style="color: #000000;">&#41;</span>
    <span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">if</span>
<span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">tell</span>
&nbsp;
<span style="color: #808080; font-style: italic;">(* do the backup *)</span>
<span style="color: #808080; font-style: italic;">(* try *)</span>
<span style="color: #ff0033; font-weight: bold;">if</span> with_administrator_privileges <span style="color: #ff0033; font-weight: bold;">then</span>
    <span style="color: #ff0033; font-weight: bold;">set</span> excluded <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #009900;">&quot; &quot;</span>
<span style="color: #ff0033; font-weight: bold;">else</span>
    <span style="color: #ff0033; font-weight: bold;">set</span> excluded <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #009900;">&quot; --exclude='.Trash*' --exclude='.Spotlight*'  &quot;</span>
<span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">if</span>
&nbsp;
<span style="color: #ff0033; font-weight: bold;">if</span> archive_backup <span style="color: #ff0033; font-weight: bold;">then</span>
    <span style="color: #ff0033; font-weight: bold;">set</span> posixDir <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #0066ff;">POSIX file</span> backup_folder
    <span style="color: #ff0033; font-weight: bold;">set</span> fileList <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #0066ff;">list</span> <span style="color: #0066ff;">folder</span> posixDir
    <span style="color: #ff0033; font-weight: bold;">set</span> archiveList <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #000000;">&#123;</span><span style="color: #000000;">&#125;</span>
    <span style="color: #ff0033; font-weight: bold;">tell</span> <span style="color: #0066ff;">application</span> <span style="color: #009900;">&quot;Finder&quot;</span>
        <span style="color: #808080; font-style: italic;">(* Search for existing backups *)</span>
        <span style="color: #ff0033; font-weight: bold;">repeat</span> <span style="color: #ff0033; font-weight: bold;">with</span> i <span style="color: #ff0033; font-weight: bold;">from</span> <span style="color: #000000;">1</span> <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #0066ff;">number</span> <span style="color: #ff0033; font-weight: bold;">of</span> <span style="color: #0066ff;">items</span> <span style="color: #ff0033; font-weight: bold;">in</span> fileList
            <span style="color: #ff0033; font-weight: bold;">set</span> thisFile <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #0066ff;">item</span> i <span style="color: #ff0033; font-weight: bold;">of</span> fileList
            <span style="color: #ff0033; font-weight: bold;">set</span> filePath <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #0066ff;">path to</span> resource thisFile <span style="color: #ff0033; font-weight: bold;">in</span> bundle posixDir
            <span style="color: #ff0033; font-weight: bold;">if</span> thisFile starts <span style="color: #ff0033; font-weight: bold;">with</span> backupBase <span style="color: #ff0033; font-weight: bold;">then</span>
                <span style="color: #ff0033; font-weight: bold;">set</span> archiveList <span style="color: #ff0033; font-weight: bold;">to</span> archiveList <span style="color: #000000;">&amp;</span> <span style="color: #0066ff;">POSIX path</span> <span style="color: #ff0033; font-weight: bold;">of</span> filePath
            <span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">if</span>
        <span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">repeat</span>
    <span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">tell</span>
&nbsp;
    <span style="color: #808080; font-style: italic;">(* List existing backups in order of last modified date *)</span>
    <span style="color: #ff0033; font-weight: bold;">set</span> latestArchive <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #009900;">&quot;&quot;</span>
    <span style="color: #ff0033; font-weight: bold;">set</span> linkDest <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #009900;">&quot;&quot;</span>
    <span style="color: #ff0033; font-weight: bold;">set</span> listString <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #009900;">&quot;&quot;</span>
    <span style="color: #ff0033; font-weight: bold;">repeat</span> <span style="color: #ff0033; font-weight: bold;">with</span> x <span style="color: #ff0033; font-weight: bold;">from</span> <span style="color: #000000;">1</span> <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #0066ff;">number</span> <span style="color: #ff0033; font-weight: bold;">of</span> <span style="color: #0066ff;">items</span> <span style="color: #ff0033; font-weight: bold;">in</span> archiveList
        <span style="color: #ff0033; font-weight: bold;">set</span> listString <span style="color: #ff0033; font-weight: bold;">to</span> listString <span style="color: #000000;">&amp;</span> <span style="color: #009900;">&quot; &quot;</span> <span style="color: #000000;">&amp;</span> <span style="color: #0066ff;">quoted form</span> <span style="color: #ff0033; font-weight: bold;">of</span> <span style="color: #0066ff;">item</span> x <span style="color: #ff0033; font-weight: bold;">of</span> archiveList
    <span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">repeat</span>
    <span style="color: #ff0033; font-weight: bold;">set</span> newString <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #0066ff;">do shell script</span> <span style="color: #009900;">&quot;ls -dt &quot;</span> <span style="color: #000000;">&amp;</span> listString <span style="color: #808080; font-style: italic;">(* sort files by modified date *)</span>
    <span style="color: #ff0033; font-weight: bold;">set</span> theList <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #000000;">&#40;</span><span style="color: #0066ff;">paragraphs</span> <span style="color: #ff0033; font-weight: bold;">of</span> newString<span style="color: #000000;">&#41;</span>
&nbsp;
    <span style="color: #808080; font-style: italic;">(* Clear out outdated backups *)</span>
    <span style="color: #ff0033; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #0066ff;">number</span> <span style="color: #ff0033; font-weight: bold;">of</span> <span style="color: #0066ff;">items</span> <span style="color: #ff0033; font-weight: bold;">in</span> theList <span style="color: #ff0033; font-weight: bold;">is</span> <span style="color: #ff0033;">greater</span> than number_of_archives<span style="color: #000000;">&#41;</span> <span style="color: #ff0033;">and</span> <span style="color: #000000;">&#40;</span>number_of_archives <span style="color: #ff0033; font-weight: bold;">is</span> <span style="color: #ff0033;">greater</span> than <span style="color: #000000;">0</span><span style="color: #000000;">&#41;</span> <span style="color: #ff0033; font-weight: bold;">then</span>
        <span style="color: #ff0033; font-weight: bold;">repeat</span> <span style="color: #ff0033; font-weight: bold;">with</span> y <span style="color: #ff0033; font-weight: bold;">from</span> <span style="color: #000000;">&#40;</span>number_of_archives <span style="color: #000000;">+</span> <span style="color: #000000;">1</span><span style="color: #000000;">&#41;</span> <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #000000;">&#40;</span><span style="color: #0066ff;">number</span> <span style="color: #ff0033; font-weight: bold;">of</span> <span style="color: #0066ff;">items</span> <span style="color: #ff0033; font-weight: bold;">in</span> theList<span style="color: #000000;">&#41;</span>
            <span style="color: #0066ff;">do shell script</span> <span style="color: #009900;">&quot;rm -Rf &quot;</span> <span style="color: #000000;">&amp;</span> <span style="color: #0066ff;">quoted form</span> <span style="color: #ff0033; font-weight: bold;">of</span> <span style="color: #0066ff;">item</span> y <span style="color: #ff0033; font-weight: bold;">of</span> theList
        <span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">repeat</span>
    <span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">if</span>
    <span style="color: #ff0033; font-weight: bold;">if</span> <span style="color: #0066ff;">number</span> <span style="color: #ff0033; font-weight: bold;">of</span> <span style="color: #0066ff;">items</span> <span style="color: #ff0033; font-weight: bold;">in</span> theList <span style="color: #ff0033; font-weight: bold;">is</span> <span style="color: #ff0033;">greater</span> than <span style="color: #000000;">0</span> <span style="color: #ff0033; font-weight: bold;">then</span>
        <span style="color: #ff0033; font-weight: bold;">set</span> latestArchive <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #0066ff;">quoted form</span> <span style="color: #ff0033; font-weight: bold;">of</span> <span style="color: #0066ff;">item</span> <span style="color: #000000;">1</span> <span style="color: #ff0033; font-weight: bold;">of</span> theList
        <span style="color: #ff0033; font-weight: bold;">if</span> latestArchive <span style="color: #ff0033; font-weight: bold;">is</span> <span style="color: #ff0033;">equal</span> <span style="color: #ff0033; font-weight: bold;">to</span> backupFolder <span style="color: #ff0033; font-weight: bold;">then</span>
            <span style="color: #808080; font-style: italic;">(* Preserve same target folder *)</span>
            <span style="color: #ff0033; font-weight: bold;">if</span> <span style="color: #0066ff;">number</span> <span style="color: #ff0033; font-weight: bold;">of</span> <span style="color: #0066ff;">items</span> <span style="color: #ff0033; font-weight: bold;">in</span> theList <span style="color: #ff0033; font-weight: bold;">is</span> <span style="color: #ff0033;">greater</span> than <span style="color: #000000;">1</span> <span style="color: #ff0033; font-weight: bold;">then</span>
                <span style="color: #ff0033; font-weight: bold;">set</span> latestArchive <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #0066ff;">quoted form</span> <span style="color: #ff0033; font-weight: bold;">of</span> <span style="color: #0066ff;">item</span> <span style="color: #000000;">2</span> <span style="color: #ff0033; font-weight: bold;">of</span> theList
            <span style="color: #ff0033; font-weight: bold;">else</span>
                <span style="color: #ff0033; font-weight: bold;">set</span> latestArchive <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #009900;">&quot;&quot;</span>
            <span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">if</span>
        <span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">if</span>
    <span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">if</span>
&nbsp;
    <span style="color: #ff0033; font-weight: bold;">if</span> latestArchive <span style="color: #ff0033; font-weight: bold;">is</span> <span style="color: #ff0033;">not</span> <span style="color: #ff0033;">equal</span> <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #009900;">&quot;&quot;</span> <span style="color: #ff0033; font-weight: bold;">then</span>
        <span style="color: #ff0033; font-weight: bold;">set</span> linkDest <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #009900;">&quot; --link-dest=&quot;</span> <span style="color: #000000;">&amp;</span> latestArchive
    <span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">if</span>
    <span style="color: #ff0033; font-weight: bold;">set</span> theScript <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #009900;">&quot;rsync &quot;</span> <span style="color: #000000;">&amp;</span> rsync_params <span style="color: #000000;">&amp;</span> linkDest <span style="color: #000000;">&amp;</span> excluded <span style="color: #000000;">&amp;</span> sourceDir <span style="color: #000000;">&amp;</span> <span style="color: #009900;">&quot; &quot;</span> <span style="color: #000000;">&amp;</span> backupFolder <span style="color: #000000;">&amp;</span> <span style="color: #009900;">&quot;; touch &quot;</span> <span style="color: #000000;">&amp;</span> backupFolder
<span style="color: #ff0033; font-weight: bold;">else</span>
    <span style="color: #ff0033; font-weight: bold;">set</span> theScript <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #009900;">&quot;rsync &quot;</span> <span style="color: #000000;">&amp;</span> rsync_params <span style="color: #000000;">&amp;</span> excluded <span style="color: #000000;">&amp;</span> sourceDir <span style="color: #000000;">&amp;</span> <span style="color: #009900;">&quot; &quot;</span> <span style="color: #000000;">&amp;</span> targetDir <span style="color: #000000;">&amp;</span> <span style="color: #009900;">&quot;; touch &quot;</span> <span style="color: #000000;">&amp;</span> targetDir
<span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">if</span>
&nbsp;
<span style="color: #ff0033; font-weight: bold;">if</span> with_administrator_privileges <span style="color: #ff0033; font-weight: bold;">then</span>
    <span style="color: #0066ff;">do shell script</span> theScript <span style="color: #ff0033; font-weight: bold;">with</span> administrator privileges
<span style="color: #ff0033; font-weight: bold;">else</span>
    <span style="color: #0066ff;">do shell script</span> theScript
<span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">if</span>
&nbsp;
<span style="color: #0066ff;">activate</span> <span style="color: #ff0033; font-weight: bold;">of</span> <span style="color: #0066ff;">me</span>
<span style="color: #0066ff;">beep</span>
<span style="color: #ff0033; font-weight: bold;">if</span> display_notification <span style="color: #ff0033; font-weight: bold;">then</span> display alert NameOfDisk <span style="color: #000000;">&amp;</span> <span style="color: #009900;">&quot; drive backed up&quot;</span>
<span style="color: #808080; font-style: italic;">(*
on error
    display alert &quot;There was an error backing up &quot; &amp; NameOfDisk
end try
*)</span>
&nbsp;
&nbsp;
<span style="color: #ff0033; font-weight: bold;">to</span> shortMonth<span style="color: #000000;">&#40;</span>themonth<span style="color: #000000;">&#41;</span>
    <span style="color: #ff0033; font-weight: bold;">set</span> MonthList <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #000000;">&#123;</span><span style="color: #0066ff;">January</span>, <span style="color: #0066ff;">February</span>, <span style="color: #0066ff;">March</span>, <span style="color: #0066ff;">April</span>, <span style="color: #0066ff;">May</span>, <span style="color: #0066ff;">June</span>, <span style="color: #0066ff;">July</span>, <span style="color: #0066ff;">August</span>, <span style="color: #0066ff;">September</span>, <span style="color: #0066ff;">October</span>, <span style="color: #0066ff;">November</span>, <span style="color: #0066ff;">December</span><span style="color: #000000;">&#125;</span>
    <span style="color: #ff0033; font-weight: bold;">set</span> mm <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #000000;">1</span>
    <span style="color: #ff0033; font-weight: bold;">repeat</span> <span style="color: #ff0033; font-weight: bold;">until</span> <span style="color: #0066ff;">item</span> mm <span style="color: #ff0033; font-weight: bold;">of</span> MonthList <span style="color: #000000;">=</span> themonth
        <span style="color: #ff0033; font-weight: bold;">copy</span> mm <span style="color: #000000;">+</span> <span style="color: #000000;">1</span> <span style="color: #ff0033; font-weight: bold;">to</span> mm
    <span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">repeat</span>
    <span style="color: #ff0033; font-weight: bold;">if</span> mm <span style="color: #000000;">&lt;</span> <span style="color: #000000;">10</span> <span style="color: #ff0033; font-weight: bold;">then</span> <span style="color: #ff0033; font-weight: bold;">copy</span> <span style="color: #009900;">&quot;0&quot;</span> <span style="color: #000000;">&amp;</span> mm <span style="color: #ff0033; font-weight: bold;">to</span> mm
    <span style="color: #ff0033; font-weight: bold;">return</span> mm
<span style="color: #ff0033; font-weight: bold;">end</span> shortMonth</pre></div></div>



<p>
<a href="http://www.cneophytou.com/wp-content/uploads/2007/03/rsync.zip">Download this script</a><br />
<br />
Copy the above code in Script Editor, and save it as an Application bundle giving it the name &quot;rsync&quot;. If you wish to give it a different name, or maintain a number of copies each with a different name, make sure to modify the first line of the Folder Action script appropriately.<br />
<br />
Finally, I can just drop a copy of the rsync application bundle in any thumb drive I want to keep a backup of, and apply the Folder Action to any computer I want to maintain backups on. Since the backup script is using <code>rsync</code> for the backup, I can have multiple backups on any number of computers and they will all mirror the contents of the thumb drive whenever the thumb drive is mounted on them. Additionally, a tar-gzipped copy of the thumb drive can optionally be created with a date stamp for archiving. Deletion of old archives must be managed manually.<br />
<br />
If you are having permission issues with some of the files on one of your thumb drives, you can enable the <code>with_administrator_privileges</code> property in the backup script. This will cause the script to ask you for a password every time the thumb drive is mounted before performing the backup, but will perform the backup as an administrator eliminating any permission issues.<br />
<br />
I feel that this script can still be improved, but for now it works just fine for my needs. If you have any suggestions for improving this process, feel free to add them in the comments.]]></content:encoded>
			<wfw:commentRss>http://www.cneophytou.com/2007/03/06/automating-backup-of-flash-drives/feed/</wfw:commentRss>
		<slash:comments>68</slash:comments>
		</item>
		<item>
		<title>Hints and code snippets for a more sane OS X Terminal experience</title>
		<link>http://www.cneophytou.com/2006/11/13/hints-and-code-snippets-for-a-more-sane-os-x-terminal-experience/</link>
		<comments>http://www.cneophytou.com/2006/11/13/hints-and-code-snippets-for-a-more-sane-os-x-terminal-experience/#comments</comments>
		<pubDate>Mon, 13 Nov 2006 11:06:56 +0000</pubDate>
		<dc:creator>Constantinos</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[OS X]]></category>
		<category><![CDATA[Hack]]></category>
		<category><![CDATA[Terminal]]></category>
		<category><![CDATA[Unix]]></category>

		<guid isPermaLink="false">http://www.cneophytou.com/2006/11/13/hints-and-code-snippets-for-a-more-sane-os-x-terminal-experience/</guid>
		<description><![CDATA[Pretty long title, huh? Well, I&#8217;ve finally made the decision that there&#8217;s no way I&#8217;ll ever be able to keep a journal. So instead, I&#8217;ll start posting code snippets and general hints that I mostly harvested online (and try to cite wherever I can &#8211; remember that is -), but also modified to suit my [...]]]></description>
			<content:encoded><![CDATA[Pretty long title, huh? Well, I&#8217;ve finally made the decision that there&#8217;s no way I&#8217;ll ever be able to keep a journal. So instead, I&#8217;ll start posting code snippets and general hints that I mostly harvested online (and try to cite wherever I can &#8211; remember that is -), but also modified to suit my purposes&#8230; First up is seamless integration of X11 in OS X with the Terminal application.. Read on for the code<br />
<span id="more-71"></span>
<br />
First off, the reason I got started in this: I HATE xterm. Really dislike it, to the point where I would actively avoid any xwindow apps. That&#8217;s until I came across <a href='http://www.macosxhints.com/article.php?story=2005091004025818&#038;query=x11%2Bterminal'>this hint</a> at <a href='http://www.macosxhints.com'>macosxhints.com</a>. Really nice hint, but to get the best possible approach you have to shift through all the comments, and merge some bash with some csh scripts in order to get the most seamless approach. So this is my solution, for the bash shell, derived from that hint on macosxhints, and explicitly avoiding any modifications of master files (which might get overwritten with an OS X upgrade).<br />
<br />
First step, is to prevent X11 from opening up an xterm window. That&#8217;s fairly easy. Simply create a file called <code>.xinitrc</code> under your home (<code>~/</code>) directory with your favorite editor (like <a href='http://macromates.com/'>TextMate</a> <img src='http://www.cneophytou.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' />  ), and paste this code in it (lifted straight off the <a href='http://www.macosxhints.com/article.php?story=2005091004025818&#038;query=x11%2Bterminal'>aforementioned hint</a>):<br />
</p>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #007800;">PATH</span>=<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>X11R6<span style="color: #000000; font-weight: bold;">/</span>bin:<span style="color: #007800;">$PATH</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># surpress starting of an initial xterm</span>
xterm<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #7a0874; font-weight: bold;">&#123;</span>
    <span style="color: #7a0874; font-weight: bold;">return</span> <span style="color: #000000;">0</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># remember the display name</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$DISPLAY</span>&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #007800;">$HOME</span><span style="color: #000000; font-weight: bold;">/</span>.tmp<span style="color: #000000; font-weight: bold;">/</span>X11-display-<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">hostname</span> -s<span style="color: #000000; font-weight: bold;">`</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># run system-defined xinitrc (doesn't return)</span>
<span style="color: #7a0874; font-weight: bold;">source</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>X11<span style="color: #000000; font-weight: bold;">/</span>xinit<span style="color: #000000; font-weight: bold;">/</span>xinitrc</pre></div></div>




<p>
Now what this does, is redefine the function that calls up the xterm window, and make it do nothing. Then the master file is sourced, so no harm no foul. This modification will survive across upgrades too.<br />
<br />
Now to the more tricky part. In your <code>.bash_profile</code> file, insert this little gem of a code:<br />
</p>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #000000; font-weight: bold;">!</span><span style="color: #007800;">$DISPLAY</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #000000; font-weight: bold;">!</span><span style="color: #007800;">$SSH_TTY</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #000000; font-weight: bold;">!</span><span style="color: #007800;">$REMOTEHOST</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #000000; font-weight: bold;">then</span>
    <span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">DISPLAY</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">ps</span> xw <span style="color: #660033;">-o</span> <span style="color: #7a0874; font-weight: bold;">command</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #660033;">-n</span> <span style="color: #ff0000;">'/^\/.*X11.*\:/s/.*:/:/p'</span><span style="color: #000000; font-weight: bold;">`</span>
<span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$DISPLAY</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #000000; font-weight: bold;">then</span>
    <span style="color: #000000; font-weight: bold;">if</span> xwininfo <span style="color: #660033;">-display</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$DISPLAY</span>&quot;</span> <span style="color: #660033;">-root</span> <span style="color: #000000; font-weight: bold;">&gt;/</span>dev<span style="color: #000000; font-weight: bold;">/</span>null <span style="color: #000000;">2</span><span style="color: #000000; font-weight: bold;">&gt;&amp;</span><span style="color: #000000;">1</span>
    <span style="color: #000000; font-weight: bold;">then</span>
        <span style="color: #7a0874; font-weight: bold;">echo</span> Using X11 display <span style="color: #007800;">$DISPLAY</span>
        <span style="color: #7a0874; font-weight: bold;">export</span> DISPLAY
    <span style="color: #000000; font-weight: bold;">else</span>
        <span style="color: #7a0874; font-weight: bold;">unset</span> DISPLAY
    <span style="color: #000000; font-weight: bold;">fi</span>
<span style="color: #000000; font-weight: bold;">fi</span></pre></div></div>



<p>
<br />
This piece of code simply tries to capture the $DISPLAY given by X11, so it can be used in the Terminal. This is usually <code>:0</code>, but not if you&#8217;re running it over ssh. This should catch either.<br />
<br />
So far so good. Whenever I need xwindows, I can start X11, then open a new terminal window and voila. But wait a minute. Why would I have to manually start X11? When that app is idle, it&#8217;s using up almost zero resources. I could very easily place it in my startup items. That&#8217;s a good solution, with the problem being that I rarely need X11, and I don&#8217;t want to have it in my dock all the time.<br />
<br />
This is where the magic happens (btw this same method can be used to hide the dock and menu-bar of pretty much ANY app). Find the X11 app in the finder under <code>/Applications/Utilities/</code>. Ctrl-click on it, and &#8220;Show Package Contents&#8221;. Then navigate to <code>Contents/Info.plist</code>, open it up in the Property List Editor, and add a new sibling under Root called <code>LSUIElement</code>, set it to boolean, and give it the value &#8216;Yes&#8217; (or set it to string and give it the value 1). Save the plist file, and close it.<br />
<br />
Almost there. Now in the terminal, give the command <code>touch /Applications/Utilities/X11.app/</code>, and you&#8217;re all set. Double click on the X11 app to start it, and&#8230; nothing! The only way you can know it&#8217;s running, is if you look for it in the Activity Monitor! This won&#8217;t survive across upgrades of X11, and in fact if X11 gets upgraded you <em>will</em> have to open Activity Monitor to kill it before the upgrade, but I feel it&#8217;s an easy change to make, and a change that&#8217;s almost a second nature to me.<br />
<br />
So that&#8217;s my solution for this. Right now I have X11 running in the background at all times, and terminal simply captures the display and uses it whenever it needs it. And since all the modified files are in the user&#8217;s home directory, this solution will survive across OS upgrades. As a final note, I do have the capture script for tcsh, but it&#8217;s the same as the script listed in a comment of the previously mentioned macosxhints hint, so I won&#8217;t enter it here again. Just look for it there.]]></content:encoded>
			<wfw:commentRss>http://www.cneophytou.com/2006/11/13/hints-and-code-snippets-for-a-more-sane-os-x-terminal-experience/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
