<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
		>
<channel>
	<title>Comments on: AppleScript &#8211; a frustrating&#160;beginning</title>
	<atom:link href="http://hexmen.com/blog/2009/04/applescript-a-frustrating-beginning/feed/" rel="self" type="application/rss+xml" />
	<link>http://hexmen.com/blog/2009/04/applescript-a-frustrating-beginning/</link>
	<description>On programming, and other things...</description>
	<lastBuildDate>Mon, 30 Jan 2012 07:45:01 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
	<item>
		<title>By: Ash</title>
		<link>http://hexmen.com/blog/2009/04/applescript-a-frustrating-beginning/comment-page-1/#comment-31231</link>
		<dc:creator>Ash</dc:creator>
		<pubDate>Thu, 16 Apr 2009 22:56:40 +0000</pubDate>
		<guid isPermaLink="false">http://hexmen.com/blog/?p=84#comment-31231</guid>
		<description>Thanks Martin.

I think a few of my frustrations were self-inflicted: the language guide is pretty good if you work through it properly.  Trying to dive straight in via the index just didn&#039;t work at all.  After going back and (skim-)reading the &lt;a href=&quot;http://developer.apple.com/documentation/applescript/conceptual/applescriptlangguide/conceptual/ASLR_lexical_conventions.html&quot; rel=&quot;nofollow&quot;&gt;lexical conventions&lt;/a&gt; (handy for list syntax) and chapter on &lt;a href=&quot;http://developer.apple.com/documentation/applescript/conceptual/applescriptlangguide/conceptual/ASLR_fundamentals.html&quot; rel=&quot;nofollow&quot;&gt;applescript fundamentals&lt;/a&gt; really helped - and lead me to the rather handy &lt;a href=&quot;http://developer.apple.com/documentation/applescript/conceptual/applescriptlangguide/reference/ASLR_classes.html&quot; rel=&quot;nofollow&quot;&gt;class reference for the core AppleScript classes&lt;/a&gt; - though I&#039;ve yet to discover if the Script Utility also has core class documentation readily available.

