preload
May 19

打開 Terminal 輸入下列指令就可以了 :

defaults write com.apple.systempreferences TMShowUnsupportedNetworkVolumes 1

這樣在 System Preferences -> Time Machine 就可以設定你要用 SMB or AFP 備份.

如果要取消, 輸入下列指令 :

defaults write com.apple.systempreferences TMShowUnsupportedNetworkVolumes 0

Tagged with:
Jan 14

在蘋果裡面網路設定很好用. 蘋果可以按照你不同地點給予不同網路環境設定profile. 例如, 在家裡撥接ADSL然後撥VPN回公司, 在辦公室用固定ip. 在會議室設定無線網路…etc 不同環境都會有不同的 profile. 甚至, 我在辦公室還有不同 profile. 例如, 上班用固定ip. 然後, 有些特殊情況要用另外一組 ip. 這時候 Location profile 就很好用.

就在 System Preferences (系統偏好) -> Network (網路) -> Location 下拉就可以編輯不同的 profile. 當你編輯好不同情境的 profile 後, 你就可以在蘋果那 選 Location.

當然用滑鼠選比較快. 但是如果要遠端執行切換 profile. 那就要靠 scselect (Select system configuration “location”) 指令來完成

例如, 我要選 Home 那就用下列指令 :

HOST:~ username$ scselect Home
CurrentSet updated to A3F0DE9C-C708-43FE-9D1D-F9230BB31C61 (Home)

如果有不懂. 歡迎留言交流. 我相信我沒有寫很仔細. :$

Tagged with:
Dec 01

如何在終端機打開圖形界面的應用程式?

一般而言, 打開應用程式要透過 Finder 進到 Applications 慢慢找某特定的應用程式. 然後點兩下執行它. 雖然, 常用的應用程式大部份都會依個人偏好放在 Dock 上方便執行. 但是, 總是會有些程式放在 Dock 上. 所以透過 Finder 尋找應用程式然後執行. 某種程度而言算是有點瑣碎. 對有些重度使用 Terminal 的使用者會認為, 如果能用某指令就能打開圖形界面的應用程式那是最好不過的. 尤其透過遠端登入要打開某個程式.那更是方便. 因為遠端沒辦法直接對某應用程式直接執行.

至於, 該怎麼遠端或是透過終端機打開圖形界面應用程式? 簡單來說就使用 open 這個指令. 先大概看一下基本的說明如下 :

$ open
Usage: open [-e] [-t] [-f] [-W] [-R] [-n] [-g] [-h] [-b ] [-a ] [filenames] [--args arguments]
Help: Open opens files from a shell.
      By default, opens each file using the default application for that file.
      If the file is in the form of a URL, the file will be opened as a URL.
Options:
      -a                Opens with the specified application.
      -b                Opens with the specified application bundle identifier.
      -e                Opens with TextEdit.
      -t                Opens with default text editor.
      -f                Reads input from standard input and opens with TextEdit.
      -R, --reveal      Selects in the Finder instead of opening.
      -W, --wait-apps   Blocks until the used applications are closed (even if they were already running).
          --args        All remaining arguments are passed in argv to the application's main() function instead of opened.
      -n, --new         Open a new instance of the application even if one is already running.
      -g, --background  Does not bring the application to the foreground.
      -h, --header      Searches header file locations for headers matching the given filenames, and opens them.

上面的內容就稍微自己看一下吧 : )

就示範幾個範例, 讓你參考.
開啓計算機

open -a Calculator

開啓 photoshop

open -a Adobe\ Photoshop\ CS4

用 Smultron 打開桌面上的 README.txt 檔案

open -a Smultron ~/Desktop/README.txt

打開某個網址

open http://liho.tw/

打開某張圖

open sexy.jpg

當然你可以把這些指令編輯道 .profile 裡面. 以方便日後開啓程式.

alias photoshop="open -a Adobe\ Photoshop\ CS4"

之後打 photoshop 就可以開啓photoshop.

遠端開啓的話, 也是一樣的方式. 只是記得在 System Preferences 開啓 Remote Login 的選項. 讓你自己能從遠端登入開啓圖形應用程式.

Tagged with:
Sep 18

必須先安裝 Xcode. 先直接印 SetFile 指令的說明檔

# /Developer/Tools/SetFile
Usage: SetFile [option...] file...
    -a attributes     # attributes (lowercase = 0, uppercase = 1)*
    -c creator        # file creator
    -d date           # creation date (mm/dd/[yy]yy [hh:mm[:ss] [AM | PM]])*
    -m date           # modification date (mm/dd/[yy]yy [hh:mm[:ss] [AM | PM]])*
        -P                                # perform action on symlink instead of following it
    -t type           # file type

    Note: The following attributes may be used with the -a option:
        A   Alias file
        B   Bundle
        C   Custom icon*
        D   Desktop*
        E   Hidden extension*
        I   Inited*
        M   Shared (can run multiple times)
        N   No INIT resources
        L   Locked
        S   System (name locked)
        T   Stationery
        V   Invisible*
        Z   Busy*

    Note: Items marked with an asterisk (*) are allowed with folders
    Note: Period (.) represents the current date and time.
    Note: [yy]yy < 100 assumes 21st century, e.g. 20yy

