Anyone know of a way to tell KM when a song is done playing in Music? (using only KM actions, no scripts)

Hello and thanks for reading.
I started building a macro and stuck at the beginning. :rofl:
I need the macro to play the song the cursor is hovering on, then it goes to the end of the song and after some seconds, when the song ends to perform a bunch of actions.
I didn't find a way (was thinking of something like "If then else" do this until the song plays or while it plays.
My problem is that as the song finishes playing, the next in queue starts right away.
I need to pause the macro as the song vanishes and see which song I want to go on ("pause until") repeating the sequence count times.
I hope I made sense (if not, I'm sure someone will let me know)... :rofl:
As I already said I want to use only KM tools since, if I use any suggested scripts I won't be able to customize/modify them after).
I am using a 2019 MBP with macOS Sonoma v. 14.4.1 and Music v. 1.4.4.48. KM v. 11.0.2
TIA.
Saul

Turns a song with 0 plays into a 1 plays Macro (v11.0.2)

Turns a song with 0 plays into a 1 plays.kmmacros (8.9 KB)

There might be a better way, but you could do something like:

  1. take a screenshot of the section showing the currently playing song
  2. pause until that image is no longer visible (since the song will have changed)
1 Like

Do you want it to play the entirety of the song you were hovering, or is it jumping to the end right after it starts playing?

-rob.

I love problems like this. (i.e., tricking an app into doing what you want.) But I still don't understand the requirement. You want to start the song (eg, one second from the end) and then immediately stop? What does that accomplish?

Apple Music is playlist oriented, from what I can see. You don't play songs, you play playlists. As you point out, Apple Music doesn't know when to stop. It wants to stream forever. But it does allow you to stop it, so we can probably make it work.

Here's a tool that might help you. Be aware that I really don't understand what you want, so this macro may not be right for you. But it might give you ideas to help.

Ultimately I don't understand what you mean by "I need to pause the macro as the song vanishes and see which song I want to go on ("pause until") repeating the sequence count times." What do you mean by "see which song I want to go on"? I'm not even sure if you are talking about viewing the Apple Music app or some other app or some KM macro.

Nevertheless this is a pretty cool macro. Just make sure that you don't start it until the song has been playing for at least one second, due to how it detects the end of a song.

Group Action (v11.0.2)

Group.kmactions (4.2 KB)

Keyboard Maestro Export

1 Like

I confess that technically solution contains "scripts." They are fairly trivial, so you might not mind them, but if you really want a solution that doesn't use "scripts," here's another one. You may want to change the trigger to a hotkey. Or you may want to put this macro into some loop. There are ways to change how it works, because I'm not sure how you want this macro to operate, but it contains the main idea of using OCR to stop the music. I absolutely love Apple OCR because it can solve so many problems.

Like my previous solution, this one uses "polling." Polling is never the best solution, but sometimes macOS does not provide the tools to detect certain things, and we have to resort to polling.

Stop at -0:01 Macro (v11.0.2)

Stop at -0-01.kmmacros (4.5 KB)

1 Like

I found that getting the duration of the song sometimes cut the song short, so I ended up going with this (loops over all songs in a playlist).

As for your requirement to use "KM Tools Only", put this in a KM action to run an applescript? I'm not sure why you would not be able to edit this since it's no different than just editing any other macro.

on run {input, parameters}
	tell application "Music"
		set allTracks to tracks of playlist "Music To Play"
		repeat with aTrack in allTracks
			set trackName to name of aTrack
			if trackName is (input as string) then
				play aTrack
			end if
		end repeat
		delay 5
		repeat while (player state is playing)
			delay 0.2
		end repeat
	end tell
end run
1 Like

First, let me thank all who answered my post. Very much appreciated!
Need to add one thing: my wife is in hospital (underwent surgery). All is good now but I will be able to go on working on the macro only in several days.
@ edjusted:
Thanks for your suggestion! I'm also always happy to try something I didn't know about it/didn't try it before!

@ griffman and also Airy:
Sorry, I guess I should have elaborated more.
First I don't stream. I use the Apple Music app in my MBP.
My goal is to "make a song vanish" from a playlist that the songs were not played. After a song is played the app "marks" the song as "1 play" and the song disappears from the playlist. I don't want to play the whole song and wait till it ends, so it's enough for me to listen to part of it, to later on put it "in the right playlist".

"...What do you mean by "see which song I want to go on"?..."
There are songs in the playlist that I know I don't want them there (by the name), but there is no better way for me to take them off. (I can, for example decide that the smart playlist will not include a certain word in any of the fields- for example "No" in the grouping/comments/etc. field- but that involves going to the info, write the word and so on)... Hope I answered clearly.
I will look into your macros, try them and get back. (And as you said, the script you used is pretty basic and I can "deal" with it)... :blush:

@ johns:
Thanks, as with Airy, I will try and get back after.

Thanks again, will be back after trying all.

Sorry to hear about your family situation, but I'm still happy to help, if I can.

Maybe others can help based on your recent description, but I would need something clearer. Are you trying to implement a macro to a process that you are already doing manually, or are you trying to invent a process without actually having yet done it manually? If you are already doing this process manually, then, for me to be able to help, please use the macOS screen recording feature (and upload the video somewhere) so I can see what you are doing. Anything you do manually, I could most likely create a process using KM to automate it.

Maybe there are other people who can help you without a video, but I don't think I can.

Playlists are not meant to have items deleted after you play them. There's another list called the Up Next list, and that one is intended for that purpose.

1 Like

Thanks Airy.

Will try to find a way to clarify what I want to achieve. (Either a video or pics/screenshots.)
Plz don't worry if it takes me several days.

If I'm understanding this right:

  1. You have a list of songs
  2. You can remove songs from the list by playing them once
  3. You know from the name you don't want the song (you don't have to listen to it to know)

