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.

toggle Music form options in applescript

I just migrated to Monterey from 10.14 and the migration destroyed all the display settings in my playlists. I have over 200 playlists, so I'm trying to write a script that will set them all to MY default setting, not Apple's default. I've got part of it working but I need help with the last bit.


so far I've done two things:


1) created a keyboard shortcut to set the playlist view as Songs. The shortcut "command-shift-s" will now set the current playlist view as Songs. this works. (thanks to a helpful webpage).


2) I've got a script which will iterate thru all my playlists and set them to view as Songs. (again thanks to the helpful webpage).


I need to include something in the script that will toggle the view options to what I want them to be. Toggling will work because every time I set a playlist to view as Songs the same options are selected so I know what needs to be toggled. The form with options looks like this:


I want to toggle Album, Love, Rating and iCloud Download.


Trouble is, while I can get my applescript to open the form, I don't know how to toggle an item in the form, nor can I find the documentation on how to do it. I've tried recording mouse clicks using automator, but that went nowhere. Hopefully there is some simple syntax to toggle the items.


Here's what I have so far for my script. The script does only one playlist because I am testing it before trying it on my entire library. Iterating thru the playlists is something I can do without problem, I just need help with the form options. The delays are there so I can see what is happening step by step while testing.

tell application "Music"

activate

set theplaylist to playlist "test1"

delay 1

reveal theplaylist

try

-- use the keyboard shortcut to change the view to Songs, this works.

tell application "System Events" to keystroke "s" using {command down, shift down}

delay 1

-- open the view options form, this works.

tell application "System Events" to keystroke "j" using {command down}

-- What do I put here to toggle the checkmark for Album, Love, etc.?????

delay 1

-- this next command closes the view options form. not sure I will need this when I am going thru the

-- entire set of playlists. It may be enough to just reveal the next playlist.

tell application "System Events" to keystroke "w" using {command

end try

end tell



Any help would be appreciated. thanks to all.


Mac mini, macOS 12.4

Posted on Jun 3, 2022 6:00 PM

Reply
Question marked as Top-ranking reply

Posted on Jun 6, 2022 9:30 AM

With some help from stack overflow this got solved. Here is a complete apple script that will

1) set all user playlists to "Song"

2) delete the view options you don't want

3) add the view options you do want


you could also modify this script to delete all options and add options back in the order you want them displayed (first added will be in the left most column, etc.)


This is not a perfect solution to the failure of apple to preserve playlist view settings, but at least all your playlists will have YOUR default settings instead of Apple's.


tell application "Music"

activate

-- first user playlist is the music library so skip it

repeat with i from 2 to (count of every user playlist)

reveal user playlist i

delay 0.1

tell application "System Events"

tell process "Music"

tell application "System Events" to keystroke "s" using {command down, shift down}

delay 0.1

tell application "System Events" to keystroke "j" using {command down}

delay 0.1

get checkbox "Album" of scroll area 1 of window 1

if value of result = 1 then

click result

end if

delay 0.1

get checkbox "Love" of scroll area 1 of window 1

if value of result = 1 then

click result

end if

delay 0.1

get checkbox "Genre" of scroll area 1 of window 1

if value of result = 1 then

click result

end if

delay 0.1

get checkbox "Track Number" of scroll area 1 of window 1

if value of result = 0 then

click result

end if

delay 0.1

--- add as many form items as you like.

tell application "System Events" to keystroke "w" using {command down}

end tell

end tell

end repeat

end tell


Similar questions

1 reply
Question marked as Top-ranking reply

Jun 6, 2022 9:30 AM in response to dotore

With some help from stack overflow this got solved. Here is a complete apple script that will

1) set all user playlists to "Song"

2) delete the view options you don't want

3) add the view options you do want


you could also modify this script to delete all options and add options back in the order you want them displayed (first added will be in the left most column, etc.)


This is not a perfect solution to the failure of apple to preserve playlist view settings, but at least all your playlists will have YOUR default settings instead of Apple's.


tell application "Music"

activate

-- first user playlist is the music library so skip it

repeat with i from 2 to (count of every user playlist)

reveal user playlist i

delay 0.1

tell application "System Events"

tell process "Music"

tell application "System Events" to keystroke "s" using {command down, shift down}

delay 0.1

tell application "System Events" to keystroke "j" using {command down}

delay 0.1

get checkbox "Album" of scroll area 1 of window 1

if value of result = 1 then

click result

end if

delay 0.1

get checkbox "Love" of scroll area 1 of window 1

if value of result = 1 then

click result

end if

delay 0.1

get checkbox "Genre" of scroll area 1 of window 1

if value of result = 1 then

click result

end if

delay 0.1

get checkbox "Track Number" of scroll area 1 of window 1

if value of result = 0 then

click result

end if

delay 0.1

--- add as many form items as you like.

tell application "System Events" to keystroke "w" using {command down}

end tell

end tell

end repeat

end tell


toggle Music form options in applescript

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