假設我不想在 Finder 看到硬碟的 /opt 目錄.
我就使用下列命令即可 :

# /Developer/Tools/SetFile -a V /opt
Tagged with:
Jun 11

To delete a user from the command line in 10.5:

1. Boot into single user mode. Hold Command-s at startup.
開機進入單人模式. 在開啟電腦後馬上按 Command-s.

2. Check the filesystem:
檢查檔案系統
# /sbin/fsck -fy

3. If no remaining errors, mount the filesystem:
如果沒有任何錯誤, 就掛載檔案系統
# /sbin/mount -uw /

4. Start up directory services:
啟動目錄服務
# launchctl load /System/Library/LaunchDaemons/com.apple.DirectoryServices.plist
Note that single user mode said to use com.apple.DirectoryServicesLocal.plist, but that didn’t work — this did.

5. Find what groups the user belongs to:
找出該使用者所屬群組
# dscl . -list /groups GroupMembership | grep username
– repeat for each group except for the user’s own group.

6. Remove the group corresponding to the username:
移除使用者對應的群組
# dscl . delete /groups/username
(this may not be necessary — you may get an error that the group doesn’t exist; you can ignore it and go on).

7. Remove the user account:
移除使用者帳戶
# dscl . delete /users/username

8. At this point, you may wish to remove or archive the user folder in /Users.
在此,你也許想移除在 /Users 內的使用者目錄.

9. You may wish to remove the .AppleSetupDone file in /var/db to cause the Setup Assistant to run when next booted.
你也許想移除在 /var/db 目錄內 .AppleSetupDone 檔案. 這樣下次開幾就會出現設定幫手(Setup Assistant).

10. All done? Type reboot to reboot the system or shutdown -h now to shut down the system.
都設定好了? 打 reboot 重新啟動電腦或是下 shutdown -h now 關機.

From : Delete users accounts from command line in 10.5

不見得用得到.但是先紀錄下來.

Tagged with:
Apr 13

假設你有個檔案叫做 “readme.txt” 那你可以用下列指令將該檔案轉成朗讀. 輸出檔名為 “readme.aiff”

say -f “readme.txt” -o “readme.aiff”

Tagged with:
Feb 23

情境 :

短時間內我還沒有足夠的錢購買 Sony DT 11-18mm 廣角鏡頭. 但是我有下列兩張照片很想把這兩張照片合併. 雖然我可以用 photoshop 處理, 但是很麻煩且步驟繁雜.

工具 :

我使用 DoubleTake 完成了這個任務 :) 只要分別將照片拖曳放入 DoubleTake 儲存檔案.這樣就完成了. 雖然裡面有一些微調工具.我也不是很清楚它真正的功能.

下列圖片就是完成圖 :)

還算滿容易的.但是這個軟體要付費.就覺得很 Orz.

Tagged with:
Feb 12

