顯示具有 Mac OS X 標籤的文章。 顯示所有文章
顯示具有 Mac OS X 標籤的文章。 顯示所有文章

2020年7月28日 星期二

MacOS Tips - Command Lines


OSX 終端機使用指含播放 mp3 檔案的方法

  • 使用 afplay 
    • afplay <mp3 filename>
語法說明
$ afplay -h

    Audio File Play
    Version: 2.0
    Copyright 2003-2013, Apple Inc. All Rights Reserved.
    Specify -h (-help) for command options

Usage:
afplay [option...] audio_file

Options: (may appear before or after arguments)
  {-v | --volume} VOLUME
    set the volume for playback of the file
  {-h | --help}
    print help
  { --leaks}
    run leaks analysis
  {-t | --time} TIME
    play for TIME seconds
  {-r | --rate} RATE
    play at playback rate
  {-q | --rQuality} QUALITY
    set the quality used for rate-scaled playback (default is 0 - low quality, 1 - high quality)
  {-d | --debug}
    debug print output


2011年10月14日 星期五

在Mac OS X初次使用Arduino實驗板

今天在HackingThursday 聚會,朋友借了一塊Arduino Mega 2560實驗板,現場測試。本文便是將開發設定相關心得做個紀錄。
當然可參考原文的說明手冊
首先至http://arduino.cc/en/Main/Software此下載Mac OS X安裝檔http://arduino.googlecode.com/files/arduino-0022.dmg
arduino_install1
開啟dmg檔案後,便會出現上列,將Arduino 圖示,拖曳到Applications(應用程式目錄),再安裝USB 序列埠驅動程式,如下,依指示安裝。
  arduino_Install_FTD_Driver
先使用USB連接線,連接Mac及2560實驗板,會出現偵測到新網路介面,按cancel 取消即可,不需進行此項設定。
IMG_1442Arduino Mega 2560 Modem in usb detected
再來到Applications 目錄中,找到並執行Arduino整合開發應用程式。
Arduino_in_Applications_dir
Arduino 整合開發環境是以Java開發而成,加上AVR gcc/g++ …的跨平台編譯器及相關設定所組成。
在Arduino設定,注意事項中,先由選單,選擇[Tools] –> [Board] –> [Arduino Mega 2560] (請依網友們的開發板型號,挑選)
arduino_select_hardware
緊接著設定USB 序列埠,先由選單,選擇[Tools] –>[Serial Port]->[/dev/tty.usbmodemfd121] (請依網友們的開發板型號,挑選)
 Arduino_select_the_serial_port
好戲上場,在Arduino中,已準備許多範例程式可供參考,選取視窗上方按鈕[Open]->[1.Basics]->[Blink],
 Arduino_selected_1.Basics_Blink.sample
