<?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:media="http://search.yahoo.com/mrss/">

<channel>
	<title>TannieSpace &#187; context</title>
	<atom:link href="http://tanniespace.com/tag/context/feed/" rel="self" type="application/rss+xml" />
	<link>http://tanniespace.com</link>
	<description>geekery, drawing, and then some</description>
	<lastBuildDate>Sat, 24 Dec 2011 08:32:01 +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>Create a new task in a project</title>
		<link>http://tanniespace.com/2009/create-a-new-task-in-a-project/</link>
		<comments>http://tanniespace.com/2009/create-a-new-task-in-a-project/#comments</comments>
		<pubDate>2011-10-31 19:46:07</pubDate>
		<dc:creator>tanja</dc:creator>
				<category><![CDATA[geekery]]></category>
		<category><![CDATA[random_stuff]]></category>
		<category><![CDATA[applescript]]></category>
		<category><![CDATA[context]]></category>
		<category><![CDATA[omnifocus]]></category>
		<category><![CDATA[project]]></category>

		<guid isPermaLink="false">http://tanniespace.com/create-a-new-task-in-a-project/</guid>
		<description><![CDATA[For completion sake, I decided to post the bit to create a new task in a new or existing project in OmniFocus through AppleScript. I have this in my script that creates tasks from my mail. If you know a bit of AppleScript, this should help out. If I have the energy, I might post [...]]]></description>
			<content:encoded><![CDATA[<p>For completion sake, I decided to post the bit to create a new task in a new or existing project in OmniFocus through AppleScript. I have this in my script that creates tasks from my mail.</p>

<p>If you know a bit of AppleScript, this should help out. If I have the energy, I might post the entire script later and explain the parts.</p>

<p>In this case, it took longest to figure out the following part:</p>

<div class="codecolorer-container applescript default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="applescript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #ff0033; font-weight: bold;">tell</span> MyProject<br />
&nbsp; <span style="color: #ff0033; font-weight: bold;">set</span> theTask <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #0066ff;">make</span> <span style="color: #0066ff;">new</span> task <span style="color: #ff0033; font-weight: bold;">with</span> <span style="color: #0066ff;">properties</span>¬<br />
&nbsp;<span style="color: #000000;">&#123;</span><span style="color: #0066ff;">name</span>:MyTaskTopic, context:MyContext, note:ThisNote<span style="color: #000000;">&#125;</span><br />
<span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">tell</span></div></div>

<p>Apparently, when creating a new task you have to tell the project. If you want to set the context, you instead tell the task to set its context property to something.</p>

<p>This does make sense, in the way that you always tell the <em>containing</em> item to do something.</p>

<p><span id="more-1208"></span>
The part I use in my script:</p>

<div class="codecolorer-container applescript default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><div class="applescript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #ff0033; font-weight: bold;">if</span> MyContext <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;NONE&quot;</span> <span style="color: #ff0033;">and</span> MyProject <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;NONE&quot;</span> <span style="color: #ff0033; font-weight: bold;">then</span><br />
&nbsp; &nbsp;<span style="color: #ff0033; font-weight: bold;">set</span> theTask <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #0066ff;">make</span> <span style="color: #0066ff;">new</span> inbox task ¬<br />
&nbsp; &nbsp; &nbsp;<span style="color: #ff0033; font-weight: bold;">with</span> <span style="color: #0066ff;">properties</span> <span style="color: #000000;">&#123;</span><span style="color: #0066ff;">name</span>:MyTaskTopic, note:ThisNote<span style="color: #000000;">&#125;</span><br />
&nbsp; <span style="color: #ff0033; font-weight: bold;">set</span> ProjectString <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #009900;">&quot;INBOX&quot;</span><br />
<br />
<span style="color: #ff0033; font-weight: bold;">else</span> <span style="color: #ff0033; font-weight: bold;">if</span> MyContext <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;NONE&quot;</span> <span style="color: #ff0033;">and</span> ¬<br />
&nbsp;MyProject <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;NONE&quot;</span> <span style="color: #ff0033; font-weight: bold;">then</span><br />
&nbsp; &nbsp; <span style="color: #ff0033; font-weight: bold;">tell</span> MyProject<br />
&nbsp; &nbsp; <span style="color: #ff0033; font-weight: bold;">set</span> theTask <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #0066ff;">make</span> <span style="color: #0066ff;">new</span> task ¬<br />
&nbsp; &nbsp; &nbsp; <span style="color: #ff0033; font-weight: bold;">with</span> <span style="color: #0066ff;">properties</span> <span style="color: #000000;">&#123;</span><span style="color: #0066ff;">name</span>:MyTaskTopic, note:ThisNote<span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">tell</span><br />
<br />
<span style="color: #ff0033; font-weight: bold;">else</span> <span style="color: #ff0033; font-weight: bold;">if</span> MyProject <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;NONE&quot;</span> <span style="color: #ff0033;">and</span> ¬<br />
&nbsp; &nbsp; MyContext <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;NONE&quot;</span> <span style="color: #ff0033; font-weight: bold;">then</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff0033; font-weight: bold;">set</span> theTask <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #0066ff;">make</span> <span style="color: #0066ff;">new</span> inbox task ¬<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff0033; font-weight: bold;">with</span> <span style="color: #0066ff;">properties</span> <span style="color: #000000;">&#123;</span><span style="color: #0066ff;">name</span>:MyTaskTopic, context:MyContext, note:ThisNote<span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff0033; font-weight: bold;">set</span> ProjectString <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #009900;">&quot;INBOX&quot;</span><br />
<br />
<span style="color: #ff0033; font-weight: bold;">else</span><br />
&nbsp; &nbsp; <span style="color: #ff0033; font-weight: bold;">tell</span> MyProject<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff0033; font-weight: bold;">set</span> theTask <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #0066ff;">make</span> <span style="color: #0066ff;">new</span> task ¬<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff0033; font-weight: bold;">with</span> <span style="color: #0066ff;">properties</span> <span style="color: #000000;">&#123;</span><span style="color: #0066ff;">name</span>:MyTaskTopic, context:MyContext, note:ThisNote<span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">tell</span><br />
<span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">if</span><br />
<br />
<span style="color: #ff0033; font-weight: bold;">try</span><br />
&nbsp; &nbsp; <span style="color: #ff0033; font-weight: bold;">set</span> Datum <span style="color: #ff0033; font-weight: bold;">to</span> setDueDate<br />
&nbsp; &nbsp; <span style="color: #ff0033; font-weight: bold;">set</span> due date <span style="color: #ff0033; font-weight: bold;">of</span> theTask <span style="color: #ff0033; font-weight: bold;">to</span> setDueDate<br />
<span style="color: #ff0033; font-weight: bold;">on</span> <span style="color: #ff0033; font-weight: bold;">error</span><br />
&nbsp; &nbsp; <span style="color: #ff0033; font-weight: bold;">set</span> due date <span style="color: #ff0033; font-weight: bold;">of</span> theTask <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span>current date<span style="color: #000000;">&#41;</span> <span style="color: #000000;">+</span> <span style="color: #000000;">604800</span><span style="color: #000000;">&#41;</span><br />
<span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">try</span><br />
&nbsp; <br />
<span style="color: #ff0033; font-weight: bold;">tell</span> theTask<br />
&nbsp; &nbsp; <span style="color: #ff0033; font-weight: bold;">set</span> note <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #ff0033; font-weight: bold;">return</span> <span style="color: #000000;">&amp;</span> <span style="color: #ff0033; font-weight: bold;">return</span><br />
&nbsp; &nbsp; <span style="color: #ff0033; font-weight: bold;">tell</span> note<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff0033; font-weight: bold;">set</span> theURL <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #009900;">&quot;message://&lt; &quot;</span> <span style="color: #000000;">&amp;</span> message_id <span style="color: #000000;">&amp;</span> <span style="color: #009900;">&quot;&gt;&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff0033; font-weight: bold;">set</span> linkText <span style="color: #ff0033; font-weight: bold;">to</span> theURL<br />
&nbsp; &nbsp; &nbsp; &nbsp; insert linkText at <span style="color: #ff0033;">before</span> <span style="color: #ff0033;">first</span> character<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff0033; font-weight: bold;">set</span> value <span style="color: #ff0033; font-weight: bold;">of</span> attribute <span style="color: #009900;">&quot;link&quot;</span> <span style="color: #ff0033; font-weight: bold;">of</span> style <span style="color: #ff0033; font-weight: bold;">of</span> <span style="color: #0066ff;">paragraph</span> <span style="color: #000000;">1</span> <span style="color: #ff0033; font-weight: bold;">to</span> theURL<br />
&nbsp; &nbsp; &nbsp; &nbsp; insert message_content at <span style="color: #ff0033;">before</span> <span style="color: #ff0033;">last</span> character<br />
&nbsp; &nbsp; <span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">tell</span><br />
<span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">tell</span></div></div>

<p>which works like a charm.</p>
]]></content:encoded>
			<wfw:commentRss>http://tanniespace.com/2009/create-a-new-task-in-a-project/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Applescripts for OmniFocus: change the context or project of selected tasks.</title>
		<link>http://tanniespace.com/2009/applescripts-for-omnifocus-change-the-context-or-project-of-selected-tasks/</link>
		<comments>http://tanniespace.com/2009/applescripts-for-omnifocus-change-the-context-or-project-of-selected-tasks/#comments</comments>
		<pubDate>2010-09-13 03:07:17</pubDate>
		<dc:creator>tanja</dc:creator>
				<category><![CDATA[geekery]]></category>
		<category><![CDATA[random_stuff]]></category>
		<category><![CDATA[applescript]]></category>
		<category><![CDATA[context]]></category>
		<category><![CDATA[e-mail]]></category>
		<category><![CDATA[easy]]></category>
		<category><![CDATA[list]]></category>
		<category><![CDATA[omnifocus]]></category>
		<category><![CDATA[omniweb]]></category>
		<category><![CDATA[project]]></category>

		<guid isPermaLink="false">http://tanniespace.com/applescripts-for-omnifocus-change-the-context-or-project-of-selected-tasks/</guid>
		<description><![CDATA[I use OmniFocus a lot, and have recently tweaked some more AppleScripts to make my workflow even more smooth. I can add any mail to OmniFocus for replies, add confirmation of orders from mail to OmniFocus which will automatically go into my project-shoebox for orders, with a &#8216;waiting for&#8217; context and a due date set [...]]]></description>
			<content:encoded><![CDATA[<p>I use OmniFocus a lot, and have recently tweaked some more AppleScripts to make my workflow even more smooth. I can add any mail to OmniFocus for replies, add confirmation of orders from mail to OmniFocus which will automatically go into my project-shoebox for orders, with a &#8216;waiting for&#8217; context and a due date set to 1 week into the future, unless I&#8217;ve changed or added <a href="http://www.indev.ca/MailTags.html">MailTags</a> with a project, a keyword and a due date. In that case it&#8217;ll take the project, the first keyword and the due date and use them to set up the OmniFocus task. I have a few more scripts:</p>

<ul>
<li>in OmniWeb I can take and add a URL for later reading, it&#8217;ll go into my inbox by default</li>
<li>in OmniWeb I can take and add a URL to my &#8216;wish-list&#8217; project (with a start date for at 2 weeks in the future)</li>
<li>in OmniFocus I have scripts to easily change the context or the project of selected tasks</li>
<li>in Mail I can press a key and have the selected e-mail(s) sent to OmniFocus with a &#8216;Respond to: &#8216; before the subject line, sorting into either a default project or the one specified in MailTags, with the context set to &#8216;mail&#8217; and the message URL in the note-field</li>
<li>in OmniFocus I can select such a task, press a key to run a script that will open the message and immediately create a reply (I have a separate one for just opening, in case I have to read it thoroughly first)</li>
</ul>

<p>All these scripts make the integration between all these programs very easy. That and <a href="http://www.red-sweater.com/fastscripts/">FastScripts</a>.<br />
I found useful scripts over at <a href="http://www.rose-hulman.edu/~clifton/software.html">Curtis Clifton&#8217;s site</a>. His scripts use <a href="http://growl.info/">Growl</a> notification so if you have Growl installed you get a small notification.</p>

<p>I had some trouble putting my own scripts together, so I decided to paste the info here, just in case I need it later on, or someone else runs into similar issues. I found it quite hard to figure out how to add a task to an existing project or to move it from inbox / other project. In the end, it only took a few lines.</p>

<p><span id="more-1207"></span>
First, when I started my script, I wanted a default project or context (I&#8217;ll use &#8216;project&#8217; from now on, but it also applies to the context-script). To do this I created a &#8216;property&#8217; at the beginning of the script:</p>

<div class="codecolorer-container applescript default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="applescript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #ff0033; font-weight: bold;">property</span> defaultProject : <span style="color: #009900;">&quot;Miscellaneous&quot;</span><br />
<span style="color: #ff0033; font-weight: bold;">property</span> alertItemNum : <span style="color: #009900;">&quot;&quot;</span></div></div>

<p>I used the alterItemNum for my alerts through this very simple routine:</p>

<div class="codecolorer-container applescript default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="applescript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #ff0033; font-weight: bold;">on</span> notify<span style="color: #000000;">&#40;</span>alertName, alertTitle, alertText<span style="color: #000000;">&#41;</span><br />
&nbsp; <span style="color: #0066ff;">display dialog</span> alertText <span style="color: #ff0033;">as</span> <span style="color: #0066ff;">string</span> <span style="color: #ff0033; font-weight: bold;">with</span> icon <span style="color: #000000;">1</span><br />
<span style="color: #ff0033; font-weight: bold;">end</span> notify</div></div>

<p>That went at the end of my script.</p>

<p>I started by addressing OmniFocus and &#8216;talking&#8217; to the open document:</p>

<div class="codecolorer-container applescript default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="applescript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #ff0033; font-weight: bold;">tell</span> <span style="color: #0066ff;">application</span> <span style="color: #009900;">&quot;OmniFocus&quot;</span><br />
&nbsp; <span style="color: #ff0033; font-weight: bold;">tell</span> <span style="color: #ff0033;">front</span> <span style="color: #0066ff;">document</span><br />
&nbsp; &nbsp; <span style="color: #ff0033; font-weight: bold;">tell</span> <span style="color: #000000;">&#40;</span><span style="color: #ff0033;">first</span> <span style="color: #0066ff;">document</span> <span style="color: #0066ff;">window</span> <span style="color: #ff0033;">whose</span> <span style="color: #ff0033;">index</span> <span style="color: #ff0033; font-weight: bold;">is</span> <span style="color: #000000;">1</span><span style="color: #000000;">&#41;</span></div></div>

<p>Then, I checked to see if that document had anything selected, and if not, give an error-dialogue:</p>

<div class="codecolorer-container applescript default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="applescript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #ff0033; font-weight: bold;">set</span> SelectedItems <span style="color: #ff0033; font-weight: bold;">to</span> selected trees <span style="color: #ff0033; font-weight: bold;">of</span> <span style="color: #0066ff;">content</span><br />
<span style="color: #ff0033; font-weight: bold;">set</span> numItems <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #000000;">&#40;</span><span style="color: #0066ff;">count</span> <span style="color: #0066ff;">items</span> <span style="color: #ff0033; font-weight: bold;">of</span> SelectedItems<span style="color: #000000;">&#41;</span><br />
&nbsp; <span style="color: #ff0033; font-weight: bold;">if</span> numItems <span style="color: #ff0033; font-weight: bold;">is</span> <span style="color: #000000;">0</span> <span style="color: #ff0033; font-weight: bold;">then</span><br />
&nbsp; &nbsp; <span style="color: #ff0033; font-weight: bold;">set</span> alertName <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #009900;">&quot;Error&quot;</span><br />
&nbsp; &nbsp; <span style="color: #ff0033; font-weight: bold;">set</span> alertTitle <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #009900;">&quot;Script failure&quot;</span><br />
&nbsp; &nbsp; <span style="color: #ff0033; font-weight: bold;">set</span> alertText <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #009900;">&quot;No valid task(s) selected&quot;</span><br />
&nbsp; &nbsp; <span style="color: #ff0033; font-weight: bold;">my</span> notify<span style="color: #000000;">&#40;</span>alertName, alertTitle, alertText<span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #ff0033; font-weight: bold;">return</span><br />
&nbsp; <span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">if</span></div></div>

<p>If I have no items selected, the script will call the alert routine from above ( my notify(alertName, alertTitle, alertText) ). Because I created a separate routine, I can use this anywhere in the script.</p>

<p>Next, display a dialogue asking for the project:</p>

<div class="codecolorer-container applescript default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="applescript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0066ff;">display dialog</span> <span style="color: #009900;">&quot;Change to what Project? &quot;</span> <span style="color: #0066ff;">default answer</span> defaultProject <span style="color: #0066ff;">buttons</span> <span style="color: #000000;">&#123;</span><span style="color: #009900;">&quot;Cancel&quot;</span>, <span style="color: #009900;">&quot;OK&quot;</span><span style="color: #000000;">&#125;</span> default button <span style="color: #000000;">2</span><br />
<br />
<span style="color: #ff0033; font-weight: bold;">set</span> theProject <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #000000;">&#40;</span><span style="color: #ff0033;">the</span> <span style="color: #0066ff;">text</span> returned <span style="color: #ff0033; font-weight: bold;">of</span> <span style="color: #ff0033;">the</span> <span style="color: #0066ff;">result</span><span style="color: #000000;">&#41;</span></div></div>

<p>The variable &#8216;theProject&#8217; will now contain the name of the (new) project to move the tasks too.</p>

<p>Next, the loop to go through all the items and move them:</p>

<div class="codecolorer-container applescript default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="applescript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #ff0033; font-weight: bold;">set</span> selectNum <span style="color: #ff0033; font-weight: bold;">to</span> numItems<br />
<span style="color: #ff0033; font-weight: bold;">set</span> successTot <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #000000;">0</span><br />
&nbsp;<span style="color: #ff0033; font-weight: bold;">repeat</span> <span style="color: #ff0033; font-weight: bold;">while</span> selectNum &gt; <span style="color: #000000;">0</span><br />
&nbsp; &nbsp;<span style="color: #ff0033; font-weight: bold;">set</span> selectedItem <span style="color: #ff0033; font-weight: bold;">to</span> value <span style="color: #ff0033; font-weight: bold;">of</span> <span style="color: #0066ff;">item</span> selectNum <span style="color: #ff0033; font-weight: bold;">of</span> SelectedItems<br />
&nbsp; &nbsp;<span style="color: #ff0033; font-weight: bold;">set</span> succeeded <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #ff0033; font-weight: bold;">my</span> ChangeProject<span style="color: #000000;">&#40;</span>selectedItem, theProject<span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp;<span style="color: #ff0033; font-weight: bold;">if</span> succeeded <span style="color: #ff0033; font-weight: bold;">then</span> <span style="color: #ff0033; font-weight: bold;">set</span> successTot <span style="color: #ff0033; font-weight: bold;">to</span> successTot <span style="color: #000000;">+</span> <span style="color: #000000;">1</span><br />
&nbsp; &nbsp;<span style="color: #ff0033; font-weight: bold;">set</span> selectNum <span style="color: #ff0033; font-weight: bold;">to</span> selectNum <span style="color: #000000;">-</span> <span style="color: #000000;">1</span><br />
&nbsp;<span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">repeat</span></div></div>

<p>This loop will end as soon as the variable &#8216;selectNum&#8217; (= numItems which I set to the count of the items in the variable SelectedItems) reaches 0. It calls the routine &#8216;ChangeProject&#8217; which I&#8217;ll get to in a bit, but I first want to wrap up this part.
Let me also explain the &#8216;if succeeded then set successTot to successTot + 1&#8242; line. The line before sets &#8216;succeeded&#8217; to the result of the ChangeProject routine. This result can mean anything, numbers, letters, whatever. In this case we use it to return a &#8216;true&#8217; or &#8216;false&#8217;. That way, we only need to use &#8216;if succeeded&#8217; (which will either be &#8216;true&#8217; or &#8216;false&#8217;) as a condition. We don&#8217;t need to check the actual content of the variable. This can come in handy for various checks, and it took me a while to catch on to that, so I figured I&#8217;d mention it here.</p>

<p>To end this main routine, I used:</p>

<div class="codecolorer-container applescript default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="applescript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp; &nbsp; &nbsp; <span style="color: #ff0033; font-weight: bold;">set</span> alertName <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #009900;">&quot;General&quot;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #ff0033; font-weight: bold;">set</span> alertTitle <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #009900;">&quot;Script complete&quot;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #ff0033; font-weight: bold;">if</span> successTot <span style="color: #000000;">&amp;</span>gt; <span style="color: #000000;">1</span> <span style="color: #ff0033; font-weight: bold;">then</span> <span style="color: #ff0033; font-weight: bold;">set</span> alertItemNum <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #009900;">&quot;s&quot;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #ff0033; font-weight: bold;">set</span> alertText <span style="color: #ff0033; font-weight: bold;">to</span> successTot <span style="color: #000000;">&amp;</span> <span style="color: #009900;">&quot; item&quot;</span> <span style="color: #000000;">&amp;</span> alertItemNum <span style="color: #000000;">&amp;</span> <span style="color: #009900;">&quot; changed to Project &quot;</span> <span style="color: #000000;">&amp;</span> theProject<br />
&nbsp; &nbsp; <span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">tell</span><br />
&nbsp; <span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">tell</span><br />
<span style="color: #ff0033; font-weight: bold;">my</span> notify<span style="color: #000000;">&#40;</span>alertName, alertTitle, alertText<span style="color: #000000;">&#41;</span><br />
<span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">tell</span></div></div>

<p>Basically, this tells the dialogue box to say the script ran successfully and displays the number of items successfully moved and only to use the &#8216;s&#8217; after &#8216;item&#8217; if the count of successful moves is higher than 1.</p>

<p>That wraps up the main part.</p>

<p>The routine to actually move the task to the other project only took 21 lines:</p>

<div class="codecolorer-container applescript default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><div class="applescript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #ff0033; font-weight: bold;">on</span> ChangeProject<span style="color: #000000;">&#40;</span>selectedItem, theProject<span style="color: #000000;">&#41;</span><br />
&nbsp; <span style="color: #ff0033; font-weight: bold;">set</span> success <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #0066ff;">false</span><br />
&nbsp; &nbsp; <span style="color: #ff0033; font-weight: bold;">tell</span> <span style="color: #0066ff;">application</span> <span style="color: #009900;">&quot;OmniFocus&quot;</span> <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #ff0033; font-weight: bold;">tell</span> default <span style="color: #0066ff;">document</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #ff0033; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>theProject <span style="color: #ff0033; font-weight: bold;">is</span> <span style="color: #ff0033;">not</span> <span style="color: #009900;">&quot;&quot;</span><span style="color: #000000;">&#41;</span> <span style="color: #ff0033; font-weight: bold;">then</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff0033; font-weight: bold;">set</span> MyProjectArray <span style="color: #ff0033; font-weight: bold;">to</span> null<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff0033; font-weight: bold;">set</span> MyProjectArray <span style="color: #ff0033; font-weight: bold;">to</span> complete theProject <span style="color: #ff0033;">as</span> project maximum matches <span style="color: #000000;">1</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff0033; font-weight: bold;">try</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff0033; font-weight: bold;">set</span> MyProjectID <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #0066ff;">id</span> <span style="color: #ff0033; font-weight: bold;">of</span> <span style="color: #ff0033;">first</span> <span style="color: #0066ff;">item</span> <span style="color: #ff0033; font-weight: bold;">of</span> MyProjectArray<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff0033; font-weight: bold;">set</span> theNewProject <span style="color: #ff0033; font-weight: bold;">to</span> project <span style="color: #0066ff;">id</span> MyProjectID<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff0033; font-weight: bold;">on</span> <span style="color: #ff0033; font-weight: bold;">error</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff0033; font-weight: bold;">set</span> theNewProject <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #000000;">&#40;</span><span style="color: #0066ff;">make</span> project <span style="color: #ff0033; font-weight: bold;">with</span> <span style="color: #0066ff;">properties</span> <span style="color: #000000;">&#123;</span><span style="color: #0066ff;">name</span>:theProject<span style="color: #000000;">&#125;</span><span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">try</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff0033; font-weight: bold;">try</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff0033; font-weight: bold;">set</span> newtask <span style="color: #ff0033; font-weight: bold;">to</span> selectedItem<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066ff;">move</span> newtask <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">of</span> tasks <span style="color: #ff0033; font-weight: bold;">of</span> theNewProject<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff0033; font-weight: bold;">set</span> success <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #0066ff;">true</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">try</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">if</span><br />
&nbsp; &nbsp; <span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">tell</span><br />
&nbsp; <span style="color: #ff0033; font-weight: bold;">return</span> success<br />
<span style="color: #ff0033; font-weight: bold;">end</span> ChangeProject</div></div>

<p>The first line sets the success to &#8216;false&#8217;, because we want to actively, <em>after</em> having our success, set it to &#8216;true&#8217;.<br />
We then chat with OmniFocus again, and this time, we&#8217;ll just talk to the default document (the one you have open). If the variable &#8216;theProject&#8217; is not empty, we&#8217;ll continue. If it is, the &#8216;if-end if&#8217; ends, without having set the &#8216;success&#8217; variable to true (and thus, the script failed). You could technically build in an extra loop to change it to a default project, however, I prefer it this way. If I accidentally emptied that dialogue-box, nothing will happen, just as I like it.</p>

<p>If theProject does contain something (anything), the script continues with its routine. It sets the MyProjectArry to null (makes it empty, just in case). It then used OmniFocus complete option to find the first matching project of OmniFocuses project-list. If you&#8217;ve ever only typed the first three letters in one of OmniFocus&#8217;s project-areas (to set the project) and it magically came up with the right project, this is the same thing. It means you only have to type the first three or four letters of your project, and the script will find it. If it can&#8217;t find the project, it will create it for you (at the end of your project-list).</p>

<p>After that, it will simply try to add the task to the desired project.</p>

<div class="codecolorer-container applescript default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="applescript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #ff0033; font-weight: bold;">try</span><br />
&nbsp; <span style="color: #ff0033; font-weight: bold;">set</span> newtask <span style="color: #ff0033; font-weight: bold;">to</span> selectedItem<br />
&nbsp; <span style="color: #0066ff;">move</span> newtask <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">of</span> tasks <span style="color: #ff0033; font-weight: bold;">of</span> theNewProject<br />
&nbsp; <span style="color: #ff0033; font-weight: bold;">set</span> success <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #0066ff;">true</span><br />
<span style="color: #ff0033; font-weight: bold;">end</span></div></div>

<p>I&#8217;ve copied this part again, because <em>this</em> took me hours to figure out. I knew how to do it for a context-change:</p>

<div class="codecolorer-container applescript default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="applescript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #ff0033; font-weight: bold;">try</span><br />
&nbsp; <span style="color: #ff0033; font-weight: bold;">set</span> newtask <span style="color: #ff0033; font-weight: bold;">to</span> selectedItem<br />
&nbsp; <span style="color: #ff0033; font-weight: bold;">set</span> context <span style="color: #ff0033; font-weight: bold;">of</span> newtask <span style="color: #ff0033; font-weight: bold;">to</span> theNewContext<br />
&nbsp; <span style="color: #ff0033; font-weight: bold;">set</span> success <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #0066ff;">true</span><br />
<span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">try</span></div></div>

<p>so I tried to &#8216;set project of newtask to theNewProject&#8217; but that didn&#8217;t work. It drove me crazy for a while, still haven&#8217;t fully recovered&#8230;</p>

<p>But it works! The complete script changes the project of selected tasks and gives a confirmation dialogue (so you know that it happened). Of course, before using it, make a back up of your OmniFocus database, and run the script from Script Editor first. Open the &#8216;Event Log&#8217; (&#8984;-3) to follow what happens while you run the script.</p>

<p><strong>zipped up version of <a href="http://tanniespace.com/files/2009/09/ChangeProject.scpt.zip">ChangeProject</a> and <a href="http://tanniespace.com/files/2009/09/ChangeContext.scpt.zip">ChangeContext</a> for easy downloading</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://tanniespace.com/2009/applescripts-for-omnifocus-change-the-context-or-project-of-selected-tasks/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

