<?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:creativeCommons="http://backend.userland.com/creativeCommonsRssModule">

<channel>
	<title>The AppleScript Studio Workshop</title>
	<atom:link href="http://foolsworkshop.com/applescript/feed/" rel="self" type="application/rss+xml" />
	<link>http://foolsworkshop.com/applescript</link>
	<description>AppleScript Studio blog with tips, scripts, and tutorials</description>
	<pubDate>Fri, 30 May 2008 09:03:41 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.5.1</generator>
	<language>en</language>
	<creativeCommons:license>http://creativecommons.org/licenses/by/3.0/</creativeCommons:license>		<item>
		<title>Adding a Check Updates Feature</title>
		<link>http://foolsworkshop.com/applescript/2008/05/adding-a-check-updates-feature/</link>
		<comments>http://foolsworkshop.com/applescript/2008/05/adding-a-check-updates-feature/#comments</comments>
		<pubDate>Fri, 30 May 2008 03:28:12 +0000</pubDate>
		<dc:creator>K. M. Lawson</dc:creator>
		
		<category><![CDATA[Applescript]]></category>

		<category><![CDATA[Applescript Studio]]></category>

		<category><![CDATA[Code Sample]]></category>

		<category><![CDATA[Frameworks]]></category>

		<category><![CDATA[Modules]]></category>

		<category><![CDATA[sparkle]]></category>

		<category><![CDATA[updates]]></category>

		<guid isPermaLink="false">http://foolsworkshop.com/applescript/?p=43</guid>
		<description><![CDATA[This tutorial shows you how to add the Sparkle framework to an AppleScript Studio application using XCode 3.1.]]></description>
			<content:encoded><![CDATA[<p>One handy feature many Mac applications have these days is the ability to check for updates. There is a free Cocoa module out there called <a href="http://sparkle.andymatuschak.org/" onclick="pageTracker._trackPageview('/outgoing/sparkle.andymatuschak.org/?referer=');">Sparkle</a> which allows Mac developers to easily add this capability to their applications. Fortunately, it is also relatively easy for AppleScript Studio developers to incorporate Sparkle update capabilities to their own applications. This posting provides a tutorial and sample application for adding Sparkle to an AppleScript Studio application.</p>
<p>I first read about this on a MacScripter <a href="http://bbs.macscripter.net/viewtopic.php?id=25655" onclick="pageTracker._trackPageview('/outgoing/bbs.macscripter.net/viewtopic.php?id=25655&referer=');">posting</a> asking about this, and then found this excellent <a href="http://guimkie.com/tutorials/adding-the-sparkle-framework/" onclick="pageTracker._trackPageview('/outgoing/guimkie.com/tutorials/adding-the-sparkle-framework/?referer=');">tutorial</a> by Max Karreth. There are very few differences between my tutorial below and his, but in my own tutorial I have created somewhat more zoomed in screenshots and a bit more information on the creation of appcasts. You might also want to consult the <a href="http://sparkle.andymatuschak.org/wiki/Documentation/Basics" onclick="pageTracker._trackPageview('/outgoing/sparkle.andymatuschak.org/wiki/Documentation/Basics?referer=');">documentation</a> on the Sparkle homepage and the PDF that comes with the download.</p>
<p><span id="more-43"></span></p>
<p>1. First download the Sparkle module from its <a href="http://sparkle.andymatuschak.org/" onclick="pageTracker._trackPageview('/outgoing/sparkle.andymatuschak.org/?referer=');">homepage</a>. This tutorial uses Sparkle 1.1 and XCode 3.1.</p>
<p>2. Drag the Sparkle.framework into your XCode application into the folder &#8220;Linked Frameworks&#8221; of the &#8220;Frameworks&#8221; folder.</p>
<div style="text-align:center;"><img src="http://foolsworkshop.com/applescript/wp-content/uploads/2008/05/xcodescreensnapz004.jpg" alt="XcodeScreenSnapz004.jpg" border="0" width="432" height="408" /></div>
<p>You should now see it in your linked frameworks folder.</p>
<div style="text-align:center;"><img src="http://foolsworkshop.com/applescript/wp-content/uploads/2008/05/xcodescreensnapz005.jpg" alt="XcodeScreenSnapz005.jpg" border="0" width="245" height="127" /></div>
<p>Now, from the &#8220;Project&#8221; menu of XCode, choose &#8220;New Copy Files Build Phase&#8221; from the &#8220;New Build Phase&#8221; menu item.</p>
<div style="text-align:center;"><img src="http://foolsworkshop.com/applescript/wp-content/uploads/2008/05/xcodescreensnapz006.jpg" alt="XcodeScreenSnapz006.jpg" border="0" width="287" height="128" /></div>
<p>A new window will appear looking like this:</p>
<div style="text-align:center;"><img src="http://foolsworkshop.com/applescript/wp-content/uploads/2008/05/xcodescreensnapz008.jpg" alt="XcodeScreenSnapz008.jpg" border="0" width="414" height="202" /></div>
<p>Now, drag the Sparkle.framework from the &#8220;Linked Frameworks&#8221; folder and drop it onto the newly created &#8220;Copy Files&#8221; build phase listed under your application in the &#8220;Targets&#8221; section of your project.</p>
<div style="text-align:center;"><img src="http://foolsworkshop.com/applescript/wp-content/uploads/2008/05/xcodescreensnapz009.jpg" alt="XcodeScreenSnapz009.jpg" border="0" width="281" height="169" /></div>
<p>Now in the Info.plist file of your project in XCode, you need to add a new key. This will designate a link to the RSS file you will eventually create, called an &#8220;AppCast&#8221; which will contain the information about updates to the application. For example:</p>

<div class="wp_syntax"><div class="code"><pre class="xml"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;key<span style="font-weight: bold; color: black;">&gt;</span></span></span>SUFeedURL<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/key<span style="font-weight: bold; color: black;">&gt;</span></span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;string<span style="font-weight: bold; color: black;">&gt;</span></span></span>http://foolsworkshop.com/downloads/sparklesample.xml<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/string<span style="font-weight: bold; color: black;">&gt;</span></span></span></pre></div></div>

<p>Now switch to the &#8220;Interface Builder&#8221; application and your &#8220;MainMenu.nib&#8221; file (open it from the &#8220;Resources&#8221; folder of your XCode project if it is not open. </p>
<p>From the File menu choose &#8220;Read Class Files&#8221;</p>
<div style="text-align:center;"><img src="http://foolsworkshop.com/applescript/wp-content/uploads/2008/05/interface-builderscreensnapz004.jpg" alt="Interface BuilderScreenSnapz004.jpg" border="0" width="264" height="219" /></div>
<p>Navigate to your folder and you should see the Sparkle.framework folder and inside that the &#8220;Headers&#8221; folder (or actually an alias to the folder, which is deep in the &#8220;Versions&#8221; folder). Select all the files in the &#8220;Headers&#8221; folder and add them.</p>
<div style="text-align:center;"><img src="http://foolsworkshop.com/applescript/wp-content/uploads/2008/05/interface-builderscreensnapz005.jpg" alt="Interface BuilderScreenSnapz005.jpg" border="0" width="382" height="164" /></div>
<p>Once you have added the class header files from Sparkle, add an &#8220;NSObject&#8221; which looks like a blue box from the library panel into the list of files in your MainMenu.nib.</p>
<div style="text-align:center;"><img src="http://foolsworkshop.com/applescript/wp-content/uploads/2008/05/interface-builderscreensnapz006.jpg" alt="Interface BuilderScreenSnapz006.jpg" border="0" width="390" height="339" /></div>
<p>Click on this object and in the &#8220;Information&#8221; tab looking like a white &#8220;I&#8221; on a blue circle, type &#8220;SUUpdater&#8221; into the &#8220;Class&#8221; field (it should auto complete if you read the class files correctly) and press enter. This will add the required Class Actions in the panel below it.</p>
<div style="text-align:center;"><img src="http://foolsworkshop.com/applescript/wp-content/uploads/2008/05/interface-builderscreensnapz007.jpg" alt="Interface BuilderScreenSnapz007.jpg" border="0" width="310" height="242" /></div>
<p>Now create your &#8220;Check for Updates&#8230;&#8221; menu item in the application menu by dragging an NSMenuItem into the appropriate place. After you add it, you can change the &#8220;Title&#8221; of your menu in the inspector in the first tab.</p>
<div style="text-align:center;"><img src="http://foolsworkshop.com/applescript/wp-content/uploads/2008/05/interface-builderscreensnapz008.jpg" alt="Interface BuilderScreenSnapz008.jpg" border="0" width="435" height="246" /></div>
<p>Now, you need to connect this menu to the new Sparkle object you created. Control-click on the menu item and a blue line will appear. Drag this line and drop it on the &#8220;Updater&#8221; object.</p>
<div style="text-align:center;"><img src="http://foolsworkshop.com/applescript/wp-content/uploads/2008/05/interface-builderscreensnapz010.jpg" alt="Interface BuilderScreenSnapz010.jpg" border="0" width="422" height="268" /></div>
<p>See Max Karreth&#8217;s <a href="http://guimkie.com/tutorials/adding-the-sparkle-framework/" onclick="pageTracker._trackPageview('/outgoing/guimkie.com/tutorials/adding-the-sparkle-framework/?referer=');">tutorial</a> for a bit more on how to add a preference for automatic checks for updates. </p>
<p>Everything you need to do in the project is set up. However, you still need to set up an AppCast RSS file. There is a sample of one in the Sparkle documentation PDF and also you can download the <a href="http://andymatuschak.org/files/sparkletestcast.xml" onclick="pageTracker._trackPageview('/outgoing/andymatuschak.org/files/sparkletestcast.xml?referer=');">test file</a> used found in the Demo application. I created my AppCast RSS file using the RSS application <a href="http://reinventedsoftware.com/feeder/" onclick="pageTracker._trackPageview('/outgoing/reinventedsoftware.com/feeder/?referer=');">Feeder</a> which actually has a template for creating Sparkle RSS files (if you use this, consider editing the template and turning on the extra field for &#8220;Release info&#8221;). The important things that must be included in your AppCast RSS feed are a link to the Sparkle namespace:</p>
<pre>
xmlns:sparkle="http://www.andymatuschak.org/xml-namespaces/sparkle"
</pre>
<p>You then add a new RSS item each time you make a new update, and include an enclosure linking to your new release, which the documentation says should be named something like &#8220;Application Name App_2.0.zip&#8221;</p>
<p>Here is what my RSS feed looks like after I created it with the Sparkle template in Feeder. Some of these things are optional lines or extra information added by Feeder itself, but it should give you an idea of how this works:</p>

<div class="wp_syntax"><div class="code"><pre class="xml"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;utf-8&quot;</span><span style="font-weight: bold; color: black;">?&gt;</span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;rss</span> <span style="color: #000066;">xmlns:atom</span>=<span style="color: #ff0000;">&quot;http://www.w3.org/2005/Atom&quot;</span> <span style="color: #000066;">xmlns:sparkle</span>=<span style="color: #ff0000;">&quot;http://www.andymatuschak.org/xml-namespaces/sparkle&quot;</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;2.0&quot;</span><span style="font-weight: bold; color: black;">&gt;</span></span>
  <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;channel<span style="font-weight: bold; color: black;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;title<span style="font-weight: bold; color: black;">&gt;</span></span></span>Sparkle Sample<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/title<span style="font-weight: bold; color: black;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;link<span style="font-weight: bold; color: black;">&gt;</span></span></span>http://foolsworkshop.com/downloads/sparklesample.xml<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/link<span style="font-weight: bold; color: black;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;description<span style="font-weight: bold; color: black;">&gt;</span></span></span>A simple example AppCast for Sparkle<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/description<span style="font-weight: bold; color: black;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;generator<span style="font-weight: bold; color: black;">&gt;</span></span></span>Feeder 1.5.3(378) http://reinventedsoftware.com/feeder/<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/generator<span style="font-weight: bold; color: black;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;docs<span style="font-weight: bold; color: black;">&gt;</span></span></span>http://blogs.law.harvard.edu/tech/rss<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/docs<span style="font-weight: bold; color: black;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;language<span style="font-weight: bold; color: black;">&gt;</span></span></span>en<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/language<span style="font-weight: bold; color: black;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;pubDate<span style="font-weight: bold; color: black;">&gt;</span></span></span>Fri, 30 May 2008 11:35:15 +0900<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/pubDate<span style="font-weight: bold; color: black;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;lastBuildDate<span style="font-weight: bold; color: black;">&gt;</span></span></span>Fri, 30 May 2008 11:35:15 +0900<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/lastBuildDate<span style="font-weight: bold; color: black;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;atom:link</span> <span style="color: #000066;">href</span>=<span style="color: #ff0000;">&quot;http://foolsworkshop.com/downloads/sparklesample.xml&quot;</span> <span style="color: #000066;">rel</span>=<span style="color: #ff0000;">&quot;self&quot;</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;application/rss+xml&quot;</span><span style="font-weight: bold; color: black;">/&gt;</span></span>
    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;item<span style="font-weight: bold; color: black;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;title<span style="font-weight: bold; color: black;">&gt;</span></span></span>Version 2.0 (No useful changes, upgrade for $100)<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/title<span style="font-weight: bold; color: black;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;pubDate<span style="font-weight: bold; color: black;">&gt;</span></span></span>Sun, 01 Jun 2008 11:24:54 +0900<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/pubDate<span style="font-weight: bold; color: black;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;enclosure</span> <span style="color: #000066;">url</span>=<span style="color: #ff0000;">&quot;http://foolsworkshop.com/downloads/Sparkle Sample App_2.0.zip&quot;</span> <span style="color: #000066;">length</span>=<span style="color: #ff0000;">&quot;561575&quot;</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;application/octet-stream&quot;</span> <span style="color: #000066;">sparkle:version</span>=<span style="color: #ff0000;">&quot;2.0&quot;</span><span style="font-weight: bold; color: black;">/&gt;</span></span>
      <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;guid</span> <span style="color: #000066;">isPermaLink</span>=<span style="color: #ff0000;">&quot;false&quot;</span><span style="font-weight: bold; color: black;">&gt;</span></span>version-20-no-useful-changes-upgrade-for-$100<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/guid<span style="font-weight: bold; color: black;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;sparkle:releaseNotesLink<span style="font-weight: bold; color: black;">&gt;</span></span></span>http://foolsworkshop.com/downloads/sparklesample.html<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/sparkle:releaseNotesLink<span style="font-weight: bold; color: black;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/item<span style="font-weight: bold; color: black;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/channel<span style="font-weight: bold; color: black;">&gt;</span></span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/rss<span style="font-weight: bold; color: black;">&gt;</span></span></span></pre></div></div>

<p>In addition to the RSS file, you might also want to post some release notes on the new version, which you can see in the above RSS is linked with the &#8220;sparkle:releaseNotesLink&#8221; tag. If such a file exists, Sparkle will display this file, which is regular HTML, when a new update is found.</p>
<p>You can try all this and play with a sample application here:</p>
<p><a href="http://foolsworkshop.com/downloads/sparklesample.zip">Sparkle Sample Project</a></p>
<p>Note: Max Karreth has already been nice enough to create a similar sample application but I had some trouble running the application.</p>
<p>Building this application and running should give you a chance to see how Sparkle works, as I have posted a &#8220;fake&#8221; 2.0 update. Note that the built application is labelled as &#8220;2.0&#8243; in the Finder if you choose &#8220;Get Info&#8221; after downloading the update.</p>
<div style="text-align:center;"><img src="http://foolsworkshop.com/applescript/wp-content/uploads/2008/05/sparkle-samplescreensnapz001.jpg" alt="Sparkle SampleScreenSnapz001.jpg" border="0" width="470" height="351" /></div>
]]></content:encoded>
			<wfw:commentRss>http://foolsworkshop.com/applescript/2008/05/adding-a-check-updates-feature/feed/</wfw:commentRss>
		</item>
		<item>
		<title>The Development of this Weblog</title>
		<link>http://foolsworkshop.com/applescript/2008/05/the-development-of-this-weblog/</link>
		<comments>http://foolsworkshop.com/applescript/2008/05/the-development-of-this-weblog/#comments</comments>
		<pubDate>Fri, 30 May 2008 01:39:53 +0000</pubDate>
		<dc:creator>K. M. Lawson</dc:creator>
		
		<category><![CDATA[Commentary]]></category>

		<guid isPermaLink="false">http://foolsworkshop.com/applescript/?p=28</guid>
		<description><![CDATA[Changes]]></description>
			<content:encoded><![CDATA[<p>I changed the name of this weblog from &#8220;Fool&#8217;s Applescript Workshop&#8221; to simply &#8220;The AppleScript Studio Workshop&#8221; since I have decided to welcome other skilled AppleScript Studio coders in the scripting community to join as contributors to this weblog. The majority of postings on this weblog will try to stick closely to the following guidelines:</p>
<p>1) To post relatively short but lucid explanations of how to solve practical problems a developer might face in creating an AppleScript Studio application, especially if one is a beginner and not that familiar with XCode, Cocoa classes, or even the AppleScript language. </p>
<p>2) Whenever possible, these explanations should be accompanied by a snippet of well-commented sample code, and if the posting author&#8217;s time allows, a sample XCode project which demonstrates the solution.</p>
<p>3) Whenever possible, links to forum/list postings, tutorials, Apple documentation, etc. which provide the same/similar or completely different solutions to similar problems should be provided so there are other sources the beginner can turn to if they need more information.</p>
<p>4) Any original content created for postings be Creative Commons<br />
licensed so it may be shared and spread easily among interested parties.</p>
]]></content:encoded>
			<wfw:commentRss>http://foolsworkshop.com/applescript/2008/05/the-development-of-this-weblog/feed/</wfw:commentRss>
		</item>
		<item>
		<title>The First Responder: Setting it to a Table Cell</title>
		<link>http://foolsworkshop.com/applescript/2008/05/the-first-responder-setting-it-to-a-table-cell/</link>
		<comments>http://foolsworkshop.com/applescript/2008/05/the-first-responder-setting-it-to-a-table-cell/#comments</comments>
		<pubDate>Wed, 28 May 2008 01:58:52 +0000</pubDate>
		<dc:creator>K. M. Lawson</dc:creator>
		
		<category><![CDATA[Applescript]]></category>

		<category><![CDATA[Applescript Studio]]></category>

		<category><![CDATA[Code Sample]]></category>

		<guid isPermaLink="false">http://foolsworkshop.com/applescript/2008/05/the-first-responder-setting-it-to-a-table-cell/</guid>
		<description><![CDATA[This example project and accompanying explanation shows how to set the first responder (the active cursor) in an individual table cell.]]></description>
			<content:encoded><![CDATA[<p>One of the problems I have had with using the first responder is the difficulty of setting the first responder (see this <a href="http://foolsworkshop.com/applescript/2008/05/using-the-first-responder-placing-the-cursor-in-a-text-field/">earlier posting</a> for more on this) to a single cell in a table. After posting a question about this to both MacSripter and the official Apple email list for AppleScript Studio, a Philip Buckley was very nice to respond with a solution. You can find his explanation of how to do this <a href="http://lists.apple.com/archives/applescript-studio/2008/May/msg00086.html" onclick="pageTracker._trackPageview('/outgoing/lists.apple.com/archives/applescript-studio/2008/May/msg00086.html?referer=');">here</a>.</p>
<p>I have not been able to find any way accomplish this task in AppleScript. Philip Buckley&#8217;s solution uses the Cocoa method &#8220;<a href="http://developer.apple.com/documentation/Cocoa/Reference/ApplicationKit/Classes/NSTableView_Class/Reference/Reference.html#//apple_ref/occ/instm/NSTableView/editColumn:row:withEvent:select:" onclick="pageTracker._trackPageview('/outgoing/developer.apple.com/documentation/Cocoa/Reference/ApplicationKit/Classes/NSTableView_Class/Reference/Reference.html_//apple_ref/occ/instm/NSTableView/editColumn_row_withEvent_select?referer=');">editColumn:row:withEvent:select:</a>&#8221; and the &#8220;call method&#8221; command to get at it (see this <a href="http://foolsworkshop.com/applescript/2008/05/calling-cocoa-string-methods-in-applescript-studio/">earlier posting</a> for more on this)</p>
<p>This method takes four parameters, as his email outlines:<br />
<blockquote>
<li>the column index &#8212; NB this is zero-based, so first column is 0, second column is 1 etc</li>
<li>the row index - NB this is zero-based, so first row is 0, second row is 1 etc</li>
<li>an NSEvent &#8212; should be nil I think, but for this purpose it seems it will accept pretty much anything, so in the example below, which I have tested, I have pased 0</li>
<li>a boolean &#8212; 1 for true</li>
</blockquote>
<p>I created a sample XCode Project which implements his solution for others to play with. You can download it here:</p>
<p><a href="http://foolsworkshop.com/downloads/firstrestable.zip">First Responder in Table Cell</a></p>
<p>The project creates a data source for the main window&#8217;s table, fills it with some text in 10 rows, and then provides a button which, when clicked, will select the column and row indicated by the user in two separate text fields.</p>
<p>The key code for the button is below:</p>

<div class="wp_syntax"><div class="code"><pre class="applescript"><span style="color: #CC0000;">set</span> theWindow <span style="color: #CC0000;">to</span> main window
<span style="color: #CC0000;">set</span> theRow <span style="color: #CC0000;">to</span> <span style="color: #66cc66;">&#40;</span><span style="color: #000000;">the</span> contents <span style="color: #CC0000;">of</span> text field <span style="color: #660000;">&quot;selectRow&quot;</span> <span style="color: #CC0000;">of</span> theWindow<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">-</span> <span style="color: #cc66cc;">1</span>
<span style="color: #808080; font-style: italic;">(* I subtract one because the parameters in the Cocoa method used below is a 0-based index *)</span>
<span style="color: #CC0000;">set</span> theColumn <span style="color: #CC0000;">to</span> <span style="color: #66cc66;">&#40;</span><span style="color: #000000;">the</span> contents <span style="color: #CC0000;">of</span> text field <span style="color: #660000;">&quot;selectColumn&quot;</span> <span style="color: #CC0000;">of</span> theWindow<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">-</span> <span style="color: #cc66cc;">1</span>
<span style="color: #808080; font-style: italic;">(* I subtract one because the parameters in the Cocoa method used below is a 0-based index *)</span>
<span style="color: #CC0000;">set</span> theTable <span style="color: #CC0000;">to</span> table view <span style="color: #cc66cc;">1</span> <span style="color: #CC0000;">of</span> scroll view <span style="color: #cc66cc;">1</span> <span style="color: #CC0000;">of</span> theWindow
<span style="color: #CC0000;">set</span> <span style="color: #000000;">first</span> responder <span style="color: #CC0000;">of</span> theWindow <span style="color: #CC0000;">to</span> theTable
<span style="color: #808080; font-style: italic;">(* If you want the row to also be selected, uncomment the next line *)</span>
<span style="color: #808080; font-style: italic;">(* set selected row of theTable to (theRow + 1) *)</span>
call method <span style="color: #660000;">&quot;editColumn:row:withEvent:select:&quot;</span> <span style="color: #CC0000;">of</span> object theTable <span style="color: #CC0000;">with</span> parameters <span style="color: #66cc66;">&#123;</span>theColumn, theRow, <span style="color: #cc66cc;">0</span>, <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#125;</span>
<span style="color: #808080; font-style: italic;">(* This example does not error check to see if the inputted row 
and column numbers are greater than the total number of rows/columns *)</span></pre></div></div>

<p>Many thanks to Philip Buckley who responded to my posting about this problem.</p>
]]></content:encoded>
			<wfw:commentRss>http://foolsworkshop.com/applescript/2008/05/the-first-responder-setting-it-to-a-table-cell/feed/</wfw:commentRss>
		</item>
		<item>
		<title>The First Responder: Put a Cursor in a Text Field</title>
		<link>http://foolsworkshop.com/applescript/2008/05/using-the-first-responder-placing-the-cursor-in-a-text-field/</link>
		<comments>http://foolsworkshop.com/applescript/2008/05/using-the-first-responder-placing-the-cursor-in-a-text-field/#comments</comments>
		<pubDate>Tue, 27 May 2008 08:52:19 +0000</pubDate>
		<dc:creator>K. M. Lawson</dc:creator>
		
		<category><![CDATA[Applescript]]></category>

		<category><![CDATA[Applescript Studio]]></category>

		<category><![CDATA[Code Sample]]></category>

		<guid isPermaLink="false">http://foolsworkshop.com/applescript/2008/05/using-the-first-responder-placing-the-cursor-in-a-text-field/</guid>
		<description><![CDATA[This describes how to set the first responder (the active cursor) for a text field.]]></description>
			<content:encoded><![CDATA[<p>One thing you might want to do in an application is to set the cursor to be active in (to blink in) a text field of your choosing. This is done through the &#8220;first responder&#8221; property which can be set for windows in your application. I have had a lot of trouble with this. I haven&#8217;t had a lot of success in making something useful out of reading the property, even though you can set it. If you have a reference to your window in the variable &#8220;myWindow&#8221; then you could set the cursor to be active in a field called &#8220;secondField&#8221; with a line of code like this:</p>

<div class="wp_syntax"><div class="code"><pre class="applescript"><span style="color: #CC0000;">set</span> <span style="color: #000000;">the</span> <span style="color: #000000;">first</span> responder <span style="color: #CC0000;">of</span> myWindow <span style="color: #CC0000;">to</span> text field <span style="color: #660000;">&quot;secondField&quot;</span> <span style="color: #CC0000;">of</span> myWindow</pre></div></div>

<p>You can download a very simple sample application which shows you how you can respond to the &#8220;return&#8221; key to move to the next text field. It also has some code to show you a button that, when pressed, will move the first responder to the second field on the screen.</p>
<p>Download the sample XCode project here: <a href="http://foolsworkshop.com/downloads/responderexample.zip">First Responder Example</a></p>
<p>Here is are the key lines of code involved:</p>

<div class="wp_syntax"><div class="code"><pre class="applescript"><span style="color: #CC0000;">on</span> clicked theObject
	<span style="color: #CC0000;">if</span> <span style="color: #000000;">the</span> name <span style="color: #CC0000;">of</span> theObject <span style="color: #CC0000;">is</span> <span style="color: #660000;">&quot;switchField&quot;</span> <span style="color: #CC0000;">then</span>
		<span style="color: #CC0000;">set</span> myWindow <span style="color: #CC0000;">to</span> <span style="color: #000000;">the</span> window <span style="color: #CC0000;">of</span> theObject
		<span style="color: #CC0000;">set</span> <span style="color: #000000;">the</span> <span style="color: #000000;">first</span> responder <span style="color: #CC0000;">of</span> myWindow ¬
           <span style="color: #CC0000;">to</span> text field <span style="color: #660000;">&quot;secondField&quot;</span> <span style="color: #CC0000;">of</span> myWindow
	<span style="color: #CC0000;">end</span> <span style="color: #CC0000;">if</span>
<span style="color: #CC0000;">end</span> clicked
&nbsp;
<span style="color: #CC0000;">on</span> keyboard up theObject event theEvent
	<span style="color: #CC0000;">set</span> myWindow <span style="color: #CC0000;">to</span> <span style="color: #000000;">the</span> window <span style="color: #CC0000;">of</span> theObject
	<span style="color: #CC0000;">if</span> <span style="color: #000000;">the</span> name <span style="color: #CC0000;">of</span> theObject <span style="color: #CC0000;">is</span> <span style="color: #660000;">&quot;firstField&quot;</span> <span style="color: #CC0000;">then</span>
		<span style="color: #CC0000;">if</span> <span style="color: #000000;">the</span> character <span style="color: #CC0000;">of</span> theEvent <span style="color: #CC0000;">is</span> <span style="color: #CC0000;">return</span> <span style="color: #CC0000;">then</span>
			<span style="color: #CC0000;">set</span> <span style="color: #000000;">the</span> <span style="color: #000000;">first</span> responder <span style="color: #CC0000;">of</span> myWindow <span style="color: #CC0000;">to</span> ¬
                text field <span style="color: #660000;">&quot;secondField&quot;</span> <span style="color: #CC0000;">of</span> myWindow
		<span style="color: #CC0000;">end</span> <span style="color: #CC0000;">if</span>
	<span style="color: #CC0000;">else</span> <span style="color: #CC0000;">if</span> <span style="color: #000000;">the</span> name <span style="color: #CC0000;">of</span> theObject <span style="color: #CC0000;">is</span> <span style="color: #660000;">&quot;secondField&quot;</span> <span style="color: #CC0000;">then</span>
		<span style="color: #CC0000;">if</span> <span style="color: #000000;">the</span> character <span style="color: #CC0000;">of</span> theEvent <span style="color: #CC0000;">is</span> <span style="color: #CC0000;">return</span> <span style="color: #CC0000;">then</span>
			<span style="color: #CC0000;">set</span> <span style="color: #000000;">the</span> <span style="color: #000000;">first</span> responder <span style="color: #CC0000;">of</span> myWindow <span style="color: #CC0000;">to</span> ¬
                 text field <span style="color: #660000;">&quot;firstField&quot;</span> <span style="color: #CC0000;">of</span> myWindow
		<span style="color: #CC0000;">end</span> <span style="color: #CC0000;">if</span>
	<span style="color: #CC0000;">end</span> <span style="color: #CC0000;">if</span>
<span style="color: #CC0000;">end</span> keyboard up</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://foolsworkshop.com/applescript/2008/05/using-the-first-responder-placing-the-cursor-in-a-text-field/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Adding a Help Book to your AppleScript Studio Application</title>
		<link>http://foolsworkshop.com/applescript/2008/05/adding-a-help-book-to-your-applescript-studio-application/</link>
		<comments>http://foolsworkshop.com/applescript/2008/05/adding-a-help-book-to-your-applescript-studio-application/#comments</comments>
		<pubDate>Tue, 27 May 2008 05:43:55 +0000</pubDate>
		<dc:creator>K. M. Lawson</dc:creator>
		
		<category><![CDATA[Applescript]]></category>

		<category><![CDATA[Applescript Studio]]></category>

		<category><![CDATA[Code Sample]]></category>

		<guid isPermaLink="false">http://foolsworkshop.com/applescript/2008/05/adding-a-help-book-to-your-applescript-studio-application/</guid>
		<description><![CDATA[This example project and explanation shows you how to add a Help Book to your application, thereby activating the help menu.]]></description>
			<content:encoded><![CDATA[<p>Once you make some progress in your application you might want to add some offline help files that can be displayed by choosing &#8220;Your_Application_Name Help&#8221; from the Help menu. Below are some instructions on how you can do this, along with an XCode project you can download to work with.<br />
<span id="more-24"></span><br />
1. Create your files using your favorite HTML application. You can have images and CSS files as well. Put all these files into a folder and give it a name. For my example, I will call the folder &#8220;Help Folder Example Help&#8221; since my application will be called &#8220;Help Folder Example&#8221;</p>
<p>2. Each file must have an additional META tag added inside the HEAD tag near the top of your HTML files with the title of your application and &#8220;Help&#8221;:</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;META</span> <span style="color: #000066;">NAME</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;AppleTitle&quot;</span> <span style="color: #000066;">CONTENT</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;Help Book Example Help&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span></pre></div></div>

<p>3. After you have finished making all your help files, open the application &#8220;Help Indexer&#8221; found in your Developer/Utilities folder. Navigate and choose the folder containing all your HTML, CSS, and images. This will create an &#8220;index&#8221; for your help files which can be used to search your files in the help browser.</p>
<p>4. Back in XCode, right-click on your &#8220;Resources&#8221; folder on the left and choose Add - &#8220;Existing Files&#8230;&#8221; choosing your folder with the help files and the newly created index.  When you are given some more options, this seems to work for me:</p>
<p><img src="http://foolsworkshop.com/applescript/wp-content/uploads/2008/05/xcodescreensnapz001.jpg" width="439" height="412" alt="XcodeScreenSnapz001.jpg" style="padding-top:5px; padding-right:5px; padding-bottom:5px; padding-left:5px;" /></p>
<p>This should result in the files being added to your project, looking something like this:</p>
<p><img src="http://foolsworkshop.com/applescript/wp-content/uploads/2008/05/xcodescreensnapz003.jpg" width="296" height="128" alt="XcodeScreenSnapz003.jpg" style="padding-top:5px; padding-right:5px; padding-bottom:5px; padding-left:5px;" /></p>
<p>You then need to add two keys to your &#8220;Info.plist&#8221; plist file, one indicating the name of your application&#8217;s help book, and the other the name of your help folder. In my example, here is what I needed to add:</p>

<div class="wp_syntax"><div class="code"><pre class="xml"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;key<span style="font-weight: bold; color: black;">&gt;</span></span></span>CFBundleHelpBookName<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/key<span style="font-weight: bold; color: black;">&gt;</span></span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;string<span style="font-weight: bold; color: black;">&gt;</span></span></span>Help Book Example Help<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/string<span style="font-weight: bold; color: black;">&gt;</span></span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;key<span style="font-weight: bold; color: black;">&gt;</span></span></span>CFBundleHelpBookFolder<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/key<span style="font-weight: bold; color: black;">&gt;</span></span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;string<span style="font-weight: bold; color: black;">&gt;</span></span></span>Help Book Example Help<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/string<span style="font-weight: bold; color: black;">&gt;</span></span></span></pre></div></div>

<p>5. Finally, you probably want to change the &#8220;Title&#8221; of the help menu item in &#8220;Interface Builder&#8221; to something like &#8220;Help Book Example Help&#8221; (in my case) so that it doesn&#8217;t say &#8220;NewApplication Help&#8221; when it is run. You can find the help menu item in the &#8220;1&#8243; menu under &#8220;2&#8243;</p>
<p><img src="http://foolsworkshop.com/applescript/wp-content/uploads/2008/05/interface-builderscreensnapz003.jpg" width="310" height="96" alt="Interface BuilderScreenSnapz003.jpg" style="padding-top:5px; padding-right:5px; padding-bottom:5px; padding-left:5px;" /></p>
<p>Now try compiling and running your application and the help book&#8217;s index.html home page should appear. My biggest complaint with the Help Book browser in OS X is that even simple files seem to load relatively slow; slower than running files directly in Safari for example. I am often reluctant to read help files since the help book takes one or two seconds longer to load than I am willing to wait for an answer. In the same time I can google a question online rather than risk the possibility that the help files are sorely lacking in documentation.</p>
<p>You can download the sample XCode project demonstrating the above here: <a href="http://foolsworkshop.com/downloads/helpbookexample.zip">Help Book Example</a></p>
<p>In order to write this posting and learn the techniques described here, I depended on these useful websites: a MacScripter <a href="http://bbs.macscripter.net/viewtopic.php?pid=96606" onclick="pageTracker._trackPageview('/outgoing/bbs.macscripter.net/viewtopic.php?pid=96606&referer=');">posting</a> on the topic and this excellent <a href="http://www.legallou.com/Mac/ASS/TutoML/ML820.html" onclick="pageTracker._trackPageview('/outgoing/www.legallou.com/Mac/ASS/TutoML/ML820.html?referer=');">tutorial</a> in French (I just looked at the pictures and guessed what I could from the accompanying text but the author recommends using Google to translate the site).</p>
]]></content:encoded>
			<wfw:commentRss>http://foolsworkshop.com/applescript/2008/05/adding-a-help-book-to-your-applescript-studio-application/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Reacting to Keyboard Input</title>
		<link>http://foolsworkshop.com/applescript/2008/05/reacting-to-keyboard-input/</link>
		<comments>http://foolsworkshop.com/applescript/2008/05/reacting-to-keyboard-input/#comments</comments>
		<pubDate>Mon, 26 May 2008 15:00:51 +0000</pubDate>
		<dc:creator>K. M. Lawson</dc:creator>
		
		<category><![CDATA[Applescript]]></category>

		<category><![CDATA[Applescript Studio]]></category>

		<category><![CDATA[Code Sample]]></category>

		<guid isPermaLink="false">http://foolsworkshop.com/applescript/2008/05/reacting-to-keyboard-input/</guid>
		<description><![CDATA[This posting and downloadable sample project shows you how to how to react to user keyboard input.]]></description>
			<content:encoded><![CDATA[<p>Another simple but useful task when developing an application in AppleScript Studio is the ability to respond to keyboard input. For example, I want my application to respond to the &#8220;return&#8221; key, in certain fields, the same way that it does when one presses the &#8220;tab&#8221; key, ie. it moves the cursor to the next field.  </p>
<p><a href="http://foolsworkshop.com/applescript/2008/05/activate-an-event-handler/">Activate</a> the &#8220;keyboard up&#8221; handler for the text field you wish to detect keyboard entries for and add some code.</p>
<p>When a key is pressed, a numerical Apple &#8220;key code&#8221; is generated that can be accessed by AppleScript. However, according to AppleScript Studio documentation:<br />
<blockquote>KEY CODE: the hardware-dependent value of the key pressed; you aren’t likely to work with the key code and no constants are currently provided to specify key codes; however, you may want to experiment with possible values; (for example, for at least one keyboard, the key code for delete is 51 and for backspace is 117)</p></blockquote>
<p>This is not very reassuring and I don&#8217;t know how standard the numbers are from keyboard to keyboard. </p>
<p>You can also access the &#8220;character&#8221; of the keyboard event which is just the literal character. Check the AppleScript document for other properties of the &#8220;event&#8221; class that may be useful to you, including booleans (true/false values) for things like: &#8220;command key down&#8221; &#8220;option key down&#8221; and &#8220;shift key down.&#8221;</p>
<p>Here is some code that will detect many of the possible keys typed into an input field and then show which numeric Apple key code corresponds to that key.</p>

<div class="wp_syntax"><div class="code"><pre class="applescript"><span style="color: #CC0000;">on</span> keyboard up theObject event theEvent
	<span style="color: #CC0000;">if</span> <span style="color: #000000;">the</span> name <span style="color: #CC0000;">of</span> theObject <span style="color: #CC0000;">is</span> <span style="color: #660000;">&quot;inputField&quot;</span> <span style="color: #CC0000;">then</span>
		<span style="color: #808080; font-style: italic;">(* Is this the input field we are typing in?  *)</span>
		<span style="color: #CC0000;">set</span> theKeyPressed <span style="color: #CC0000;">to</span> <span style="color: #66cc66;">&#40;</span>key code <span style="color: #CC0000;">of</span> theEvent<span style="color: #66cc66;">&#41;</span>
		<span style="color: #808080; font-style: italic;">(* Save the key code into a variable *)</span>
		<span style="color: #CC0000;">set</span> theCharacterTyped <span style="color: #CC0000;">to</span> <span style="color: #66cc66;">&#40;</span>character <span style="color: #CC0000;">of</span> theEvent<span style="color: #66cc66;">&#41;</span>
		<span style="color: #808080; font-style: italic;">(* Save the character that was typed *)</span>
		<span style="color: #CC0000;">if</span> theCharacterTyped <span style="color: #CC0000;">is</span> <span style="color: #CC0000;">return</span> <span style="color: #CC0000;">then</span> <span style="color: #CC0000;">set</span> theCharacterTyped <span style="color: #CC0000;">to</span> <span style="color: #660000;">&quot;RET&quot;</span>
		<span style="color: #808080; font-style: italic;">(* The return key doesn't show up nicely in the result, so let's
                replace it with &quot;RET&quot; *)</span>
&nbsp;
		<span style="color: #CC0000;">if</span> theKeyPressed <span style="color: #CC0000;">is</span> <span style="color: #003399;">not</span> <span style="color: #cc66cc;">76</span> <span style="color: #CC0000;">then</span>
			<span style="color: #808080; font-style: italic;">(* 76 is the Apple key code for the &quot;Enter&quot; key 
                        - at least on my keyboard *)</span>
			<span style="color: #CC0000;">set</span> <span style="color: #000000;">the</span> contents <span style="color: #CC0000;">of</span> text field <span style="color: #660000;">&quot;showResult&quot;</span> <span style="color: #CC0000;">of</span> window <span style="color: #660000;">&quot;sampleWindow&quot;</span> <span style="color: #CC0000;">to</span> ¬
				theCharacterTyped <span style="color: #66cc66;">&amp;</span> <span style="color: #660000;">&quot;=&quot;</span> <span style="color: #66cc66;">&amp;</span> theKeyPressed
			<span style="color: #CC0000;">return</span> <span style="color: #003399;">false</span>
			<span style="color: #808080; font-style: italic;">(* Returning false will allow the typing to continue without disruption *)</span>
		<span style="color: #CC0000;">else</span>
			<span style="color: #808080; font-style: italic;">(* The &quot;Enter&quot; key was pressed *)</span>
			display dialog <span style="color: #660000;">&quot;You pressed the enter key, I think.&quot;</span>
			<span style="color: #CC0000;">return</span> <span style="color: #003399;">false</span>
		<span style="color: #CC0000;">end</span> <span style="color: #CC0000;">if</span>
	<span style="color: #CC0000;">end</span> <span style="color: #CC0000;">if</span>
<span style="color: #CC0000;">end</span> keyboard up</pre></div></div>

<p>After checking to see if the user is typing into the input field (which they obviously are in a window that has only one text field receiving this handler), the key code and character of the event are put into a variable for later use (some will simply refer to this directly rather than putting it into a variable first). It then checks to see if the character typed is the return key and changes the variable to &#8220;RET&#8221; so it will show up easier in the output. The code then checks to see if the enter key was pressed (on my keyboard at least) and if not, displays the character pressed, an equals sign, and the corresponding key code. If it thinks the enter key was pressed (if your keyboard also has 76 set to &#8220;enter&#8221;) then it will display a dialog to that effect.  Returning false allows the user to type undisturbed by the events. Set this to &#8220;true&#8221;, if you like, in order to see what happens to the typed text.</p>
<p>You can download the sample code to try this out here: <a href="http://foolsworkshop.com/downloads/keyboardsample.zip">Keyboard Input Sample</a></p>
<p>In the case of my own application, I&#8217;m looking for the user to press the &#8220;return&#8221; (key code 36 on my keyboard) or &#8220;enter&#8221; keys (key code 76) and if this is caught, I will &#8220;set the first responder&#8221; (see upcoming posting) to the next field I want the user to type into, as if they had pressed the &#8220;tab&#8221; key.</p>
]]></content:encoded>
			<wfw:commentRss>http://foolsworkshop.com/applescript/2008/05/reacting-to-keyboard-input/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Activate an Event Handler</title>
		<link>http://foolsworkshop.com/applescript/2008/05/activate-an-event-handler/</link>
		<comments>http://foolsworkshop.com/applescript/2008/05/activate-an-event-handler/#comments</comments>
		<pubDate>Mon, 26 May 2008 14:16:54 +0000</pubDate>
		<dc:creator>K. M. Lawson</dc:creator>
		
		<category><![CDATA[Applescript]]></category>

		<category><![CDATA[Applescript Studio]]></category>

		<guid isPermaLink="false">http://foolsworkshop.com/applescript/2008/05/activate-an-event-handler/</guid>
		<description><![CDATA[This show the important basic step of activating a handler so that code can be added to react to various events.]]></description>
			<content:encoded><![CDATA[<p>This is really basic, and explained in most tutorials for AppleScript Studio out there, but since I haven&#8217;t explained it very eloquently, here is what I mean when I say in various postings that one must activate an event handler before one adds some code.</p>
<p>When you want to write some code for a button press, a menu selection, respond to a keyboard event, etc. in Interface Builder you must explicitly lay out your intentions by activating the event handler in question. For example, if you want to do something in response to the user pressing a key in a text field (see next posting), then:</p>
<p>1. Click on the text field in Interface Builder.<br />
2. Open the AppleScript tab of the inspector.<br />
3. It is good practice to give your object a name here, which can be used to refer to the object in your script.<br />
4. Choose your applescript that you want to attach to this object in the &#8220;Script&#8221; pop-up menu here.<br />
5. Activate the check mark next to &#8220;keyboard up&#8221; in the &#8220;Key&#8221; section of the &#8220;Event Handlers&#8221; pane.</p>
<p><img src="http://foolsworkshop.com/applescript/wp-content/uploads/2008/05/interface-builderscreensnapz001.jpg" width="321" height="382" alt="Interface BuilderScreenSnapz001.jpg" style="padding-top:5px; padding-right:5px; padding-bottom:5px; padding-left:5px;" /></p>
<p>Forgetting to give an object a name, forgetting to assign it to a script and activate the correct event handler are common mistakes I have made that prevented me from getting any results.</p>
<p><strong>A handy shortcut:</strong> You can directly jump to the empty method created by activating the handler by double-clicking the relevant handler.</p>
]]></content:encoded>
			<wfw:commentRss>http://foolsworkshop.com/applescript/2008/05/activate-an-event-handler/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Calling Cocoa String Methods in Applescript Studio</title>
		<link>http://foolsworkshop.com/applescript/2008/05/calling-cocoa-string-methods-in-applescript-studio/</link>
		<comments>http://foolsworkshop.com/applescript/2008/05/calling-cocoa-string-methods-in-applescript-studio/#comments</comments>
		<pubDate>Mon, 26 May 2008 10:52:10 +0000</pubDate>
		<dc:creator>K. M. Lawson</dc:creator>
		
		<category><![CDATA[Applescript]]></category>

		<category><![CDATA[Applescript Studio]]></category>

		<category><![CDATA[Code Sample]]></category>

		<guid isPermaLink="false">http://foolsworkshop.com/applescript/2008/05/calling-cocoa-string-methods-in-applescript-studio/</guid>
		<description><![CDATA[This posting and downloadable sample project shows how to make simple Cocoa method calls directly in AppleScript Studio.]]></description>
			<content:encoded><![CDATA[<p>HAS, the devleoper of <a href="http://appscript.sourceforge.net/" onclick="pageTracker._trackPageview('/outgoing/appscript.sourceforge.net/?referer=');">appscript</a> left a useful comment in response to my earlier posting on the <a href="http://foolsworkshop.com/applescript/2008/05/search-a-string-offset/">offset method</a>. He offered an example of how one might easily and usefully call Cocoa methods to manipulate strings in AppleScript Studio that aren&#8217;t available directly in the AppleScript language.  </p>
<p>If, for example, you wanted to use the existing Cocoa method to make a string all uppercase you could write code for a button that contains something like this:</p>

<div class="wp_syntax"><div class="code"><pre class="applescript"><span style="color: #CC0000;">on</span> clicked theObject
	<span style="color: #CC0000;">if</span> <span style="color: #000000;">the</span> name <span style="color: #CC0000;">of</span> theObject <span style="color: #CC0000;">is</span> <span style="color: #660000;">&quot;makeUppercase&quot;</span> <span style="color: #CC0000;">then</span>
		<span style="color: #CC0000;">set</span> contents <span style="color: #CC0000;">of</span> text field <span style="color: #660000;">&quot;inputField&quot;</span> <span style="color: #CC0000;">of</span> window <span style="color: #660000;">&quot;myWindow&quot;</span> <span style="color: #CC0000;">to</span> call method <span style="color: #660000;">&quot;uppercaseString&quot;</span> <span style="color: #CC0000;">of</span> <span style="color: #66cc66;">&#40;</span>contents <span style="color: #CC0000;">of</span> text field <span style="color: #660000;">&quot;inputField&quot;</span> <span style="color: #CC0000;">of</span> window <span style="color: #660000;">&quot;myWindow&quot;</span><span style="color: #66cc66;">&#41;</span>
	<span style="color: #CC0000;">end</span> <span style="color: #CC0000;">if</span>
<span style="color: #CC0000;">end</span> clicked</pre></div></div>

<p>If, instead, you wanted to have a string only capitalize the first letter of each word, then you would use the Cocoa function &#8220;capitalizedString&#8221; instead.</p>

<div class="wp_syntax"><div class="code"><pre class="applescript"><span style="color: #CC0000;">set</span> contents <span style="color: #CC0000;">of</span> text field <span style="color: #660000;">&quot;inputField&quot;</span> <span style="color: #CC0000;">of</span> window <span style="color: #660000;">&quot;myWindow&quot;</span> <span style="color: #CC0000;">to</span> call method <span style="color: #660000;">&quot;capitalizedString&quot;</span> <span style="color: #CC0000;">of</span> <span style="color: #66cc66;">&#40;</span>contents <span style="color: #CC0000;">of</span> text field <span style="color: #660000;">&quot;inputField&quot;</span> <span style="color: #CC0000;">of</span> window <span style="color: #660000;">&quot;myWindow&quot;</span><span style="color: #66cc66;">&#41;</span></pre></div></div>

<p>You can download an example project with this example here: <a href="http://foolsworkshop.com/downloads/callmethodexample.zip">Call Method Example</a>.</p>
<p>A full list of the Cocoa methods for the NSString class in Cocoa can be found in Apple document <a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/Reference/NSString.html" onclick="pageTracker._trackPageview('/outgoing/developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/Reference/NSString.html?referer=');">NSString Class Reference</a>. Some of these methods need to be handled differently as they may require parameters etc. There is more detail on the <a href="http://developer.apple.com/documentation/AppleScript/Conceptual/StudioBuildingApps/chapter04/chapter_4_section_2.html" onclick="pageTracker._trackPageview('/outgoing/developer.apple.com/documentation/AppleScript/Conceptual/StudioBuildingApps/chapter04/chapter_4_section_2.html?referer=');">call method command</a> in the AppleScript Studio documentation to be found where you can learn more about how to include parameters.</p>
<p>Strings are only a simple beginning, this command opens up a lot of possibilities for using Cocoa methods that may not have equivalents in AppleScript, if done with care.</p>
]]></content:encoded>
			<wfw:commentRss>http://foolsworkshop.com/applescript/2008/05/calling-cocoa-string-methods-in-applescript-studio/feed/</wfw:commentRss>
		</item>
		<item>
		<title>An AppleScript Replace Text Method</title>
		<link>http://foolsworkshop.com/applescript/2008/05/an-applescript-replace-text-method/</link>
		<comments>http://foolsworkshop.com/applescript/2008/05/an-applescript-replace-text-method/#comments</comments>
		<pubDate>Fri, 23 May 2008 07:31:09 +0000</pubDate>
		<dc:creator>K. M. Lawson</dc:creator>
		
		<category><![CDATA[Applescript]]></category>

		<category><![CDATA[Code Sample]]></category>

		<guid isPermaLink="false">http://foolsworkshop.com/applescript/2008/05/an-applescript-replace-text-method/</guid>
		<description><![CDATA[This posting offers a replace text method written by Bruce Phillips.]]></description>
			<content:encoded><![CDATA[<p><a href="http://brucep.net/" onclick="pageTracker._trackPageview('/outgoing/brucep.net/?referer=');">Bruce Phillips</a>, one of the leading posters at MacScripter, <a href="http://brucep.net/2007/replace-text/" onclick="pageTracker._trackPageview('/outgoing/brucep.net/2007/replace-text/?referer=');">posted</a> a very useful method on his blog which you can use to find and replace text in a variable. Below is the code he created and an example so you can test it in the Script Editor.</p>

<div class="wp_syntax"><div class="code"><pre class="applescript"><span style="color: #CC0000;">on</span> replaceText<span style="color: #66cc66;">&#40;</span>find, replace, subject<span style="color: #66cc66;">&#41;</span>
	<span style="color: #CC0000;">set</span> prevTIDs <span style="color: #CC0000;">to</span> text item delimiters <span style="color: #CC0000;">of</span> AppleScript
	<span style="color: #CC0000;">set</span> text item delimiters <span style="color: #CC0000;">of</span> AppleScript <span style="color: #CC0000;">to</span> find
	<span style="color: #CC0000;">set</span> subject <span style="color: #CC0000;">to</span> text items <span style="color: #CC0000;">of</span> subject
&nbsp;
	<span style="color: #CC0000;">set</span> text item delimiters <span style="color: #CC0000;">of</span> AppleScript <span style="color: #CC0000;">to</span> replace
	<span style="color: #CC0000;">set</span> subject <span style="color: #CC0000;">to</span> <span style="color: #660000;">&quot;&quot;</span> <span style="color: #66cc66;">&amp;</span> subject
	<span style="color: #CC0000;">set</span> text item delimiters <span style="color: #CC0000;">of</span> AppleScript <span style="color: #CC0000;">to</span> prevTIDs
&nbsp;
	<span style="color: #CC0000;">return</span> subject
<span style="color: #CC0000;">end</span> replaceText
&nbsp;
<span style="color: #CC0000;">get</span> replaceText<span style="color: #66cc66;">&#40;</span><span style="color: #660000;">&quot;Windows&quot;</span>, <span style="color: #660000;">&quot;the Mac OS&quot;</span>, <span style="color: #660000;">&quot;I love Windows and I will always love Windows and I have always loved Windows.&quot;</span><span style="color: #66cc66;">&#41;</span></pre></div></div>

<p>Mr. Phillips has over 2500 postings at MacScripter and one can learn a lot from <a href="http://bbs.macscripter.net/search.php?action=show_user&amp;user_id=5342" onclick="pageTracker._trackPageview('/outgoing/bbs.macscripter.net/search.php?action=show_user_amp_user_id=5342&referer=');">browsing</a> through them to see the various solutions he has proposed to people&#8217;s problems.</p>
]]></content:encoded>
			<wfw:commentRss>http://foolsworkshop.com/applescript/2008/05/an-applescript-replace-text-method/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Matt Neuburg&#8217;s Advice on Declaring Variables</title>
		<link>http://foolsworkshop.com/applescript/2008/05/matt-neuburgs-advice-on-declaring-variables/</link>
		<comments>http://foolsworkshop.com/applescript/2008/05/matt-neuburgs-advice-on-declaring-variables/#comments</comments>
		<pubDate>Thu, 22 May 2008 02:08:52 +0000</pubDate>
		<dc:creator>K. M. Lawson</dc:creator>
		
		<category><![CDATA[Applescript]]></category>

		<guid isPermaLink="false">http://foolsworkshop.com/applescript/2008/05/matt-neuburgs-advice-on-declaring-variables/</guid>
		<description><![CDATA[As I fiddle with AppleScript Studio, I have been reading AppleScript: The Definitive Guide, 2nd Edition by Matt Neuburg.
Here is a piece of advice he offers after he explains the complexities of scope for properties, global, and local variables in chapter 10:
The ideal way to manage scope, in my view, would be to declare everything. [...]]]></description>
			<content:encoded><![CDATA[<p>As I fiddle with AppleScript Studio, I have been reading AppleScript: The Definitive Guide, 2nd Edition by Matt Neuburg.</p>
<p>Here is a piece of advice he offers after he explains the complexities of scope for properties, global, and local variables in chapter 10:<br />
<blockquote>The ideal way to manage scope, in my view, would be to declare everything. If you need a variable to be visible in this scope and deeper scopes, then declare a property. (In a handler, merely declaring a local will do.) Otherwise, declare a local. Use global declarations sparingly, only for special occasions when separate regions of scope need shared access to a value. If you follow these rules, then any undeclared variable must be a free variable (see the next section). Thus you always know what everything is. Unfortunately, as I&#8217;ve said, AppleScript doesn&#8217;t help, so you can&#8217;t easily and reliably follow these rules, even if you want to.<sup>1</sup></p></blockquote>
<ol class="footnotes"><li id="footnote_0_16" class="footnote"> Quote from section 10.7 </li></ol>]]></content:encoded>
			<wfw:commentRss>http://foolsworkshop.com/applescript/2008/05/matt-neuburgs-advice-on-declaring-variables/feed/</wfw:commentRss>
		</item>
		<item>
		<title>FaceSpan 5 and the HyperCard Dream</title>
		<link>http://foolsworkshop.com/applescript/2008/05/facespan-5-and-the-hypercard-dream/</link>
		<comments>http://foolsworkshop.com/applescript/2008/05/facespan-5-and-the-hypercard-dream/#comments</comments>
		<pubDate>Wed, 21 May 2008 13:37:08 +0000</pubDate>
		<dc:creator>K. M. Lawson</dc:creator>
		
		<category><![CDATA[Applescript]]></category>

		<guid isPermaLink="false">http://foolsworkshop.com/applescript/2008/05/facespan-5-and-the-hypercard-dream/</guid>
		<description><![CDATA[I admit it. I&#8217;m one of those lost HyperCard fans, sulkily roaming through the world awaiting the return of the Messiah. That is why I&#8217;m playing with AppleScript Studio, which, for an amateur like me is incredibly unsatisfying and nowhere near the ease and intuitive beauty of the old HyperCard or SuperCard environment (though SuperCard [...]]]></description>
			<content:encoded><![CDATA[<p>I admit it. I&#8217;m one of those lost HyperCard fans, sulkily roaming through the world awaiting the return of the Messiah. That is why I&#8217;m playing with AppleScript Studio, which, for an amateur like me is incredibly unsatisfying and nowhere near the ease and intuitive beauty of the old HyperCard or SuperCard environment (though <a href="http://www.supercard.us/" onclick="pageTracker._trackPageview('/outgoing/www.supercard.us/?referer=');">SuperCard</a> is still lurking around in undead form, with a full Scottish resistance being waged out of Edinburgh with <a href="http://www.runrev.com/home/product-family/" onclick="pageTracker._trackPageview('/outgoing/www.runrev.com/home/product-family/?referer=');">Revolution</a>, I&#8217;m tired of paying so much money for solutions that always seem on the verge of disappearing from the market).</p>
<p>I&#8217;m hoping that FaceSpan 5 will bring back the dream, greatly surpass the failures of alternatives like SuperCard, Revolution, overcome some of the problems of pure AppleScript and avoid the complexities of AppleScript Studio. And&#8230;is this asking for too much?&#8230;I hope the price will be reasonable.</p>
<p>Read more about the development of FaceSpan 5, which is currently in alpha, on their official <a href="http://www.latenightsw.com/blogfs5/" onclick="pageTracker._trackPageview('/outgoing/www.latenightsw.com/blogfs5/?referer=');">blog</a>. I&#8217;m just a little concerned that the last posting was in September of 2007, as of this posting.</p>
<p>The Facespan mailing list <a href="http://tech.groups.yahoo.com/group/fs-talk/message/286" onclick="pageTracker._trackPageview('/outgoing/tech.groups.yahoo.com/group/fs-talk/message/286?referer=');">offers</a> a bit more news.<br />
<span id="more-15"></span><br />
After some users asked for an update, the developer, Mark Alldritt, responded<br />
<blockquote>
The simple answer is that I massively underestimated the effort needed to turn FaceSpan into the product I want it to be. This has impacted all of my other work as FaceSpan 5 has expanded to consume almost all my resources and delayed the release of other products (Script Debugger 4.5, Affrus 2).</p>
<p>This said, the FaceSpan 5 is progressing. The FaceSpan IDE now includes Script Debugger&#8217;s AppleScript editing and debugging. This means that you can single step through the code in your project and manage breakpoints directly within the IDE. Script Debugger&#8217;s dictionary windows, including the Explorer, are also fully integrated into the FaceSpan IDE.</p>
<p>&#8230;</p>
<p>There are still some key missing features (eg. tables, outlines) which I want to implement before opening the testing program to the public. However, if you want to begin using FaceSpan 5 in its current form, you can join the private Alpha testing program by emailing me privately.</p></blockquote>
<p>It is sad that this looks like a one man show.</p>
]]></content:encoded>
			<wfw:commentRss>http://foolsworkshop.com/applescript/2008/05/facespan-5-and-the-hypercard-dream/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Ruby for Scriptable Applications</title>
		<link>http://foolsworkshop.com/applescript/2008/05/ruby-for-scriptable-applications/</link>
		<comments>http://foolsworkshop.com/applescript/2008/05/ruby-for-scriptable-applications/#comments</comments>
		<pubDate>Wed, 21 May 2008 13:26:20 +0000</pubDate>
		<dc:creator>K. M. Lawson</dc:creator>
		
		<category><![CDATA[Applescript]]></category>

		<guid isPermaLink="false">http://foolsworkshop.com/applescript/2008/05/ruby-for-scriptable-applications/</guid>
		<description><![CDATA[I don&#8217;t like AppleScript, to be perfectly honest. However, its deceptively English-like language was something that reminded me of the HyperCard glory days of my childhood, which where the only reason a non-programming historian like myself every made me want to tinker with coding.
I would love to really get good at languages like Python and [...]]]></description>
			<content:encoded><![CDATA[<p>I don&#8217;t like AppleScript, to be perfectly honest. However, its deceptively English-like language was something that reminded me of the HyperCard glory days of my childhood, which where the only reason a non-programming historian like myself every made me want to tinker with coding.</p>
<p>I would love to really get good at languages like Python and Ruby, especially after a few years of playing with a muddy language like PHP.  However, I just haven&#8217;t ever gotten around to it.  </p>
<p>A number of sites I have come across mention rb-appscript. This will allow you to write Ruby scripts that can script applications normally only scriptable by AppleScript. While I haven&#8217;t tried it and it doesn&#8217;t seem to be too useful for AppleScript Studio, it may be worth a look for people who are frustrated by the limitations of AppleScript and want the power and beauty of Ruby.</p>
<p>The homepage can be found here:</p>
<p><a href="http://appscript.sourceforge.net/rb-appscript/index.html" onclick="pageTracker._trackPageview('/outgoing/appscript.sourceforge.net/rb-appscript/index.html?referer=');">rb-appscript</a> </p>
<p>Here is information on how to <a href="http://appscript.sourceforge.net/rb-appscript/install.html" onclick="pageTracker._trackPageview('/outgoing/appscript.sourceforge.net/rb-appscript/install.html?referer=');">install</a> it. If you have the developer tools installed, this may amount to nothing more than the command:</p>
<pre>sudo gem install rb-appscript</pre>
<p>If you want a solution to help you use Ruby for developing Cocoa applications, there is something called <a href="http://rubycocoa.sourceforge.net/HomePage" onclick="pageTracker._trackPageview('/outgoing/rubycocoa.sourceforge.net/HomePage?referer=');">Ruby Cocoa</a>, which provides a bridge to Cocoa. I&#8217;m reluctant to go out and learn Ruby only to find that the frustrations I already have with an official Apple supported environment like AppleScript Studio in XCode might be compounded when working through this kind of bridge environment. If Ruby Cocoa continues to mature and grow wider in support, I may eventually jump the AppleScript wagon and study the Ruby Way.</p>
]]></content:encoded>
			<wfw:commentRss>http://foolsworkshop.com/applescript/2008/05/ruby-for-scriptable-applications/feed/</wfw:commentRss>
		</item>
		<item>
		<title>AppleScript-Studio Mailing List</title>
		<link>http://foolsworkshop.com/applescript/2008/05/applescript-studio-mailing-list/</link>
		<comments>http://foolsworkshop.com/applescript/2008/05/applescript-studio-mailing-list/#comments</comments>
		<pubDate>Wed, 21 May 2008 13:15:53 +0000</pubDate>
		<dc:creator>K. M. Lawson</dc:creator>
		
		<category><![CDATA[Applescript Studio]]></category>

		<guid isPermaLink="false">http://foolsworkshop.com/applescript/2008/05/applescript-studio-mailing-list/</guid>
		<description><![CDATA[Another resource for AppleScript Studio that I have found really useful (through its archives page) is the official Apple mailing list for ASS. 
Apple&#8217;s Mailing List for AppleScript Studio:
AppleScript-Studio Home
AppleScript-Studio Archives
It is also great to see interesting interventions from people such as the author Matt Neuburg and many other experienced scripters that I have seen [...]]]></description>
			<content:encoded><![CDATA[<p>Another resource for AppleScript Studio that I have found really useful (through its archives page) is the official Apple mailing list for ASS. </p>
<p>Apple&#8217;s Mailing List for AppleScript Studio:</p>
<p><a href="http://lists.apple.com/mailman/listinfo/applescript-studio" onclick="pageTracker._trackPageview('/outgoing/lists.apple.com/mailman/listinfo/applescript-studio?referer=');">AppleScript-Studio Home</a><br />
<a href="http://lists.apple.com/archives/applescript-studio" onclick="pageTracker._trackPageview('/outgoing/lists.apple.com/archives/applescript-studio?referer=');">AppleScript-Studio Archives</a></p>
<p>It is also great to see interesting interventions from people such as the author Matt Neuburg and many other experienced scripters that I have seen replying with some of the best posts at MacScripter.</p>
]]></content:encoded>
			<wfw:commentRss>http://foolsworkshop.com/applescript/2008/05/applescript-studio-mailing-list/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Tell a Button to Trigger a Menu</title>
		<link>http://foolsworkshop.com/applescript/2008/05/tell-a-button-to-trigger-a-menu/</link>
		<comments>http://foolsworkshop.com/applescript/2008/05/tell-a-button-to-trigger-a-menu/#comments</comments>
		<pubDate>Wed, 21 May 2008 12:40:37 +0000</pubDate>
		<dc:creator>K. M. Lawson</dc:creator>
		
		<category><![CDATA[Applescript]]></category>

		<category><![CDATA[Applescript Studio]]></category>

		<category><![CDATA[Code Sample]]></category>

		<guid isPermaLink="false">http://foolsworkshop.com/applescript/2008/05/tell-a-button-to-trigger-a-menu/</guid>
		<description><![CDATA[This posting explains how you can get a button to trigger a menu item when pressed using the "perform action" command.]]></description>
			<content:encoded><![CDATA[<p>One of the first things I went poking around for on MacScripter <a href="http://bbs.macscripter.net/" onclick="pageTracker._trackPageview('/outgoing/bbs.macscripter.net/?referer=');">forums</a> was simply how to get a button to trigger a menu. I was looking for a simple &#8220;do menu item&#8221; kind of command. I don&#8217;t remember where I found it but this was apparently all I needed to do is activate the click handler for the button and assign it the correct script in Interface Builder and then add a script such as the one below:</p>

<div class="wp_syntax"><div class="code"><pre class="applescript"><span style="color: #CC0000;">on</span> clicked theObject
    <span style="color: #CC0000;">if</span> <span style="color: #000000;">the</span> name <span style="color: #CC0000;">of</span> theObject <span style="color: #CC0000;">is</span> <span style="color: #660000;">&quot;doMenuItem&quot;</span> <span style="color: #CC0000;">then</span>
	   <span style="color: #CC0000;">tell</span> menu item <span style="color: #660000;">&quot;menuItemName&quot;</span> <span style="color: #CC0000;">of</span> menu <span style="color: #660000;">&quot;menuFile&quot;</span> <span style="color: #CC0000;">of</span> main menu <span style="color: #CC0000;">to</span> perform action
    <span style="color: #CC0000;">end</span> <span style="color: #CC0000;">if</span>
<span style="color: #CC0000;">end</span> clicked</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://foolsworkshop.com/applescript/2008/05/tell-a-button-to-trigger-a-menu/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Add a Toolbar</title>
		<link>http://foolsworkshop.com/applescript/2008/05/add-a-toolbar/</link>
		<comments>http://foolsworkshop.com/applescript/2008/05/add-a-toolbar/#comments</comments>
		<pubDate>Wed, 21 May 2008 12:36:12 +0000</pubDate>
		<dc:creator>K. M. Lawson</dc:creator>
		
		<category><![CDATA[Applescript]]></category>

		<category><![CDATA[Applescript Studio]]></category>

		<guid isPermaLink="false">http://foolsworkshop.com/applescript/2008/05/add-a-toolbar/</guid>
		<description><![CDATA[This posting shows you how you can add a toolbar in Interface Builder if you have OS X 10.5 Leopard and mentions some of the problems of this approach.]]></description>
			<content:encoded><![CDATA[<p>There is a sample project that comes with installations of XCode which will show you how to create a toolbar at the top of windows. This method appears to be the only way of creating a standard window toolbar if you are designing an application for OS X 10.4 or earlier versions. You can find this example code here on your hard drive here:</p>
<p>/Developer/Examples/AppleScript Studio/Simple Toolbar</p>
<p>For Leopard users who don&#8217;t mind building applications that require OS X 10.5 or higher, you can now create toolbars directly in Interface Builder with the NSToolbar class. </p>
<p><img src="http://foolsworkshop.com/applescript/wp-content/uploads/2008/05/interface-builderscreensnapz002.jpg" width="338" height="362" alt="NSToolbar" style="padding-top:5px; padding-right:5px; padding-bottom:5px; padding-left:5px;" /></p>
<p>Add the class to your window, and you will get a series of default buttons. You can add buttons to the toolbar by adding NSToolbarItem (the item to the right with the &#8220;?&#8221; image in it) and can add images for the toolbar via a popup menu in the inspector.</p>
<p>The Simple Toolbar sample scripts controlled the toolbar buttons through the &#8220;clicked toolbar item&#8221; handler of the window containing the toolbar, which confused me when I tried to use NSToolbar without generating the toolbar directly in the applescript. After much frustration, I discovered that the toolbar buttons were scripted through the &#8220;clicked&#8221; handler as any other button in the window might be. There appears to be no need to necessarily use &#8220;clicked toolbar item&#8221; at all.</p>
<p><strong>UPDATE:</strong> I posted to MacScripter on a problem I had with buttons that are added or re-added when the toolbar is customized: <a href="http://bbs.macscripter.net/viewtopic.php?id=25599" onclick="pageTracker._trackPageview('/outgoing/bbs.macscripter.net/viewtopic.php?id=25599&referer=');">NSToolbar error when customizing the toolbar</a></p>
<p><strong>UPDATE:</strong> Another MacSripter <a href="http://bbs.macscripter.net/viewtopic.php?id=25589" onclick="pageTracker._trackPageview('/outgoing/bbs.macscripter.net/viewtopic.php?id=25589&referer=');">posting</a> by regulus6633 points to problems using the new toolbar. Apparently there are problems when referring to any non-button objects on the toolbar (such as pop-up menu or a search field). My own tinkering confirms this.</p>
]]></content:encoded>
			<wfw:commentRss>http://foolsworkshop.com/applescript/2008/05/add-a-toolbar/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Search a String: Offset</title>
		<link>http://foolsworkshop.com/applescript/2008/05/search-a-string-offset/</link>
		<comments>http://foolsworkshop.com/applescript/2008/05/search-a-string-offset/#comments</comments>
		<pubDate>Tue, 20 May 2008 08:11:07 +0000</pubDate>
		<dc:creator>K. M. Lawson</dc:creator>
		
		<category><![CDATA[Applescript]]></category>

		<category><![CDATA[Code Sample]]></category>

		<guid isPermaLink="false">http://foolsworkshop.com/applescript/2008/05/search-a-string-offset/</guid>
		<description><![CDATA[This posting introduces the applescript "offset" command for searching strings.]]></description>
			<content:encoded><![CDATA[<p>There are a lot of handy string functions in most languages. You can find a list of equivalents for various Python string functions <a href="http://aurelio.net/doc/as4pp.html" onclick="pageTracker._trackPageview('/outgoing/aurelio.net/doc/as4pp.html?referer=');">here</a>. One commonly used string function is <a href="http://docs.info.apple.com/article.html?path=AppleScript/2.1/en/as192.html" onclick="pageTracker._trackPageview('/outgoing/docs.info.apple.com/article.html?path=AppleScript/2.1/en/as192.html&referer=');">offset</a>, which can find a string. If you are searching for the word &#8220;needle&#8221; in a string variable called &#8220;haystack&#8221; then doing this:</p>

<div class="wp_syntax"><div class="code"><pre class="applescript">offset <span style="color: #CC0000;">of</span> <span style="color: #660000;">&quot;needle&quot;</span> <span style="color: #CC0000;">in</span> haystack</pre></div></div>

<p>will return the start position of &#8220;needle&#8221; and if it doesn&#8217;t find needle at all, will return 0.</p>
]]></content:encoded>
			<wfw:commentRss>http://foolsworkshop.com/applescript/2008/05/search-a-string-offset/feed/</wfw:commentRss>
		</item>
		<item>
		<title>For Loops in AppleScript: Repeat</title>
		<link>http://foolsworkshop.com/applescript/2008/05/for-loops-in-applescript-repeat/</link>
		<comments>http://foolsworkshop.com/applescript/2008/05/for-loops-in-applescript-repeat/#comments</comments>
		<pubDate>Tue, 20 May 2008 06:56:11 +0000</pubDate>
		<dc:creator>K. M. Lawson</dc:creator>
		
		<category><![CDATA[Applescript]]></category>

		<category><![CDATA[Code Sample]]></category>

		<guid isPermaLink="false">http://foolsworkshop.com/applescript/2008/05/for-loops-in-applescript-repeat/</guid>
		<description><![CDATA[This posting introduces the way to create loops in Applescript.]]></description>
			<content:encoded><![CDATA[<p>This <a href="http://www.mactech.com/articles/mactech/Vol.20/20.12/RepeatLoops/index.html" onclick="pageTracker._trackPageview('/outgoing/www.mactech.com/articles/mactech/Vol.20/20.12/RepeatLoops/index.html?referer=');">article</a> on MacTech summarizes the loop flow control structures in AppleScript which apparently amounts to the &#8220;repeat&#8221; command.</p>

<div class="wp_syntax"><div class="code"><pre class="applescript"><span style="color: #CC0000;">repeat</span>
   <span style="color: #808080; font-style: italic;">-- code</span>
<span style="color: #CC0000;">end</span> <span style="color: #CC0000;">repeat</span></pre></div></div>

<p>this will repeat indefinitely but you can exit the repeat within such a block by adding something like this:</p>

<div class="wp_syntax"><div class="code"><pre class="applescript"><span style="color: #CC0000;">if</span> stopMe <span style="color: #66cc66;">=</span> <span style="color: #003399;">true</span> <span style="color: #CC0000;">then</span>
   <span style="color: #CC0000;">exit</span> <span style="color: #CC0000;">repeat</span>
<span style="color: #CC0000;">end</span> <span style="color: #CC0000;">if</span></pre></div></div>

<p>You can also repeat a fixed number of times:</p>

<div class="wp_syntax"><div class="code"><pre class="applescript"><span style="color: #CC0000;">repeat</span> <span style="color: #cc66cc;">5</span> <span style="color: #CC0000;">times</span>
   <span style="color: #808080; font-style: italic;">-- code</span>
<span style="color: #CC0000;">end</span> <span style="color: #CC0000;">repeat</span></pre></div></div>

<p>You can also repeat until some condition:</p>

<div class="wp_syntax"><div class="code"><pre class="applescript"><span style="color: #CC0000;">repeat</span> <span style="color: #CC0000;">while</span> keepGoing <span style="color: #66cc66;">=</span> <span style="color: #003399;">true</span>
   <span style="color: #808080; font-style: italic;">-- code</span>
<span style="color: #CC0000;">end</span> <span style="color: #CC0000;">repeat</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="applescript"><span style="color: #CC0000;">repeat</span> <span style="color: #CC0000;">until</span> stopMe <span style="color: #66cc66;">=</span> <span style="color: #003399;">true</span>
   <span style="color: #808080; font-style: italic;">-- code</span>
<span style="color: #CC0000;">end</span> <span style="color: #CC0000;">repeat</span></pre></div></div>

<p>Finally there is a kind of repeat which is familiar to anyone who has used increments in for loops in other programming languages:</p>

<div class="wp_syntax"><div class="code"><pre class="applescript"><span style="color: #CC0000;">repeat</span> <span style="color: #CC0000;">with</span> x <span style="color: #CC0000;">from</span> <span style="color: #cc66cc;">1</span> <span style="color: #CC0000;">to</span> <span style="color: #cc66cc;">10</span>
   <span style="color: #808080; font-style: italic;">-- code which can refer to the number x which increases with each repeat</span>
<span style="color: #CC0000;">end</span> <span style="color: #CC0000;">repeat</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://foolsworkshop.com/applescript/2008/05/for-loops-in-applescript-repeat/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Responding to a Chosen Menu Item</title>
		<link>http://foolsworkshop.com/applescript/2008/05/responding-to-a-chosen-menu-item/</link>
		<comments>http://foolsworkshop.com/applescript/2008/05/responding-to-a-chosen-menu-item/#comments</comments>
		<pubDate>Tue, 20 May 2008 04:19:00 +0000</pubDate>
		<dc:creator>K. M. Lawson</dc:creator>
		
		<category><![CDATA[Applescript]]></category>

		<category><![CDATA[Applescript Studio]]></category>

		<category><![CDATA[Code Sample]]></category>

		<guid isPermaLink="false">http://foolsworkshop.com/applescript/2008/05/responding-to-a-chosen-menu-item/</guid>
		<description><![CDATA[This posting demonstrates how you can respond to a chosen menu.]]></description>
			<content:encoded><![CDATA[<p>More basics. After you create a menu and a menu item in Interface Builder, in the last tab of the inspector give it a name, select the applescript in your project where you will be adding the script for the menu item, and then give it an event handler by checking Menu: Choose Menu Item in the list of possible Event Handlers listed below.</p>

<div class="wp_syntax"><div class="code"><pre class="applescript"><span style="color: #CC0000;">on</span> choose menu item theObject
	<span style="color: #CC0000;">if</span> <span style="color: #000000;">the</span> name <span style="color: #CC0000;">of</span> theObject <span style="color: #CC0000;">is</span> <span style="color: #660000;">&quot;myMenuItem&quot;</span> <span style="color: #CC0000;">then</span>
		display dialog <span style="color: #660000;">&quot;You chose my new menu item.&quot;</span>
	<span style="color: #CC0000;">end</span> <span style="color: #CC0000;">if</span>
<span style="color: #CC0000;">end</span> choose menu item</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://foolsworkshop.com/applescript/2008/05/responding-to-a-chosen-menu-item/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Responding to a Clicked Button</title>
		<link>http://foolsworkshop.com/applescript/2008/05/responding-to-a-clicked-button/</link>
		<comments>http://foolsworkshop.com/applescript/2008/05/responding-to-a-clicked-button/#comments</comments>
		<pubDate>Tue, 20 May 2008 04:15:41 +0000</pubDate>
		<dc:creator>K. M. Lawson</dc:creator>
		
		<category><![CDATA[Applescript]]></category>

		<category><![CDATA[Applescript Studio]]></category>

		<category><![CDATA[Code Sample]]></category>

		<guid isPermaLink="false">http://foolsworkshop.com/applescript/2008/05/responding-to-a-clicked-button/</guid>
		<description><![CDATA[More basics. After you create an button in Interface Builder, in the last tab of the inspector give it a name, select the applescript in your project where you will be adding the script for the button, and then give it an event handler by checking Action: Clicked in the list of possible Event Handlers [...]]]></description>
			<content:encoded><![CDATA[<p>More basics. After you create an button in Interface Builder, in the last tab of the inspector give it a name, select the applescript in your project where you will be adding the script for the button, and then give it an event handler by checking Action: Clicked in the list of possible Event Handlers listed below.</p>
<p>Then go back to your script and you can begin scripting the button in XCode. For example:</p>

<div class="wp_syntax"><div class="code"><pre class="applescript"><span style="color: #CC0000;">on</span> clicked theObject
	<span style="color: #CC0000;">if</span> <span style="color: #000000;">the</span> name <span style="color: #CC0000;">of</span> theObject <span style="color: #CC0000;">is</span> <span style="color: #660000;">&quot;myButton&quot;</span> <span style="color: #CC0000;">then</span>
		display dialog <span style="color: #660000;">&quot;You pushed a button.&quot;</span>
	<span style="color: #CC0000;">end</span> <span style="color: #CC0000;">if</span>
<span style="color: #CC0000;">end</span> clicked</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://foolsworkshop.com/applescript/2008/05/responding-to-a-clicked-button/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Change the Contents of Text Fields</title>
		<link>http://foolsworkshop.com/applescript/2008/05/change-the-contents-of-text-fields/</link>
		<comments>http://foolsworkshop.com/applescript/2008/05/change-the-contents-of-text-fields/#comments</comments>
		<pubDate>Tue, 20 May 2008 04:12:32 +0000</pubDate>
		<dc:creator>K. M. Lawson</dc:creator>
		
		<category><![CDATA[Applescript]]></category>

		<category><![CDATA[Applescript Studio]]></category>

		<category><![CDATA[Code Sample]]></category>

		<guid isPermaLink="false">http://foolsworkshop.com/applescript/2008/05/change-the-contents-of-text-fields/</guid>
		<description><![CDATA[This is pretty basic, but we all need to start somewhere. To change the contents of a text field (any NSTextField, including Labels), simple issue this kind of command:

set contents of text field &#34;myTextField&#34; of window &#34;myWindow&#34; to &#34;Hello, World.&#34;

Make sure the &#8220;name&#8221; (not the &#8220;title&#8221;) of your target object (in this case &#8220;myTextField&#8221;) is [...]]]></description>
			<content:encoded><![CDATA[<p>This is pretty basic, but we all need to start somewhere. To change the contents of a text field (any NSTextField, including Labels), simple issue this kind of command:</p>

<div class="wp_syntax"><div class="code"><pre class="applescript"><span style="color: #CC0000;">set</span> contents <span style="color: #CC0000;">of</span> text field <span style="color: #660000;">&quot;myTextField&quot;</span> <span style="color: #CC0000;">of</span> window <span style="color: #660000;">&quot;myWindow&quot;</span> <span style="color: #CC0000;">to</span> <span style="color: #660000;">&quot;Hello, World.&quot;</span></pre></div></div>

<p>Make sure the &#8220;name&#8221; (not the &#8220;title&#8221;) of your target object (in this case &#8220;myTextField&#8221;) is correct in your NIB file in Interface Builder.</p>
]]></content:encoded>
			<wfw:commentRss>http://foolsworkshop.com/applescript/2008/05/change-the-contents-of-text-fields/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