So all you have to do is select a bunch of songs (you can ⌘-click songs to add them non-contiguously) then increase the "play count" of all the songs currently selected by 1 with this AppleScript:

tell application "Music"
	repeat with eachItem in (get selection)
		set played count of eachItem to ((played count of eachItem) + 1)
	end repeat
end tell

Although I'm not entirely sure I've understood what you are trying to do!

1 Like

Yes!!! That's exactly what I wanted to do!
Although I would prefer to use "pure" KM actions, this script is pretty basic and if I research a bit, I may be able to start learning Apple script (encouraged by this one). :smiley:
Thank you Nige_S!!!

@ edjusted, Airy and johns I still will try to try your suggestions and get back to you.
Thank you all!!! :smiley:
Saul
(@ Nige_S: I am not marking your reply as the solution:
a- I will still try to find a way with KM
b- I think if I do so it will close this post for additional comments.)

Nige has an outstanding ability to understand people's requests.

1 Like

Then think about it as "how would I do this manually, and how can I replicate that in KM?".

One problem you have at the moment is that when a song ends the next one starts. So instead of moving to the end of a playing song -- pause the track then move to the next!

You can do that manually by hitting the space bar and then the "fast forward" button or media key (F9 on my keyboard). And, with KM native actions, that's as simple as

1 Like

You know why I don’t like answers like yours??!!
Cause they make me hit my forehead (hard) and then ask myself “You idiot!!! How didn’t YOU think about it!!!” :rofl: :rofl: :rofl:
Thanks Nige_S, appreciate your patience!!! :pray:

1 Like

We've all been there! That's what is so great about this Forum -- there's a lot of people here with a wide range of knowledge/experience, so you can practically guarantee a face-palm moment every day :slight_smile:

2 Likes

:rofl:
We are in agreement about how great this forum is and how helpful the people are!!! (Myself "tested" it not once and not twice!)

Agreed!!!

1- I wanted to thank everyone who tried to help me.
2- Although it used Apple Script I marked Nige's answer as the solution because
a- It's close/simple enough.
b- The rest of the macros I didn't succeed to execute them.
c- I don't want to go on dragging this post anymore.
So, again, thank you guys! You are (as always) awesome!
Saul

1 Like