1

I need to turn up system volume temporarily and then set it back to the value it was before. I'm getting an error:

error "Can’t make {output volume:29, input volume:58, alert volume:46, output muted:false} into type real." number -1700 from {output volume:29, input volume:58, alert volume:46, output muted:false} to real

Does anyone know the correct way to do this? Here is my code.

tell application "Finder"
    set myVolume to get volume settings
    tell application "Finder" to set volume 5
    tell application "Finder" to set volume myVolume
end tell

1 Answer 1

2

The get volume settings and set volume are a part of Standard Additions in AppleScript and Finder is not needed.

The following example AppleScript code is what you want:

set myVolume to output volume of (get volume settings)
set volume output volume 5
set volume output volume myVolume

Note that you may need/want to set a short delay between the two set volume output ... lines of code.



Note: The example AppleScript code is just that and sans any included error handling does not contain any additional error handling as may be appropriate. The onus is upon the user to add any error handling as may be appropriate, needed or wanted. Have a look at the try statement and error statement in the AppleScript Language Guide. See also, Working with Errors. Additionally, the use of the delay command may be necessary between events where appropriate, e.g. delay 0.5, with the value of the delay set appropriately.

1
  • Thanks! Works just like I wanted :-) Commented Aug 17, 2021 at 14:53

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .