How to create a menu bar toggle in Mac OSX Lion?
How would I go about creating 开发者_StackOverflow社区a menu bar icon to toggle the microphone mute button?
Would I use AppleScript or Objective-C? What kind of project do I create in Xcode (if that's the IDE I should use). Thanks for any help or direction.
Try this...
property toggled : 0 --0 means the mic is off, 1 means the mic is on
if toggled is 0 then
set volume input volume 100
set toggled to 1
else
set volume input volume 0
set toggled to 0
end if
Save this as a regular script file in the Scripts
folder of the local Library
folder.
If you have a little icon in your menubar that looks like a scroll (formerly known as the Script Menu
), the script should appear somewhere in that menu. If you don't see the icon, run AppleScript Utility
(located at /Applications/AppleScript/AppleScript Utility
) and check the Show Script Menu in menu bar
checkbox.
Now, all you have to do to run it is open up the Script Menu, find your script, and just click on it once. Questions? Ask. :)
Here's a simple way because we can get or set the output muted property of the volume directly...
set isMuted to output muted of (get volume settings)
if isMuted then
set volume without output muted
else
set volume with output muted
end if
As far as setting a menubar toggle, do as fireshadow52 suggested. Enable the applescript menu from the preferences in AppleScript Editor then place this applescript in the ~/Library/Scripts folder (create the folder if it doesn't exist).
EDIT: Sorry, I see you want the microphone muted not the volume! My mistake.
精彩评论