You can make a difference in the Apple Support Community!

When you sign up with your Apple Account, you can provide valuable feedback to other community members by upvoting helpful replies and User Tips.

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

System Events + Music + Import Playlists

Hello, I'm attempting to import playlists into Music using Applescript System Events. This is as far as I've got:


tell application "System Events"
	tell process "Music"
		set frontmost to true
		click menu item "Import Playlist…" of menu "Library" of menu item "Library" of menu "File" of menu bar item "File" of menu bar 1
	end tell
end tell


This displays the Open dialog but I can't work out how to process each of the playlists that are now displayed. I've downloaded the Accessibility Inspector and I think I might need to work with the AXGroup and Index in some sort of Repeat routine, but I can't put it together. Can I somehow go from Index 0 through to however many playlists I've got in that folder using the AXGroup list?


Thanks.



Posted on Jan 26, 2022 6:46 PM

Reply
Question marked as Top-ranking reply

Posted on Jan 27, 2022 5:04 PM

I see Doug's Scripts has a method for exporting multiple lists, but no obvious sign of one to import such a collection. It looks like you're trying to leverage the menu commands of the Music app, but it may be tricky to get that to access each file in turn. It may be easier to construct an AppleScript that iterates over the files in a selected folder. For each file, if it is an XML file, create a new playlist with the name of the playlist file, or the name stored within the XML if you can parse that, then iterate through the lines of the XML file adding tracks when you read a line that lists the location property. Loop until end of file, loop until no more files.


tt2

Similar questions

9 replies
Question marked as Top-ranking reply

Jan 27, 2022 5:04 PM in response to Peter H

I see Doug's Scripts has a method for exporting multiple lists, but no obvious sign of one to import such a collection. It looks like you're trying to leverage the menu commands of the Music app, but it may be tricky to get that to access each file in turn. It may be easier to construct an AppleScript that iterates over the files in a selected folder. For each file, if it is an XML file, create a new playlist with the name of the playlist file, or the name stored within the XML if you can parse that, then iterate through the lines of the XML file adding tracks when you read a line that lists the location property. Loop until end of file, loop until no more files.


tt2

Jan 27, 2022 7:38 PM in response to turingtest2

This works:


set theFolder to (choose folder) as string
set itemList to list folder theFolder without invisibles


repeat with i in itemList
	set theFileString to (theFolder & i) as string
	set theFileAlias to alias theFileString
	tell application "Music"
		add (theFileAlias)
	end tell
end repeat


Thanks tt2 for pointing me in the right direction.

System Events + Music + Import Playlists

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.