Sunday, August 3, 2008

set volume in max os x terminal

Costing my much time to search, It seems no command for setting volume in Leopard. When I used AppleScript to do this, I didn't know why the executable file cause some problem in screen. But Ruby's applescript gem do this good. I saved below content as /usr/bin/volume, and then I could use $ volume [1-7 as volume] to set Leopard's Volume from remote.

01 #!/usr/bin/env ruby
03 require 'rubygems'
04 require 'applescript'
06 AppleScript.execute("set volume #{ARGV[0]}")

update 2008/8/3

the way using applescript interpreter is $ osascript -e "set volume [1-7]"
or call in script by shebang.

01 #!/usr/bin/osascript
03 set volume [1-7]


No comments: