I have try everything to create a command to control de volume only of spotify.
Yes it is true that i’m not a programer but … I can manage simple thing.
I copy this code that i have found :
tell application "System Events"
set MyList to (name of every process)
end tell
if (MyList contains "Spotify") is true then
tell application "Spotify"
set volcheck to get sound volume
set volcheck to volcheck + 10
set sound volume to volcheck
end tell
end if
And i have try many other combination, look the web, command definition, etc …
To debug I found that i can use “SAY” so i add every where “say volcheck”
And i discover that volcheck is stuck with the same value. The only way to change it, is to pause and restart spotify. Now he get the new value. Others wise he get stuck with the first he had.
I get the same problem when the commande was very simple :
set sound volume to sound volume + 10
It move once and stuck there. but if i press pause/play it work a second time and stuck again.
Here the information for spotify specific classes :
application n [see also Standard Suite] : The Spotify application.
properties
current track (track, r/o) : The current playing track.
sound volume (integer) : The sound output volume (0 = minimum, 100 = maximum)
player state (stopped/playing/paused, r/o) : Is Spotify stopped, paused, or playing?
player position (real) : The player’s position within the currently playing track in seconds.
repeating enabled (boolean, r/o) : Is repeating enabled in the current playback context?
repeating (boolean) : Is repeating on or off?
shuffling enabled (boolean, r/o) : Is shuffling enabled in the current playback context?
shuffling (boolean) : Is shuffling on or off?
Fortunately I had an old version I tested with first. Script 1 below worked.
I then updated to the most recent version of Spotify, and the 1st script broke.
tell application "Spotify"
if it is running then
set aSound to sound volume
set sound volume to ((get sound volume) + 10)
set sound volume to ((get sound volume) - 10)
set bSound to sound volume
end if
end tell
With the new version get sound volume fails.
You can still set an absolute sound value, but if you run script below you’ll see aSound and bSound are not correct even though the volume IS set.
tell application "Spotify"
if it is running then
set aSound to sound volume
set sound volume to 70
set bSound to sound volume
end if
end tell
As @ComplexPoint says you should report this as a bug.
I didn’t find a special place to report this and when i read on spotify it was saying to go on stack for non programer. I poste it here : http://stackoverflow.com/q/32274009/5276999
This Applescript works like a charm with the current Spotify version (2022)
Volume up:
tell application "Spotify"
if the sound volume is not greater than 90 then
set sound volume to ((sound volume) + 10)
else
set sound volume to 100
end if
end tell
Volume down:
tell application "Spotify"
if the sound volume is greater than 9 then
set sound volume to ((sound volume) - 10)
else
set sound volume to 0
end if
end tell
FWIW a variant allowing for a custom set of volume-level notches, e.g.
finer grained around your typical listening level
coarser grained at the extremes
A single function to cover increasing and decreasing volume (first argument true or false).
Second argument should be a list of integer volume levels. (in the sample below it's just a continuous list, at intervals of 5, between 0 and 100 – enumFromThenTo(0)(5)(1000) – but you could use any list that suits you better – the intervals can be varied.
To test in Script Editor, set the language selector at top left to JavaScript.
To assign to triggers in Keyboard Maestro, use Execute JavaScript for Automation actions.
Expand disclosure triangle to view JS source
(() => {
"use strict";
// ---- SPOTIFY VOLUME CHANGE IN GIVEN INCREMENTS ----
// RobTrew @2022
// Ver 0.2
const granularity = 5;
const main = () =>
spotifyVolumeChanged(true)(
enumFromThenTo(0)(granularity)(100)
);
// spotifyVolumeChanged :: Bool -> [Int] -> IO Int
const spotifyVolumeChanged = increasing =>
volumes => {
const
spotify = Application("Spotify"),
soundVolume = spotify.soundVolume(),
nextPosition = volumes.findIndex(
x => soundVolume <= x
) + (increasing ? 1 : -1);
return (
nextVolume => (
spotify.soundVolume = nextVolume,
nextVolume
)
)(
nextPosition < 0
? 0
: nextPosition >= volumes.length
? 100
: volumes[nextPosition]
);
};
// --------------------- GENERIC ---------------------
// enumFromThenTo :: Int -> Int -> Int -> [Int]
const enumFromThenTo = m =>
// Integer values enumerated from m to n
// with a step defined by (nxt - m).
nxt => n => {
const d = nxt - m;
return Array.from({
length: (Math.floor(n - nxt) / d) + 2
}, (_, i) => m + (d * i));
};
return main();
})();