用来修正错误编码的文件名的 Safari 插件

我之前[讨论过](/2008/02/17/cocoa-nsstring-decoding-error/)一次这种文件名的错误编码,为了在浏览器下载时的不必手工修正这个问题,这里提供一个 Safari 的 SIMBL 插件: SafariURLFix。

使用步骤如下:

1. 如果没装过,先[安装 SIMBL](http://www.culater.net/software/SIMBL/SIMBL.php);

2. 下载 [SafariURLFix.zip](http://jjgod.org/program/SafariURLFix.zip),解压后,放到 `~/Library/Application Support/SIMBL/Plugins` 目录 (如果没这个目录就自己创建);

3. 在 Terminal 中输入:

`defaults write com.apple.Safari JJURLsToFix -dict newsmth.net GBK`

其中 newsmth.net 为你希望应用修正的网站域名。也可以打开 `~/Library/Preferences/com.apple.Safari.plist` 文件自己编辑 `JJURLsToFix` 这个 Dictionary,自行添加新的,见附图。Edit Safari Preferences Manually

4. 重新启动 Safari,尝试下载[这样](http://att.newsmth.net/att.php?p.719.275418.308.png)的文件,看看文件名是否被正确纠正了。

如果还有什么问题,欢迎在下面提出。

用 AppleScript 来辅助 Pages 排版

[Pages](http://www.apple.com/iwork/pages/) 的混合语言排版功能一直为人诟病 (实际上 Pages 的多语言支持也一直很弱,甚至比不上 TextEdit),比如像组合字体 (combined font) 这样在排版软件中很常见的功能也迟迟没有提供,所以经常有人说用 Pages 排版中英文混合的文章是一种折磨。

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

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](http://appscript.sourceforge.net/) 接口来调用 (它的语法比 [ScriptingBridge](http://www.apple.com/applescript/features/scriptingbridge.html) 要友好很多),作用是,扫描所有 Pages 打开的文档,把所有的汉字的字体设为 SimSun,因为仅仅作为一个示例,所以没有加任何参数。

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

before

然后运行:

python format-pages.py

这时候切换回 Pages 就能看到效果,如下图所示。

after

其实这个脚本还可以做很多其他的变化,比如加入界面来选择字体、只是转换当前选中的部分等等等等,至少了解一点 AppleScript 的调用方式就可以尝试,这里不赘述了。

CoreAVC 与 CorePlayer

CorePlayer Pro for OS X

昨天碰巧翻到一个叫 [CoreAVC for Linux](http://code.google.com/p/coreavc-for-linux) 的项目,其实应该之前很早就听说过,因为这个项目在去年五月份的时候曾经被 Google Code 停止提供服务,因为“[DMCA complaint](http://en.wikipedia.org/wiki/CoreAVC#The_CoreAVC-For-Linux_DMCA_complaint)”,但现在又恢复了,不过可能 patch 更新得不够及时,不一定能够用在 svn HEAD 的 mplayer 上。

CoreAVC for Linux 到底是个怎么样的项目呢?众所周知的是,CoreAVC 是目前公认软解 H.264 效率最高的解码器,在 Windows 平台有提供,价格是 $15 (不过大部分 Windows 用户都用破解版本的)。开发这个解码器的公司还把它移植到了 Palm, Symbian, Windows CE 等平台上,是移动平台中最有名的一个通用播放器,叫 CorePlayer。

从去年二月开始,CorePlayer 被移植到了 Windows 和 Mac OS X 平台上,但官方没有提供给 Mac OS X 平台的 CoreAVC (假如有的话,应该是 Perian, Flip4Mac 那样作为 QuickTime 插件的形式,但不知道这个公司出于什么考虑,并没有像 Windows 平台那样提供)。而 Linux 平台下也没有提供公开销售的版本。所以 CoreAVC for Linux 就是为了能在 Linux 平台下使用这个解码器而产生的。

虽然细节比较复杂,我现在也不大了然,但原理也不难理解,修改 mplayer 的 DirectShow 支持代码,类似调用 RealMedia 的 DirectShow 插件那样来调用 CoreAVC 的 DirectShow 插件。开发者说有[两种修改方法](http://code.google.com/p/coreavc-for-linux/wiki/MplayerInstallation):

1. 使用一个外部程序 dshowserver 来提供服务,修改 mplayer 使之能够支持 dshowserver,这种方法能够适用于 x86_64 和 ia32
2. 直接修改 mplayer 的 Win32 dshow 代码使之支持 CoreAVC,只适用于 ia32

作者说第一种是推荐的方法,但不能用于 Windows 和 Mac。而第二种完全没有提到具体步骤,也没见到具体的 patch。

正巧看到 [CorePlayer Pro for OS X](http://www.mobihand.com/product.asp?id=16794),虽然没提供试用版本,但好在也不算贵 ($17),就买了一个试试。下面是一点结论:

No AC3 support in CorePlayer OS X

1. 最大的问题是音频解码支持很弱,不支持 AC3 解码,不支持 DTS 解码,而且发布之后一年内始终没得到解决,开发者很有点言而无信,一开始在去年二月说“数周内”能解决,到 12 月还没提供,又改说我们可能要依赖平台提供的功能实现 (Windows 下用 DirectShow, Mac 下用 Core Audio),这也没问题,可这都二月了,还没解决。感觉相比移动平台,这个公司并不怎么注重桌面平台的支持。

2. 界面很土,非要做跨平台的界面,结果用起来非常不方便,更不用说完全不 Mac 化了。

3. 解码 H.264 的效率确实比其他任何 Mac 平台的解码器都要好,手头一个 1080p 的 Fight Club 的 BDRe, 用 Plex 时的 CPU 占用率在 120% ~ 150% 左右,用 CorePlayer 时占用率在 75% ~ 80% 左右。

4. 不支持外挂字幕,而且短期内不打算支持。

总的说来,我觉得他们最大的决策错误就是不提供单独的 CoreAVC,非要自己做播放器,结果给自己带来了过重的开发负担,比如界面、音频编码器这些,如果只提供一个 QuickTime 插件,就压根不需要他们操心了。H.264 的解码效率是好,但也没有好到超过一个数量级的程度,在 Snow Leopard 和新一代 Mac 提供了显卡硬解码支持的背景下,就更难让人看好这个产品的前景了。

How to test a proxy autoconfiguration file

Due to the existence of [Greal Firewall](en.wikipedia.org/wiki/Golden_Shield_Project), I have a terribly long `proxy.pac` file. Apparently, how to maintain that becomes a problem. Regularly, I use [git](http://git-scm.com) to keep a “stable” version and make updates on it.

Recently I just found the script stop working for no good reason, because the proxy server I’m using is working, and I tried manually choose a proxy server (by entering its address and port into my browser directly) it also worked, so apparently there is something wrong with the script.

However, it has been a while since I last commit my changes to this script back to git. So there are some changes I wish to keep and I don’t want to do a binary search to find out the problem (Yep, I’m a lazy guy).

A few googling got me a tool called [pactester](http://code.google.com/p/pactester/), which turned out to be very useful. Basically it’s a Perl wrap of [SpiderMonkey](http://www.mozilla.org/js/spidermonkey) JavaScript engine. Since the proxy autoconfiguration script is just a subset of plain JavaScript, it can safely executes that with SpiderMonkey and find out where is the problem.

So I installed it and did one test:

$ pactester -p ~/Documents/Miscs/proxy.pac -u ‘http://blog.iphone-dev.org’
Use of uninitialized value in numeric ne (!=) at pactester line 137.
Error: SyntaxError: missing ) after condition at line 98:
if (dnsDomainIs(host, “cubes.fr”) return “SOCKS 127.0.0.1:7777”;

So that’s the problem. Fixed it, everything is back to normal again!

That’s a small tip on debugging a complex pac script, hope it helps.

A closer look at Classics.app

A Screenshot of Classics

“[Classics](http://www.classicsapp.com/)” is a great product, it shows us iPhone developers what an *elegant* ebook reader can be, so I bought it almost instantly after it’s released. I’ve been chatting with my friends about this app for a while, now I’d like to give a more closer examination to it from the perspective of a typographer and a programmer. Especially its weaknesses.

Illustrated by my favorite graphic designer, [David Lanham](http://dlanham.com), Classics tries its best to provide a traditional book reading experience (that’s why it’s called “Classics”). It contains the following books, even I’ve read most of them in Chinese long time ago, thanks to Classics, it’s still a fascinating experience to read them again in English:

* *[20,000 Leagues Under the Sea](http://en.wikipedia.org/wiki/Twenty_Thousand_Leagues_Under_the_Sea)* by [Jules Verne](http://en.wikipedia.org/wiki/Jules_Verne)
* *[A Christmas Carol](http://en.wikipedia.org/wiki/A_Christmas_Carol)* by [Charles Dickens](http://en.wikipedia.org/wiki/Charles_Dickens) [Added in version 1.1]
* *[Alice in Wonderland](http://en.wikipedia.org/wiki/Alice_in_Wonderland)* by [Lewis Carroll](http://en.wikipedia.org/wiki/Lewis_Carroll)
* *[Flatland](http://en.wikipedia.org/wiki/Flatland)* by [Edwin Abbott Abbott](http://en.wikipedia.org/wiki/Edwin_Abbott_Abbott)
* *[Gulliver’s Travels](http://en.wikipedia.org/wiki/Gulliver%27s_Travels)* by [Jonathan Swift](http://en.wikipedia.org/wiki/Jonathan_Swift)
* *[The Hound of the Baskervilles](http://en.wikipedia.org/wiki/Hound_of_the_Baskervilles)* by Sir [Arthur Conan Doyle](http://en.wikipedia.org/wiki/Arthur_Conan_Doyle)
* *[Adventures of Huckleberry Finn](http://en.wikipedia.org/wiki/Adventures_of_Huckleberry_Finn)* by [Mark Twain](http://en.wikipedia.org/wiki/Mark_Twain)
* *[Paradise Lost](http://en.wikipedia.org/wiki/Paradise_Lost)* by [John Milton](http://en.wikipedia.org/wiki/John_Milton)
* *[Robinson Crusoe](http://en.wikipedia.org/wiki/Robinson_Crusoe)* by [Daniel Defoe](http://en.wikipedia.org/wiki/Daniel_Defoe)
* *[The Call of the Wild](http://en.wikipedia.org/wiki/The_Call_Of_The_Wild)* by [Jack London](http://en.wikipedia.org/wiki/Jack_London)
* *[The Jungle Book](http://en.wikipedia.org/wiki/The_Jungle_Book)* by [Rudyard Kipling](http://en.wikipedia.org/wiki/Rudyard_Kipling)
* *[The Metamorphosis](http://en.wikipedia.org/wiki/The_Metamorphosis)* by [Franz Kafka](http://en.wikipedia.org/wiki/Franz_Kafka)
* *[The Time Machine](http://en.wikipedia.org/wiki/The_Time_Machine)* by [H. G. Wells](http://en.wikipedia.org/wiki/H._G._Wells)

However, there are still some details to be improved.
Continue reading “A closer look at Classics.app”