Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Jul 28, 2013, 03:38 AM   #1
wrignj08
macrumors newbie
 
Join Date: Jun 2009
Incremental volume adjustments with AppleScript?

Hello All

I would like an AppleScript that would increase volume as if i was hitting Shift+options+F12. Does anyone know how to do this?

Cheers
wrignj08 is offline   0 Reply With Quote
Old Jul 28, 2013, 05:22 AM   #2
HexMonkey
Administrator
 
HexMonkey's Avatar
 
Join Date: Feb 2004
Location: New Zealand
The following will approximate it (minus the visual and audio cues that it's changed):

Code:
set currentVolume to output volume of (get volume settings) -- in the range 0 to 100 (integer)
set newVolume to round (currentVolume * 64 / 100) -- convert to the range 0 to 64 (float)
if newVolume < 64 then set newVolume to newVolume + 1 -- increment the volume
set volume output volume (newVolume * 100 / 64) -- convert back to the range 0 to 100
The technical details are below, but they're not important if you're not too concerned about details.

Unfortunately it's more complicated than it should be. The actual system volume is an integer from 0 to 100, but the normal range with the up/down volume keys is 0 to 16, and when using option-shift-volume up/down the range is effectively 0 to 64 (as there are four increments for each square). As the actual volume is stored as an integer, numbers don't convert cleanly between ranges, so for example 0.25 squares is volume 1, 0.5 squares is volume 3, 0.75 squares is volume 4, etc. Apple's mapping between the two ranges doesn't seem to follow an obvious formula (a quarter of a square increase can correspond to an actual volume increase of 1, 2, or 3), so the above won't match it perfectly, but will be fairly close.
HexMonkey is offline   0 Reply With Quote
Old Jul 28, 2013, 05:27 AM   #3
wrignj08
Thread Starter
macrumors newbie
 
Join Date: Jun 2009
Thanks for that nice script and explanation, however I was hoping to get the graphical and audial feedback. I know you can do keystrokes with AppleScript however I'm unable to tell applescript to combine Shift+options+F12 successfully. Any help with that?
wrignj08 is offline   0 Reply With Quote
Old Jul 28, 2013, 06:30 AM   #4
HexMonkey
Administrator
 
HexMonkey's Avatar
 
Join Date: Feb 2004
Location: New Zealand
Sorry, I misunderstood!

You can literally get Applescript to type shift-option-F12 like this:

Code:
tell application "System Events" to key code 111 using {option down, shift down}
Unfortunately, this won't do what you want; 111 corresponds to F12, but the media keys (volume up, volume down, etc) are treated as different keys. In theory there's a separate key code for the "volume up" key (72), but it doesn't work either. I can't seem to find any workaround, sorry.
HexMonkey is offline   0 Reply With Quote
Old Jul 28, 2013, 06:32 AM   #5
wrignj08
Thread Starter
macrumors newbie
 
Join Date: Jun 2009
Thanks Mate, that is were I was also stuck, I was thinking if I could tell it to also hold down the function key but i could not find the command for that either.
wrignj08 is offline   0 Reply With Quote
Old Jul 28, 2013, 06:41 AM   #6
HexMonkey
Administrator
 
HexMonkey's Avatar
 
Join Date: Feb 2004
Location: New Zealand
Yeah, I had a look at that - unfortunately the key down command doesn't have any support for the function key, that I can see.
HexMonkey is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Tags
applescript, incremental volume

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
Volume adjustments "sluggish" 10.8.5 sine-nomine OS X 10.8 Mountain Lion 0 Oct 6, 2013 11:59 PM
Issues Lowering Volume of Spotify with AppleScript macman7002 Mac Programming 0 Mar 18, 2013 09:07 PM
Mount ssh volume with Applescript MacPC Windows, Linux & Others on the Mac 2 Feb 18, 2013 06:36 AM
AppleScript to zip sub folders on a volume kevinless Mac Basics and Help 2 Nov 11, 2012 06:37 PM
Applescript to unmount/mount drive on identifier other than volume name? mixvio OS X 10.8 Mountain Lion 0 Sep 6, 2012 05:20 AM

Forum Jump

All times are GMT -5. The time now is 08:03 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC