October 29, 2010

在finder中開啟終端機

先前曾經找過從finder直接開啟該目錄下的終端機的作法。今天又找了一個用小機器人(Automator)達到這件事的作法。參考網址

照參考網址做大概就可以了。只不過有一點小問題就是,在新的automator中並沒有save as plugin的選項。後來找到這篇討論裡面提到新的automator把這個選項取消掉了,所以如果要做同樣的事情,請在新增的時候選擇"服務"就可以了。

具體的步驟如下
1.打開automator,開啟一個新的服務。
2.從左邊拉一個AppleScript進來,script內容如下。on run {input, parameters}
tell application "Terminal"
activate
if (the (count of the window) = 0) or ¬
(the busy of window 1 = true) then
tell application "System Events"
keystroke "n" using command down
end tell
end if
do script "cd \"" & (POSIX path of ¬
(input as string)) & "\"" in window 1
end tell
return input
end run

3.存檔即可。

操作畫面如下。

直接用action script的作法有一個缺點就是,每次開起來都會多開一個在~/底下的terminal,雖然無礙,但是惱人。用小機器人的這個作法雖然不會出現兩個視窗了,但缺點就是有一點慢... orz 實在是有一好沒有兩好呀...

10/31後記。
仔細研究過兩邊的apple script之後找出可以讓他開出來只有一個視窗的辦法。雖然有點笨,不過總算可以達到目的。
程式碼如下-- this subroutine processes does the actual work
--
on process_item(this_item)
set thePath to quoted form of POSIX path of this_item
tell application "Terminal"
activate
if (the (count of the window) = 1) then
tell application "System Events"
keystroke "w" using command down
end tell
end if
do script with command "source ~/.bashrc; cd " & thePath
tell window frontmost
set custom title to this_item
end tell
end tell
end process_item

其中tell application "System Events"
keystroke "w" using command down
end tell
這一段就是把前一個視窗關掉的指令。
這樣就不會再跑兩個視窗出來了。

October 27, 2010

eclipse syntax highlight settings

今天把工作環境搞死了... (昏)

花半天時間重新建過eclipse+ADT,最後要把eclipse裡面改過用的很習慣的黑色底色的syntax highlighting移植到新的workspace裡,找到這篇有詳細的設定存放位置。

具體的位置在workspace內.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.jdt.ui.prefs這個位置。複製到新的workspace即可。

後記。
eclipse中所有跟syntax highlight相關的設定如底下圖中這些檔案。(當然去掉.bak才是對的。)

October 26, 2010

ProGuard on android LVL

今天一整天被android的混淆搞的烏煙瘴氣,害我又浪費掉一整天的時間。

最近先前的案子要發佈到android market上,臨時說禮拜五前要上,於是昨天花了一天弄那包LVL,下半前終於搞定。本以為今天只要再做個混淆就可以release了,沒想到ProGuard又耗了我一天。

終究原因如下。在google所release的market licensing的那包library裡面有用到enum這個東西。由於先前聽說在android上使用enum會有某些奇怪的問題,所以我們自己寫的code一律都是使用static final int來做。

沒想到的是,就在這包android的ref design裡面竟然有用到enum。混淆之後enum的value/valueof被混淆過,於是就不能用了。

在ProGuard官方網站裡面有提到這點,詳細請參考這邊

具體的作法就是把-keepclassmembers enum * {
public static **[] values();
public static ** valueOf(java.lang.String);
}
這段加到ant build的xml中ProGuard那段裡面即可。