It also turns out my early attempts to get all URLs out of Safari were stymied by some incompatibility having both WebKit and the Safari 4 Beta installed.  In fact I get errors if I try chucking the code at WebKit now (I&#039;ve only two browser windows open, but &lt;code&gt;every window&lt;/code&gt; iterates over &lt;em&gt;three&lt;/em&gt;.  Not sure what&#039;s going on there...)

Even after skimming the language reference, I still can&#039;t figure out why it&#039;s OK to inline one of the &lt;code&gt;set&lt;/code&gt;/&lt;code&gt;repeat&lt;/code&gt; intermediaries, but not the other.   I end up with this - which works fine, but it&#039;d be nice to kill the &lt;code&gt;try&lt;/code&gt;/&lt;code&gt;end try&lt;/code&gt; and the &lt;code&gt;tabURLs&lt;/code&gt; variable:

&lt;pre&gt;&lt;code&gt;
set URLlist to {}
tell app &quot;WebKit&quot;
  -- repeat with &#039;windows&#039; works fine:
  repeat with browserwindow in windows
    try
      -- accessing tabs chucks an error for spurious windows
      tabs of browserwindow

      -- this repeat fails:
      -- repeat with tabURL in (URL of tabs of browserwindow)

      -- so we MUST use a temp variable...?
      set tabURLs to URL of tabs of browserwindow
      repeat with tabURL in tabURLs
        set URLlist to URLlist &amp; tabURL
      end repeat
    end try
  end repeat
end tell
return URLlist
&lt;/code&gt;&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>Thanks Martin.</p>
<p>I think a few of my frustrations were self-inflicted: the language guide is pretty good if you work through it properly.  Trying to dive straight in via the index just didn&#8217;t work at all.  After going back and (skim-)reading the <a href="http://developer.apple.com/documentation/applescript/conceptual/applescriptlangguide/conceptual/ASLR_lexical_conventions.html" rel="nofollow">lexical conventions</a> (handy for list syntax) and chapter on <a href="http://developer.apple.com/documentation/applescript/conceptual/applescriptlangguide/conceptual/ASLR_fundamentals.html" rel="nofollow">applescript fundamentals</a> really helped &#8211; and lead me to the rather handy <a href="http://developer.apple.com/documentation/applescript/conceptual/applescriptlangguide/reference/ASLR_classes.html" rel="nofollow">class reference for the core AppleScript classes</a> &#8211; though I&#8217;ve yet to discover if the Script Utility also has core class documentation readily available.</p>
<p>It also turns out my early attempts to get all URLs out of Safari were stymied by some incompatibility having both WebKit and the Safari 4 Beta installed.  In fact I get errors if I try chucking the code at WebKit now (I&#8217;ve only two browser windows open, but <code>every window</code> iterates over <em>three</em>.  Not sure what&#8217;s going on there&#8230;)</p>
<p>Even after skimming the language reference, I still can&#8217;t figure out why it&#8217;s OK to inline one of the <code>set</code>/<code>repeat</code> intermediaries, but not the other.   I end up with this &#8211; which works fine, but it&#8217;d be nice to kill the <code>try</code>/<code>end try</code> and the <code>tabURLs</code> variable:</p>
<pre><code>
set URLlist to {}
tell app "WebKit"
  -- repeat with 'windows' works fine:
  repeat with browserwindow in windows
    try
      -- accessing tabs chucks an error for spurious windows
      tabs of browserwindow

      -- this repeat fails:
      -- repeat with tabURL in (URL of tabs of browserwindow)

      -- so we MUST use a temp variable...?
      set tabURLs to URL of tabs of browserwindow
      repeat with tabURL in tabURLs
        set URLlist to URLlist &#038; tabURL
      end repeat
    end try
  end repeat
end tell
return URLlist
</code></pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: Martin Michel</title>
		<link>http://hexmen.com/blog/2009/04/applescript-a-frustrating-beginning/comment-page-1/#comment-31228</link>
		<dc:creator>Martin Michel</dc:creator>
		<pubDate>Thu, 16 Apr 2009 19:52:11 +0000</pubDate>
		<guid isPermaLink="false">http://hexmen.com/blog/?p=84#comment-31228</guid>
		<description>• checking a file exists (without using Finder or throwing an error)

AppleScript code:

&lt;pre&gt;&lt;code&gt;set itemexists to my itempathexists(path to desktop as text)
-- set itemexists to my itempathexists(&quot;Foo:&quot;)&lt;/code&gt;&lt;/pre&gt;

&lt;pre&gt;&lt;code&gt;on itempathexists(itempath)
	try
		set itemalias to itempath as alias
		return true
	on error
		return false
	end try
end itempathexists&lt;/code&gt;&lt;/pre&gt;

• list files in a directory (without using do shell script or using Finder)

AppleScript code:

&lt;pre&gt;&lt;code&gt;set folderfiles to list folder (path to desktop) with invisibles
-- set folderfiles to list folder (path to desktop) without invisibles&lt;/code&gt;&lt;/pre&gt;

• get the urls of all tabs of all windows of safari

AppleScript code:

&lt;pre&gt;&lt;code&gt;set URLlist to {}
tell application &quot;Safari&quot;
	set browserwindows to every window
	repeat with browserwindow in browserwindows
		set browserwindowURLs to URL of tabs of browserwindow
		repeat with browserwindowURL in browserwindowURLs
			set URLlist to URLlist &amp; browserwindowURL
		end repeat
	end repeat
end tell
return URLlist&lt;/code&gt;&lt;/pre&gt;

•  but where the hell’s the core language documentation?

AppleScript Language Guide:

http://developer.apple.com/documentation/applescript/conceptual/applescriptlangguide/index.html

Hope it helps :-)

Best regards from Berlin!</description>
		<content:encoded><![CDATA[<p>• checking a file exists (without using Finder or throwing an error)</p>
<p>AppleScript code:</p>
<pre><code>set itemexists to my itempathexists(path to desktop as text)
-- set itemexists to my itempathexists("Foo:")</code></pre>
<pre><code>on itempathexists(itempath)
	try
		set itemalias to itempath as alias
		return true
	on error
		return false
	end try
end itempathexists</code></pre>
<p>• list files in a directory (without using do shell script or using Finder)</p>
<p>AppleScript code:</p>
<pre><code>set folderfiles to list folder (path to desktop) with invisibles
-- set folderfiles to list folder (path to desktop) without invisibles</code></pre>
<p>• get the urls of all tabs of all windows of safari</p>
<p>AppleScript code:</p>
<pre><code>set URLlist to {}
tell application "Safari"
	set browserwindows to every window
	repeat with browserwindow in browserwindows
		set browserwindowURLs to URL of tabs of browserwindow
		repeat with browserwindowURL in browserwindowURLs
			set URLlist to URLlist &amp; browserwindowURL
		end repeat
	end repeat
end tell
return URLlist</code></pre>
<p>•  but where the hell’s the core language documentation?</p>
<p>AppleScript Language Guide:</p>
<p><a href="http://developer.apple.com/documentation/applescript/conceptual/applescriptlangguide/index.html" rel="nofollow">http://developer.apple.com/documentation/applescript/conceptual/applescriptlangguide/index.html</a></p>
<p>Hope it helps <img src='http://hexmen.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p>Best regards from Berlin!</p>
]]></content:encoded>
	</item>
</channel>
</rss>

