delimiters problem

Hi,

the UI scripting snippet below truncates a string using Applescript’s text item delimiters and works just fine for me, but apparently not for others. I get an even number result, while others get a value with decimals. I can’t understand why this very simple piece of code would behave differently on other machines running the same OS? Any suggestions?

set AppleScript’s text item delimiters to “,”
tell application “System Events” to tell process “VLC” to set the_volume to (first text item of ((value of slider 1 of window “VLC - Controller”) * 3.125 as string))
if the_volume is not “0” then
return the_volume
else
return false
end if

this script was automatically tagged for
color coded syntax by Script to Markup Code
written by Jonathan Nathan

Hi, snarb.

  1. By “even number”, do you mean “integer”?
  2. Is the comma the decimal point symbol on your system? If so, the script won’t work on systems configured with “.” as the decimal point.
  3. If the script does what I think it does, you probably don’t need to use text at all.
tell application "System Events" to tell process "VLC" to set the_volume to (value of slider 1 of window "VLC - Controller") * 3.125 div 1
if the_volume is 0 then
  return false
else
  return the_volume
end if

VLC’s dictionary has…

So you could use a set repeat loop something like this…

tell application "VLC"
	repeat 16 times
		volumeDown 1
	end repeat
end tell

So if the volume was at 100%, the script would take it to 50%. You can adjust the repeat number from 1 to 32.

Also…

tell application "VLC"
	repeat 32 times
		volumeDown 1-- volume to zero%
	end repeat
	tell application "VLC"
		repeat 4 times -- volume to 12.5%
			volumeUp 1
		end repeat
	end tell
end tell

Hi Nigel,
you’re absolutely right, no need for strings. Actually I didn’t know that the decimal point depends on the system configuration, but your code does the trick nicely so the problem is solved now. Thanks a lot!

Hey Greg,
I do indeed use a repeat loop when setting the volume from within the script, but if you then change the volume manually while running the script (which is a remote controller for bluetooth devices), it messes things up. That’s why I call System Events to do the job. I should have elaborated a little on the purpose of the script, sorry about that!

Thanks both for helping out, I really appreciate it!
:smiley: