script no longer works - blasts sound volume - please help

I wrote a simple script to remember the current sound volume, then raise the volume to a certain level to announce an email message, then return the system to the saved sound volume.
It recently stopped working for some reason, and I’d like some help figuring out what went wrong and how to fix it.
Now, the volume is set to the highest possible sound volume at the end of the script. When I use “get sound volume” it returnd a value of 256!

This is my script. I have Jon’s Commands installed.

set oldVol to sound volume
set sound volume to 5
say “You have new email”
set sound volume to oldVol

It speaks the text at the correct volume, but then it blasts at 100percent sound volume, even though it was not there before.

Even if I do this as a test:

set sound volume to 5
get sound volume

it returns a value of 256. Well beyond the range of possible volume.

Does anyone maybe know what’s going on, or how I can fix this?
Much appreciate any help.

weskos

Model: OS 10.4.8 Dual 2GHz G5
AppleScript: 1.10.7 version 2.1.1(81)
Browser: Safari 419.3
Operating System: Mac OS X (10.4)

tell application "System Events"
	set getSound to (get volume settings) as list
	
	set Theoutput to item 1 of getSound
	if Theoutput > 15 then
		
		set volume output volume 15
	end if
	say "You have new email"
	set volume output volume Theoutput
	say "testing 1, 2 ,3"
end tell

what do you get if you play this

First, the system speaks the designated phrase “You have new email” at whatever sound volume the system happens to be set at at the time. Then it displays this error message.

“System Events got an error: Can’t make missing value into type small real.”:[OK]

and it highlights the line of the script:

“set volume output volume Theoutput”

The line, “Testing 1,2,3” remains unspoken, the data for the sound volume value remains unreturned, and the sound volume itself remains physically unchanged from whatever it started out as.

Hope that helps diagnose. Thanks for your efforts.

weskos

While that script does work for me, there is no need to involve System Events. (Also, get volume settings returns a record.)

set {output volume:originalOutput, output muted:originalMuted} to (get volume settings)

set volume without output muted
if originalOutput > 20 then set volume output volume 20

say "You have new email"

set volume output volume originalOutput output muted originalMuted
say "1, 2"

.

-- This is depreciated syntax for the Standard Additions command
set volume to 5

-- This is the new syntax for the Standard Additions command
set volume output volume someNumber -- 0 thru 100

This syntax is depreciated as of OS X v10.3.5 (AppleScript v1.9.4). The volume commands are in the Standard Additions dictionary.

Edit: Didn’t see the part about Jon’s Commands; Unless there’s a specific reason (older machines?) for doing so, I would stop using those particular commands and try using the standard commands instead.

Edit:

Maybe that scripting addition isn’t working properly.

This second script(2) does the same thing as the first suggested script, and gives me the same error message, “Can’t make missing value into type small real.”
This time the line, “set volume output volume originalOutput output muted originalMuted” is highlighted, and the phrase, “1,2” remains unspoken.
sound volume remains unchanged from whatever it happens to be at the time.

(2)
set {output volume:originalOutput, output muted:originalMuted} to (get volume settings)

set volume without output muted
if originalOutput > 20 then set volume output volume 20

say “You have new email”

set volume output volume originalOutput output muted originalMuted
say “1, 2”

The script -

set volume to 5

  • does not compile

However, the script -

set sound volume to 5

  • does compile, run, and sets the sound volume to below an audible range.

This script -

set volume output volume 5
get volume settings

sets the volume to 1 graphic tick mark when using the volume keys on my keyboard, and
returns this data result -

{output volume:missing value, input volume:0, alert volume:100, output muted:false}

Any more suggestions? I am still at a loss.
Can someone perhaps explain to me ‘why’ the script is setting my sound volume to so high when it recalls the variable in my original script? Where is it getting that 256, even though I’ve supposedly set the sound volume to the variable, which should be the volume it was at before? And why is the volume, all of a sudden, refusing to change from that value (according to data results), even though my funcitonal sound volume seems correct?

weskos