tell application "iTunes"
set loved of current track to not loved of current track
end tell
script so that I can love tracks with a shortcut. Unfortunately, I don’t really know script. Is it possible to make the script such that it will only do this for tracks that are not already loved? Really this script seems to toggle loved/unloved, and so it goes both ways. I’d like it to not go both ways in case I love a song that I had previously loved but forgot…
I notice that current track chokes if nothing is playing.
error "Can’t make «class pLov» of «class pTrk» of application \"iTunes\"
into type boolean."
number -1700 from «class pLov» of «class pTrk» to boolean
In JS for Automation you might handle that with something like:
(function () {
'use strict';
var it = Application('iTunes'),
// track is only defined if something is playing
track = it.playerState() !== "stopped" ? (
it.currentTrack()
) : undefined;
// Either there is no track, or there is and we ensure that its loved.
return !track || (track.loved = true);
})();
I’m back to Apple Music (had a free Spotify Premium subscription).
This works really well. I also adapted it to dislike songs when needed, it also skips to next song. Thanks!
tell application "iTunes"
if player state ≠ stopped and not loved of current track then
set disliked of current track to true
next track
end if
end tell
Just figured I'd chime in here with a version I created for the (new iTunes) Music app:
tell application "Music"
if player state ≠ stopped then
if (not loved of current track and not disliked of current track) then
set loved of current track to true
return "Loved"
else if loved of current track then
set disliked of current track to true
return "Disliked"
else
set disliked of current track to false
set loved of current track to false
return "Cleared"
end if
end if
end tell
In KM I just have this on a single hot key to loop through the different settings, and it shows the status via a notification (display results briefly).
tell application "Music"
if player state ≠ stopped then
set currenttrackname to name of current track
if (not loved of current track and not disliked of current track) then
set loved of current track to true
display notification currenttrackname & " Loved" with title "Apple Music"
else if loved of current track then
set disliked of current track to true
display notification currenttrackname & " Disliked" with title "Apple Music"
else
set disliked of current track to false
set loved of current track to false
display notification currenttrackname & " Cleared" with title "Apple Music"
end if
end if
end tell