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

<channel>
	<title>cockscomblog &#187; AppleScript</title>
	<atom:link href="http://blog.cockscomb.info/tag/applescript/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.cockscomb.info</link>
	<description>cockscomb on blog</description>
	<lastBuildDate>Sun, 25 Oct 2009 03:12:33 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Access the desktop picture with AppleScript</title>
		<link>http://blog.cockscomb.info/2009/05/05/access-the-desktop-picture-with-applescript/</link>
		<comments>http://blog.cockscomb.info/2009/05/05/access-the-desktop-picture-with-applescript/#comments</comments>
		<pubDate>Tue, 05 May 2009 13:16:30 +0000</pubDate>
		<dc:creator>cockscomb</dc:creator>
				<category><![CDATA[Mac]]></category>
		<category><![CDATA[AppleScript]]></category>

		<guid isPermaLink="false">http://blog.cockscomb.info/?p=96</guid>
		<description><![CDATA[AppleScript は様々な用途に使えるマルチなプログラミング言語ですが、今回はデスクトップピクチャにアクセスする方法を紹介したいと思います。というのも、色々と調べてみると、Mac OS X Leopard から新た [...]]]></description>
			<content:encoded><![CDATA[<p>AppleScript は様々な用途に使えるマルチなプログラミング言語ですが、今回はデスクトップピクチャにアクセスする方法を紹介したいと思います。というのも、色々と調べてみると、Mac OS X Leopard から新たに加わった「Desktop Suite」へのアクセスを用いた実例が見当たらなかったためです。</p>
<p>「スクリプトエディタ」の「ライブラリ」から、「System Events」を開いてみます。この中には実に多くの「Suites」が存在していますが、今回用いるのはもちろん「Desktop Suite」です。色々と書いてありますが、今回はデスクトップピクチャに指定のパスにある画像を設定、また現在の画像があるパスを取得できれば良いとします。</p>
<h3>デスクトップピクチャを設定する</h3>
<pre style="color:#20F;font-size:12px;font-family:CourierNewPSMT;"><strong>tell</strong> <span style="color:#00F">application</span> <span style="color:#000">"System Events"</span>
    <strong>set</strong> <span style="color:#00F">picture</span> <strong>of</strong> <span style="color:#00F">current desktop</span> <strong>to</strong> <span style="color:#000">"/Library/Desktop Pictures/Nature/Aurora.jpg"</span>
<strong>end</strong> <strong>tell</strong></pre>
<p>まずは上記のスクリプトを実行してみましょう。デスクトップピクチャが Leopard 標準のものになったと思います。見ていただければ分かるように、適当なパスを指定するだけでデスクトップピクチャが変更されます。簡単ですね。</p>
<h3>デスクトップピクチャを取得する</h3>
<pre style="color:#20F;font-size:12px;font-family:CourierNewPSMT;"><strong>tell</strong> <span style="color:#00F">application</span> <span style="color:#000">"System Events"</span>
    <strong>set</strong> <span style="color:#370">theFile</span> <strong>to</strong> <span style="color:#00F">picture</span> <strong>of</strong> <span style="color:#00F">current desktop</span> <strong>as</strong> <span style="color:#00F">alias</span>
    <strong>get</strong> <span style="color:#00F">POSIX path</span> <strong>of</strong> <span style="color:#370">theFile</span>
<strong>end</strong> <strong>tell</strong></pre>
<p>次のこちらを実行してみましょう。現在のデスクトップピクチャへのパスが返ってくることと思います。今設定しているデスクトップピクチャがどこにあるのか分からなくなったときに便利ですね。</p>
<p>それで本来ならば仕組みなどをご説明したいところですが、全然分からないので割愛します。AppleScript は予想以上に深くてよく分かりませんでした。誰か分かる方がいたら教えてください。</p>
<p>そもそも何故こんなものを作ったかといいますと、アプリケーションからデスクトップピクチャを操作する方法を探していて、Apple Event を送るのに割と手軽だったからです。NSAppleScript クラスをうまく使えば簡単ですね。</p>
<p>ということで、ImageUp にデスクトップピクチャ変更機能を組み込むなどしていますが、思ったよりも微妙な感じで残念です。デスクトップピクチャは頻繁に変更されるようには出来てないみたいですね。そりゃそうか。</p>
<p>余談ですが、AppleScript のシンタックスハイライトに「<a href="http://d.hatena.ne.jp/zariganitosh/20090222/1235458945">ザリガニが見ていた&#8230;。</a>」さんの AppleScript を使用させていただきました。これはおそろしく便利です。この場を借りてお礼申し上げます。</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.cockscomb.info/2009/05/05/access-the-desktop-picture-with-applescript/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
