Music.app: Launch command blocks the quit command for 1-3 seconds?

With delay smaller than 4 seconds, following script blocks Music.app quitting on my Catalina. It is very strange behaviour, I can’t understand how this happens - I can’t even automate the delay with checking running property.

Any working solution to automate the delay?


tell application "Music"
	launch -- or, activate
	delay 1 -- little delay blocks quitting 
	quit
end tell
-- NOTE: doesn't quit after this script execution even manual way)

I tried following, but it doesn’t solve the problem:


tell application "Music"
	launch -- or, activate
	repeat until (get its running) is true
		delay 0.2
	end repeat
	quit
end tell

Following doesn’t solve the problem, as well:


tell application "Music"
	launch -- or, activate
	get properties
	quit
end tell

It is working with Big Sur.
I can’t test it with Catalina, sorry.

KniazidisR. FWIW, all three of your scripts without modification work fine on my computer with Catalina.

Thanks for testing, @peavine.

I will try to restart my computer. Haven’t turned it off for a long time, so there may be some kind of failure.

UPDATE: I restarted my Mac. The problem remain.

With 4 seconds delay (or bigger) the script works stable. But I can’t understand why so big delay is required on my machine. Maybe, I have some iTunes leftovers, I will check:


tell application "Music"
	launch -- or, activate
	delay 4
	quit
end tell

KniazidisR. One thing I didn’t mention but should have is that I do not use the Music app to store or play songs. The reason I mention this is the thought that reading or other activities relating to a large song catalog might make a difference.

Is there a command other than ‘quit’ that can be tested similarly?

I have not seen such behavior with other commands yet. Fortunately.

Basically, the problem with quit is small. If there are other commands between the launch/activate command and the quit command, everything works fine. I think because they return a result as opposed to activation. I just wanted to quickly get all the properties of Music.app and quit it.

I’m a user of Mojave so I couldn’t test Music.app

You could try this with Scripting Bridge framework

use framework "ScriptingBridge"

set iTunesProperties to current application's SBApplication's applicationWithBundleIdentifier:"com.apple.iTunes"
iTunesProperties's |properties|() as record

Hi, @Fredrik71.

Thanks for your post. I tried it - the properties are returned quicker, but 4 seconds problem with Music.app quitting remain. I tested this:


use framework "ScriptingBridge"

set iTunesApp to current application's SBApplication's applicationWithBundleIdentifier:"com.apple.Music"
set iTunesProperties to iTunesApp's |properties|() as record -- 1.52 seconds so far
-- delay 2.5 -- without this quitting fails (1.52 + 2.5) = > 4 seconds
tell application id "com.apple.Music" to quit

return iTunesProperties

From other perspective… iTunes.app and I guess it also apply to Music.app
They are also web browsers that return contents from web…
On my machine in Script Geek it takes 2 second to return the properties.

That include: open application and display the contents of store

When the Application is open its takes 0.06 seconds, 10.14.6 Mojave

Try this one…

use framework "Foundation"
use framework "ScriptingBridge"
use scripting additions

set iTunes to current application's SBApplication's applicationWithBundleIdentifier:"com.apple.iTunes"
set theProperties to iTunes's |properties|() as record
iTunes's |quit|()
return theProperties

This time I got little more 1 second…

It worked some attempts, now it fails again. The problem is - it isn’t stable.