在台灣 Mac 出廠設定都是中文. 有時候看得很不習慣. 雖然 Mac 提供使用者自訂自己語言的偏好. 但是 Login Window 還是不能改變成我想要的語言設定.有點沮喪. :’( 後來在網路上找到一篇. Tutorial: Change the language of Mac OS X. 讓我開心許多 :P

只要在 Terminal 裡面打入下列指令就可以設定 Login Window 的語言 :

sudo "/System/Library/CoreServices/Language Chooser.app/Contents/MacOS/Language Chooser"

Tagged with:
Jan 23

由於要使用 OpenAFS 所以必需在 Mac 上設定成 Kerberos 認證. 但是光有 Kerberos 認證密碼還不夠. 還要取得 afs 的認可. 通常可以在 Terminal 下打 aklog 的命令. 但是當使用者登入 Mac 後, 還要要求使用者打一個指令, 使用者會跳腳. 只好努力的問 Google 大師. 慶幸的是終於有突破了. 使用者不用在敲 aklog 就可以取得 afs token.

首先, 先去下載 http://www.ibiblio.org/macsupport/kerberos/10.4/afs-login.sh 這個 script. 主要讓使用者登入後再後置執行 aklog. 在蘋果上的設定是

sudo defaults write com.apple.loginwindow LoginHook /Library/Management/afs-login.sh

編輯 /etc/ttys 檔案

vi /etc/ttys

# Look for a line that reads:
#console “/System/Library/CoreServices/loginwindow.app/Contents/MacOS/loginwindow” vt100 on secure window=/System/Library/CoreServices/WindowServer onoption=”/usr/libexec/getty std.9600″

# Edit this line so that it reads as follows (there are no breaks in this line):
#console “/System/Library/CoreServices/loginwindow.app/Contents/MacOS/loginwindow -LoginHook /Library/Management/afs-login.sh” vt100 on secure window=/System/Library/CoreServices/WindowServer onoption=”/usr/libexec/getty std.9600″

這樣就可以了 :P 這個搞好久. 終於搞定 :D

HOWTO Get AFS token (aklog) Mac OS X after Login Kerberos?

To get afs token in Linux is quite easy. But, getting afs token in Mac OS X is very painful. After you login Kerberos in Mac OS X, you have to type “aklog” command to get your AFS token when you use OpenAFS. Otherwise, you have no permission to access OpenAFS files. This problem was stuck me for while. Finally, I found the solution. I asume you already have Kerberos servers ready and your Mac could talk with Kerveros servers.

You have to download this (http://www.ibiblio.org/macsupport/kerberos/10.4/afs-login.sh) script. In my case, I modified  the script as following:

########## Begin Script ##########

#!/bin/tcsh -f
############################ afs-login.sh ##########################
# Mike Bydalek | mbydalek at contentconnections com
# Use 'defaults write com.apple.loginwindow LoginHook' to make this
# script run upon user login.
####################################################################
# very minor mods by bil hays (bil_hays at unc edu)
############

### Description ###
#
# This script runs aklog for the particular user upon logging in
# to grab AFS tokens.

### Debug/testing sanity check ###
if ( $#argv < 1 ) then
echo "No user specified!"
exit 1
endif

### Script action ###
# We just need to run aklog
/usr/bin/aklog
su $1 -c /usr/bin/aklog

### Always exit with 0 status
exit 0
########## End Script ##########

After you got the script, you could put that script whatever you like. I prefer to put the script in /Library/Management directory. We also need to tell Mac OS X to do the Login Hook. Please see the following command :
sudo defaults write com.apple.loginwindow LoginHook /Library/Management/afs-login.sh
You also need to edit /etc/ttys file in order to make Login Hook functional.
vi /etc/ttys
# Look for a line that reads: #console "/System/Library/CoreServices/loginwindow.app/Contents/MacOS/loginwindow" vt100 on secure window=/System/Library/CoreServices/WindowServer onoption="/usr/libexec/getty std.9600" # Edit this line so that it reads as follows (there are no breaks in this line): #console "/System/Library/CoreServices/loginwindow.app/Contents/MacOS/loginwindow -LoginHook /Library/Management/afs-login.sh" vt100 on secure window=/System/Library/CoreServices/WindowServer onoption="/usr/libexec/getty std.9600" You could use "klist" command to check your tokens.
$ klist
Kerberos 5 ticket cache: 'API:Initial default ccache'
Default principal: USERNAME@XXXXX.EDU.TW

Valid Starting     Expires            Service Principal
01/23/09 16:11:42  02/22/09 16:11:42  krbtgt/XXXXX.EDU.TW@XXXXX.EDU.TW
	renew until 01/23/09 16:11:42
01/23/09 16:11:43  02/22/09 16:11:42  afs@XXXXX.EDU.TW
	renew until 01/23/09 16:11:42

References :

Tagged with:
Dec 17

如何聽遠端 iTunes 的音樂? 或許這個需求不是那麼大. 但是覺得好玩就把它記錄下來.

首先你要先下載 RendezvousProxy 軟體. 建議使用 Java 版本. Binary 在我的 Leopard 似乎不能用. 或是你也可以下載原始碼自己編譯. 我沒自己編譯過, 如果你成功編譯歡迎向大家分享.

再來, 你需要建立個 ssh 通道(tunnel). 在 [linux notes] to bind remote port as local port through ssh tunnel 曾經介紹如何建立 ssh 通道. 語法如下 :

ssh username@xxx.xxx.xxx.xxx -fN -L 3689:localhost:3689

如果你本機端沒分享你的 iTunes 可以把遠端 iTunes port(3689) 綁在自己端的 iTunes port. 假設你有分享你的 iTunes 那你就用下列指令 :

ssh username@xxx.xxx.xxx.xxx -fN -L 36890:localhost:3689

連線後, 再打開剛剛下載的 RendezvousProxy 軟體.

按 Add Host

然後分別在IP Address 輸入 localhost, Port 輸入 3689 如果你用 36890 也就請你輸入 36890. Host Label 就看你想怎麼命名. Service Type 選 _daap._tcp. (iTunes Host). 再按 Add 按鈕

這時候你就可以打開 iTunes 將會看到遠端的分享如下 :

如此一來你就可以聽到來至另外一端的 iTunes Library. :D

Reference : How to stream your iTunes library across the web for free

Tagged with: