<?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>jjgod / blog &#187; applescript</title>
	<atom:link href="http://blog.jjgod.org/tag/applescript/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.jjgod.org</link>
	<description>Random notes &#38; thoughts by Jiang Jiang.</description>
	<lastBuildDate>Mon, 16 Jan 2012 11:08:59 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>用 AppleScript 来辅助 Pages 排版</title>
		<link>http://blog.jjgod.org/2009/03/03/reformat-pages-with-appscript/</link>
		<comments>http://blog.jjgod.org/2009/03/03/reformat-pages-with-appscript/#comments</comments>
		<pubDate>Tue, 03 Mar 2009 04:04:24 +0000</pubDate>
		<dc:creator>jjgod</dc:creator>
				<category><![CDATA[Mac]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Tools]]></category>
		<category><![CDATA[Typography]]></category>
		<category><![CDATA[applescript]]></category>
		<category><![CDATA[appscript]]></category>
		<category><![CDATA[iwork]]></category>
		<category><![CDATA[pages]]></category>

		<guid isPermaLink="false">http://blog.jjgod.org/?p=365</guid>
		<description><![CDATA[Pages 的混合语言排版功能一直为人诟病 (实际上 Pages 的多语言支持也一直很弱，甚至比不上 TextEdit)，比如像组合字体 (combined font) 这样在排版软件中很常见的功能也迟迟没有提供，所以经常有人说用 Pages 排版中英文混合的文章是一种折磨。 昨天看到 Apple 版上的一篇文章，便想起来试试 Page &#8217;09 新增的 AppleScript 功能，其实用到的功能在之前的 Pages 版本中应该也有，不过我手头没有更早的版本，所以无法试验了。可以点这里看完整的脚本，其实核心代码非常短： from appscript import * pages = app(id="com.apple.iWork.Pages") for doc in pages.documents(): words = doc.words() i = 0 for word in words: i += 1 if isch(word[0][0]): doc.words[i].font_name.set("SimSun") 这个脚本没有直接用 AppleScript，而是通过第三方提供的 py-appscript 接口来调用 (它的语法比 ScriptingBridge 要友好很多)，作用是，扫描所有 [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.apple.com/iwork/pages/">Pages</a> 的混合语言排版功能一直为人诟病 (实际上 Pages 的多语言支持也一直很弱，甚至比不上 TextEdit)，比如像组合字体 (combined font) 这样在排版软件中很常见的功能也迟迟没有提供，所以经常有人说用 Pages 排版中英文混合的文章是一种折磨。</p>

<p>昨天看到 Apple 版上的一篇文章，便想起来试试 Page &#8217;09 新增的 AppleScript 功能，其实用到的功能在之前的 Pages 版本中应该也有，不过我手头没有更早的版本，所以无法试验了。可以点这里看<a href="http://att.newsmth.net/att.php?s.719.285617.1216.py">完整的脚本</a>，其实核心代码非常短：</p>

<pre><code>from appscript import *
pages = app(id="com.apple.iWork.Pages")

for doc in pages.documents():
    words = doc.words()
    i = 0

    for word in words:
        i += 1
        if isch(word[0][0]):
            doc.words[i].font_name.set("SimSun")
</code></pre>

<p>这个脚本没有直接用 AppleScript，而是通过第三方提供的 <a href="http://appscript.sourceforge.net/">py-appscript</a> 接口来调用 (它的语法比 <a href="http://www.apple.com/applescript/features/scriptingbridge.html">ScriptingBridge</a> 要友好很多)，作用是，扫描所有 Pages 打开的文档，把所有的汉字的字体设为 SimSun，因为仅仅作为一个示例，所以没有加任何参数。</p>

<p>使用方法是，先<a href="http://appscript.sourceforge.net/py-appscript/install.html">安装 py-appscript</a>，然后打开 Pages，随便输入一段中文和英文混杂的文字，比如刚才的“在50ml的PBS缓冲中加入15mg的HCl使得最终pH为5”这句，一开始加入时因为默认字体是 Helvetica，所以英文字母和数字都用了 Helvetica，汉字则使用了 Helvetica 的默认 Fallback, 也就是 STXihei，如下图所示。</p>

<p><img src="http://blog.jjgod.org/wp-content/uploads/2009/03/before.png" alt="before" title="before" width="446" height="76" class="alignright size-full wp-image-366" /></p>

<p>然后运行:</p>

<pre><code>python format-pages.py
</code></pre>

<p>这时候切换回 Pages 就能看到效果，如下图所示。</p>

<p><img src="http://blog.jjgod.org/wp-content/uploads/2009/03/after.png" alt="after" title="after" width="437" height="55" class="alignnone size-full wp-image-367" /></p>

<p>其实这个脚本还可以做很多其他的变化，比如加入界面来选择字体、只是转换当前选中的部分等等等等，至少了解一点 AppleScript 的调用方式就可以尝试，这里不赘述了。</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.jjgod.org/2009/03/03/reformat-pages-with-appscript/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>