即出現下方畫面,中央為範例程式碼。最後執行[Upload]鈕(右方數來第二按鈕),立刻編譯並上傳到開發板。(在傳送過程式中,TX燈會閃爍,完成後,即啟動閃爍程式,令13腳位LED每隔一秒閃爍一次。
arduino_Blink_LED_Uploading
若無其他3.3V LED可連13及GND腳位時,可參考下圖,USB Port右方,紅色燈號亦作用與在13pin插LED相同。
 IMG_1445 IMG_1448
結論
Arduino設計非常易於使用,並且有相當多的相容擴充元件可供使用,很適合不太熟悉程式設計及硬體的人來使用。

2011年8月23日 星期二

在Mac OS X上編繹BenOS並使用Qemu執行

bos_run_at_osx

續上篇自製開發BenOS支援Windows+Cygwin後,發現Mac上的使用者(當然筆者也是其中之一,不才也是半個蘋果迷)也想能直接編繹(另一個原因是,不想再開另一個Linux 虛擬機,太耗資源及電力,環保一下吧),於是乎有了這篇文章。

編繹環境設定

筆者的Mac 是Snow Leopard 10.6.8

1. 安裝Xcode

到http://developer.apple.com/下載並安裝Xcode (筆者用的是4.0.2)

2. 安裝HomeBrew

請參考把常用的UNIX 環境重建到MAC OS X (1) 一文。

3. 使用brew 安裝 nasm 和qemu

sudo brew install nasm qemu git

4.安裝cross gcc

測試使用Xcode 的gcc,並發現不能做完整靜態連結。也不能輸出ELF檔案。

正想把最後殺手鐧拿來,自己編繹gcc時,心血來潮google 一下,

發現下列的站台,有專門編繹給Mac OS X,二話不說,馬上拿來用,節省不少時間。

可從此處下載http://crossgcc.rts-software.org/doku.php

dmg 安裝至目錄

gcc-4.5.2-for-linux32.dmg (65.2 MB)

/usr/local/gcc-4.5.2-for-linux32/
gcc-4.5.2-for-linux64.dmg (71.7 MB) /usr/local/gcc-4.5.2-for-linux64/

筆者安裝是64位元版,但在編繹時需要加上-m32, 因為目前bos 尚未相容64位元模式。

5. 安裝mtools

在編繹過程,只有一個小問題,便是找不到iconv,極可能是script 的bug,加上-liconv,即可通過編繹。

另外為求保險,去除不必要的變數,故加上-arch i386,產生mtools i386 版。

env CFLAGS="-arch i386" LDFLAGS="-arch i386 -liconv" ./configure
make
sudo make install

結語

如此一來,便可在OSX上編繹及執行,可參考開頭畫面。

再則,感謝google 大神,讓我能省去編繹 toolchain時間。相對windows 來說,Mac OS X 對Unix-like開發者,較為友善。

然後,到本文筆者便寫完三個主要平台的OS開發環境Linux、Windows、OSX上設定。

希望對大家有所幫助,少走一彎路。

最後,筆者因為以前工作屬工友級,所以需要什麼,就學什麼。

想請問大家最常使用什麼平台和工具來進行程式開發呢?

說不定有更好的組合提高您的生產力;一人技窮,二人技長;快提出來大家討論,集思廣益吧。

註一:下次的大聚會9/6,有重量級的OS長老駕到,可來吸收一甲子功力,請大家踴躍參加。

註二:此次9/6活動已加入TOSSUG行程(請參閱http://www.tossug.org/2011)

2011年5月20日 星期五

Facebook iOS SDK 學習筆記及其範例簡介

參考Facebook mobile官方網址,將iOS相關部分翻譯成中文, 並加入相關心得。
在開始開發Facebook iOS程式之前,你需要先安裝iOS開發工具、原始碼版本控制工具Git 以及從GitHub上抓下最新版本函式庫:
   git clone git://github.com/facebook/facebook-ios-sdk.git


fackbook-ios-sdk 檔案結構如下:


README.mdown: 英文說明檔
sample/DemoApp/DemoApp.xcodeproj: (請使用Xcode 3.2來執行並編譯)
src/facebook-ios-sdk.xcodeproj: (SDK用來聯結到你的應用程式專案中)
src/JSON/:一個輕量Objective-C版的JSON(JavaScript Object Notation)的語法分析器及產生器
test/UnitTest: 單元測試



DemoApp:範例程式
前置作業、編譯及執行順序
  • 建立Facebook App ID: (請參考 http://www.facebook.com/developers/createapp.php)
  • 修改 DemoAppViewController.m 和 DemoApp-Info.plist (under URL types > Item 0 > URL Schemes > Item 0)內[app_id] 置換你的Facebook AppId。
  • 最後編譯及執行


此範例提供下列功能:
-(IBAction)fbButtonClick:(id)sender; // 登入/登出按鈕事件
-(IBAction)getUserInfo:(id)sender; // 使用GraphAPI來取得目前登入使用者資訊
-(IBAction)getPublicInfo:(id)sender; // 取得使用者公開資訊:例如使用者名稱
-(IBAction)publishStream:(id)sender; // 開啟一個談話視窗來讓使用者可把訊息貼到塗鴉牆
-(IBAction)uploadPhoto:(id)sender; // 上傳圖片


2011年5月14日 星期六

解決Python 跨平台相容性問題 (Mac OS X)

最近因工作需要使用Python來寫技術支援的程式,且其能在Tiger(10.4+), Leopard(10.5.5+), Snowlepoard (10.6.2+)正確執行。


測試開發用環境
Snowleopard 10.6.7 內建  python 2.6.1,
Leopard 10.5.8 內建 python 2.5.1
Tiger 10.4.8 內建 python 2.3.5

開發過程中,遇到下列問題:
Exception處理
try:

    open("/var/log/testexcept.log", w)
except IOError as (errno, strerror):
    print "Error %d: %s" % (errno, strerror)

上列程式,在Leopard 發生Exception錯誤。
$ python except_invalid.py
except_invalid.py:4: Warning: 'as' will become a reserved keyword in Python 2.6
  File "except_invalid.py", line 4
    except IOError as (errno, strerror):
                    ^
SyntaxError: invalid syntax
就Mac OS X 平台來說,"as" 是Python 2.6的保留字

解決方案:
try:
    open("/var/log/test.log", 'w')
except IOError, v:
    try:
       (code, msg) = v
    except:
       code = 0
       msg
    print "I/O Error:%d %s" % (code , msg)

執行結果:
$ python except_ok.py
I/O Error:13 Permission denied

readPlist/writePlist 不支援10.4


查了一下python plistlib 函式 python 2.5.1 and 2.6.1 都有相關函式
Python 2.5.1 (r251:54863, Jun 17 2009, 20:37:34)     ==>
[GCC 4.0.1 (Apple Inc. build 5465)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import plistlib
>>> dir(plistlib)
['Data', 'Dict', 'DumbXMLWriter', 'PLISTHEADER', 'Plist', 'PlistParser', 'PlistWriter', 'StringIO', '_InternalDict', '__all__', '__builtins__', '__doc__', '__file__', '__name__', '_controlCharPat', '_dateFromString', '_dateParser', '_dateToString', '_encodeBase64', '_escapeAndEncode', 'binascii', 'datetime', 're', 'readPlist', 'readPlistFromResource', 'readPlistFromString', 'writePlist', 'writePlistToResource', 'writePlistToString']

python 2.3.5 沒有所需函式
Python 2.3.5 (#1, Jul 25 2006, 00:38:48)
[GCC 4.0.1 (Apple Computer, Inc. build 5363)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import plistlib
>>> dir(plistlib)
['Data', 'Date', 'Dict', 'DumbXMLWriter', 'False', 'INDENT', 'PLISTHEADER', 'Plist', 'PlistParser', 'PlistWriter', 'True', '__all__', '__builtins__', '__doc__', '__file__', '__name__', '_encode', 'bool', 'sys']

解決方案:

使用Plist()的函式 fromFile(file) and write(file)
import plistlib
pl = plistlib.Plist()
file="/Applications/iTunes.app/Contents/version.plist"
dict = pl.fromFile(file)
print dict['CFBundleShortVersionString']
dict['CFBundleShortVersionString'] = "10.1"
dict.write("my.plist")

2011年5月10日 星期二

學習iPhone/iPad 程式設計的參考資料清單(2)

續上次書目,如英文書讀起比較吃力的話,可以考慮下列我朋友所讀的中文譯書。

精通Objective-C 2.0程式設計2/e(平裝)
本譯書是由蔡明志所翻譯,譯者在C++領域有很深的造詣,曾譯過Ivor Horton's C++ 教學範本(Beginning the complete language)等書。值得列參考書看看。

探索iPhone程式開發實戰
這本書是從英文版翻譯:英文書(4th printing edition)出版日期為(2008年11月)與這本中文書(2010年10月)相差了兩年,遠遠追不上Apple iOS 更新的速度。
而這本書的第二版加入的iphone4 新的技術,在2011年1月出版Beginning iPhone 4 Development: Exploring the iOS SDK如果已有基礎,要看看iPhone 4 技術,可考慮新書。

2011年4月18日 星期一

把常用的UNIX 環境重建到MAC OS X (1)

把常用的UNIX 環境重建到MAC OS X

最近舊的Mac壞了,
換了新的Macbook pro,環境要重灌真是一件煩人事。
之前都是用Macports, 這次想試試Homebrew 與最近的MACOSX 及Xcode 會不會簡單些?

實驗環境:
硬體:2.3 GHz Intel i5, 4GB DDR3
軟體:Mac OS X 10.6.7,  Xcode 4.01 and iOS SDK 4.3

參考官方安裝說明(https://github.com/mxcl/homebrew/wiki/installation),以我所使用的環境為例,在安裝前請注意下列事項:
* Mac 必須為Intel CPU 
* Mac OS X 必須10.5 (Leopard) 以上 (目前在10.6 上使用也OK)
*建議移除 /usr/local/include 和 /usr/local/lib 以避免一些相容的問題。
*安裝目錄:
 ﹣ 免避包含空白的目錄
 ﹣ 免避使用Macports 所用目錄(/opt/local 和 /sw)
 ﹣ 建議使用/usr/local, 因為簡單、安全,因預設路徑已包含、Apple 保留這個目錄給大家使用。

安裝Homebrew,執行如下:

$ ruby -e "$(curl -fsSLk https://gist.github.com/raw/323731/install_homebrew.rb)"
==> This script will install:
/usr/local/bin/brew
/usr/local/Library/Formula/...
/usr/local/Library/Homebrew/...

Press enter to continue
==> /usr/bin/sudo /bin/mkdir /usr/local

WARNING: Improper use of the sudo command could lead to data loss
or the deletion of important system files. Please double-check your
typing when using sudo. Type "man sudo" for more information.

To proceed, enter your password, or type Ctrl-C to abort.

Password:
==> /usr/bin/sudo /bin/chmod g+w /usr/local
==> /usr/bin/sudo /usr/bin/chgrp staff /usr/local
==> Downloading and Installing Homebrew...
==> Installation successful!

安裝成功!!

接下來,先試安裝一下原始碼管理工具 git 吧!!

$ brew install git
==> Downloading http://kernel.org/pub/software/scm/git/git-1.7.4.4.tar.bz2
######################################################################## 100.0%
==> make prefix=/usr/local/Cellar/git/1.7.4.4 install
==> Downloading http://kernel.org/pub/software/scm/git/git-manpages-1.7.4.4.tar.
######################################################################## 100.0%
==> Downloading http://kernel.org/pub/software/scm/git/git-htmldocs-1.7.4.4.tar.
######################################################################## 100.0%
==> Caveats
Bash completion and emacs support have been installed.

The rest of the "contrib" folder has been copied to:
  /usr/local/Cellar/git/1.7.4.4/share/contrib
==> Summary
/usr/local/Cellar/git/1.7.4.4: 1054 files, 19M, built in 49 seconds

馬上可供使用,滿方便。

結論

使用無障礙,很簡單清爽的介面,提供剛好資訊給使用者。
就個人而言,偏好(Information Just fit)工具,所以推廌給大家使用。

更新10-01: 使用下列命令可下載或更新並安裝,最新版的Qemu
  brew install qemu

2010年1月29日 星期五

How to connect VPN by Juniper Network Connect 6.0.0 on Snow Leopard 10.6.2?

Originally, I cannot connect VPN with Network 6.0.0 on Snow Leopard.

I’m working fine now on My Snow Leopard after following steps. (^.^)

1. remove the proxy settting
2. after I commanded the followings
sudo chmod 755 /usr/local/juniper/nc/6.0.0/
sudo mkdir '/Applications/Network Connect.app/Contents/Frameworks'
3. if you use the Network Connect 6.3.0, please remember to run following command
sudo chmod 4711 /usr/local/juniper/nc/6.0.0/ncproxyd

Issue for PAC

"Network Connect" is not supported the proxy configuration (Proxy Auto Config)
I found the root cause after I dug the logs of “Network Connect”.
reason = "Conversion to encoding 30 failed for string \"function FindProxyFo...\"";
“function FindProxyForURL(url, host)” is the function name in my PROXY.pac.

The ncproxyd seems to be not supported proxy configuration well.
I tried it without proxy setting via ADSL line. It worked well.

2010年1月28日 星期四

蘋果電腦硬體相關問題(1)使用nvram後,無法開機成功

有一次,曾遇到使用nvram 指令更改起動變數後,Leopard 10.5.8 無法正常開機。
只能使用[Command + Shift)進入保護模式。
開機使用偵錯模式,發現Mac 的驅動程式發生載入錯誤。

後來,聯絡Apple computer 的技術支援,回覆是先試用下列說明
 
重設Mac's PRAM and NVRAM
http://support.apple.com/kb/HT1379


(PS: 更換了Mac 的硬體後,也有可能發生。不妨試試這個方法。)

2010年1月25日 星期一

在蘋果電腦上執行 qemu (MAC OS X)

QEMU 為一開放源始碼的虛擬機器模擬器。

若是使用Snow leopard(MAC OS X 1.0) 以上的網友可考慮使用, homebrew.
   ==>請參考 把常用的UNIX 環境重建到MAC OS X 一文

如尚未安裝Darwin Ports, 請至  http://www.macports.org/  下載符合系統的版本進行安裝。


接著你可執行port 安裝qemu,過程如下述:
$ sudo port install qemu

Password:

You will then be prompted for your root password, which you should enter. You may have to wait for a few minutes while the software is retrieved from the network and installed for you. Y ou should see something that looks similar to:

---> Fetching qemu
---> Verifying checksum for qemu
---> Extracting qemu
---> Configuring qemu
---> Building qemu with target all
---> Staging qemu into destroot
---> Installing qemu

(註:當上述指令執行中,請勿關閉終端機(Terminal)。)
安裝完成後,你可用下述指令得到qemu 更詳細的資訊
$ man qemu
$ apropos qemu
$ which qemu
$ locate qemu

預設安裝好qemu, 並不包含 arm 的執行檔
若需要其他的處理器(processors)的支援可用下述指令進行安裝:

$ sudo port install +target_arm qemu

你可用 sudo port variants qemu 查詢可能目標處理器支援。
範例如下:
VMLeopard:~ ben$ port variants qemu

qemu has the variants:
target_arm: add arm target support
target_cris: add cris target support
target_m68k: add m68k target support
target_mips: add mips target support
target_mips64: add mips64 target support
target_mips64el: add mips64el target support
target_mipsel: add mipsel target support
target_ppcemb: add ppcemb target support
target_sh4: add sh4 target support
target_sh4eb: add sh4eb target support
target_sparc: add sparc target support
universal: Build for multiple architectures

參考資訊