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

<channel>
	<title>www.anthonysmith.me.uk &#187; Python</title>
	<atom:link href="http://www.anthonysmith.me.uk/tag/python/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.anthonysmith.me.uk</link>
	<description>Ceci n&#039;est pas un blog</description>
	<lastBuildDate>Wed, 08 Feb 2012 17:07:24 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Moving files to trash from the Mac command line</title>
		<link>http://www.anthonysmith.me.uk/2008/01/08/moving-files-to-trash-from-the-mac-command-line/</link>
		<comments>http://www.anthonysmith.me.uk/2008/01/08/moving-files-to-trash-from-the-mac-command-line/#comments</comments>
		<pubDate>Tue, 08 Jan 2008 15:58:24 +0000</pubDate>
		<dc:creator>Anthony</dc:creator>
				<category><![CDATA[Computing]]></category>
		<category><![CDATA[Bash]]></category>
		<category><![CDATA[Macs]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://www.anthonysmith.me.uk/2008/01/08/moving-files-to-trash-from-the-mac-command-line/</guid>
		<description><![CDATA[Ever wished you could move files to the trash from the command line on the Mac? Here's how. First, buy a Mac. Then Option 1 (uses bash): add the following to your ~/.bash_profile function rem &#123; for b in &#34;$@&#34; do osascript -e &#34;tell app \&#34;Finder\&#34; to delete POSIX file \&#34;${PWD}/$b\&#34;&#34; done &#125; Then type&#8230;]]></description>
			<content:encoded><![CDATA[<p>Ever wished you could move files to the trash from the command line on the Mac? Here's how.</p>
<p>First, buy a Mac. Then</p>
<p><span id="more-88"></span></p>
<p>Option 1 (uses bash): add the following to your ~/.bash_profile</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> rem <span style="color: #7a0874; font-weight: bold;">&#123;</span>
<span style="color: #000000; font-weight: bold;">for</span> b <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #ff0000;">&quot;$@&quot;</span>
<span style="color: #000000; font-weight: bold;">do</span>
osascript <span style="color: #660033;">-e</span> <span style="color: #ff0000;">&quot;tell app <span style="color: #000099; font-weight: bold;">\&quot;</span>Finder<span style="color: #000099; font-weight: bold;">\&quot;</span> to delete POSIX file <span style="color: #000099; font-weight: bold;">\&quot;</span><span style="color: #007800;">${PWD}</span>/<span style="color: #007800;">$b</span><span style="color: #000099; font-weight: bold;">\&quot;</span>&quot;</span>
<span style="color: #000000; font-weight: bold;">done</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span></pre></div></div>

<p>Then type 'source ~/.bash_profile' in Terminal.</p>
<p>Or Option 2 (uses Python and gives slightly more meaningful error messages): make an executable file called 'rem' somewhere in your $PATH:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">#! /usr/bin/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;">sys</span>
<span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #008000;">len</span><span style="color: black;">&#40;</span><span style="color: #dc143c;">sys</span>.<span style="color: black;">argv</span><span style="color: black;">&#41;</span> <span style="color: #66cc66;">&amp;</span>gt<span style="color: #66cc66;">;</span> <span style="color: #ff4500;">1</span>:
    <span style="color: #ff7700;font-weight:bold;">for</span> arg <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #dc143c;">sys</span>.<span style="color: black;">argv</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">1</span>:<span style="color: black;">&#93;</span>:
        <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #dc143c;">os</span>.<span style="color: black;">path</span>.<span style="color: black;">exists</span><span style="color: black;">&#40;</span>arg<span style="color: black;">&#41;</span>:
            <span style="color: #dc143c;">os</span>.<span style="color: black;">system</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'osascript -e <span style="color: #000099; font-weight: bold;">\'</span>tell app &quot;Finder&quot; '</span>
                      + <span style="color: #483d8b;">'to move the POSIX file &quot;'</span>
                      + <span style="color: #dc143c;">os</span>.<span style="color: black;">path</span>.<span style="color: black;">abspath</span><span style="color: black;">&#40;</span>arg<span style="color: black;">&#41;</span> + <span style="color: #483d8b;">'&quot; to trash<span style="color: #000099; font-weight: bold;">\'</span>'</span><span style="color: black;">&#41;</span>
        <span style="color: #ff7700;font-weight:bold;">else</span>:
            <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;Error:&quot;</span>, <span style="color: #dc143c;">os</span>.<span style="color: black;">path</span>.<span style="color: black;">abspath</span><span style="color: black;">&#40;</span>arg<span style="color: black;">&#41;</span>, <span style="color: #483d8b;">&quot;does not exist&quot;</span>
<span style="color: #ff7700;font-weight:bold;">else</span>:
    <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;usage: rem file(s)&quot;</span>
    <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;       move file(s) to Trash&quot;</span></pre></div></div>

<p>Now, either way, to move 'blah.txt' to Trash, simply type 'rem blah.txt'. Wildcards and lists of files are permitted. You even get the sound effects!</p>
<p>(This makes use of Applescript and works for me on OS X Tiger and Leopard. Thanks to kw for pointing out the problem with Option 1 and leading me to think of an alternative - 3 July 2008. And thanks for icke for showing me how to make the bash version work all the time - 6 Nov 2008.)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.anthonysmith.me.uk/2008/01/08/moving-files-to-trash-from-the-mac-command-line/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
	</channel>
</rss>

