1

I'm trying to replicate the function of the volume keys, but in applescript. I can't get it to work though. The increase volume button puts the volume at max and the decrease volume button does the same. Anyone know what i'm doing wrong? Heres my code:

-- increase volume

on increaseVolumeHandler_(sender)
    tell application "finder"
    set theOutput to output volume of (get volume settings)
    set volume output volume (theOutput + 6.25)
    end tell
    do shell script "afplay /System/Library/Sounds/Pop.aiff"
end increaseVolumeHandler_

-- decrease volume

on decreaseVolumeHandler_(sender)
    tell application "finder"
    set theOutput to output volume of (get volume settings)
    set volume output volume (theOutput - 6.25)
    end tell
    do shell script "afplay /System/Library/Sounds/Pop.aiff"
end decreaseVolumeHandler_
4

1 回答 1

1

这些功能在 10.7.5 上对我有用,你在尝试什么 OSX 版本?

您也可以删除 sender 参数和 tell finder 块的冗余代码,例如,

on increaseVolumeHandler_()
    set theOutput to output volume of (get volume settings)
    set volume output volume (theOutput + 6.25)
    do shell script "afplay /System/Library/Sounds/Pop.aiff"
end increaseVolumeHandler_
于 2013-08-11T06:07:45.930 回答