I have the following apple script that works for setting the View Options for an Apple Music Playlist by selecting one playlist at a time and the running the script. I have been trying to get it to iterate through all of my playlists using AI via Google chrome, however it modifies it to the point where it breaks and it sets "</ repeat>" and "</tell>" rather than "end repeat" and "end tell". Can this script be modified to iterate through all of my playlists?
tell application "Music"
activate
tell application "System Events"
tell process "Music"
-- Step 1: Ensure playlist is viewed "as Songs" (Using error-resistant approach)
set menuChanged to false
try
click menu item "as Songs" of menu "View" of menu bar 1
set menuChanged to true
end try
if not menuChanged then
try
click menu item "as Songs" of menu 1 of menu item "View As" of menu "View" of menu bar 1
end try
end if
delay 0.5
-- Step 2: Open View Options (Command + J)
keystroke "j" using {command down}
delay 0.5
-- Step 3: Target the View Option Columns that should be added and removed.
if exists window "View Options" then
set viewOptionsWindow to window "View Options"
else
set viewOptionsWindow to window 1
end if
if exists scroll area 1 of viewOptionsWindow then
set allCheckboxes to checkboxes of scroll area 1 of viewOptionsWindow
set targetNames to {"Album", "Album Artist", "Artist"}
repeat with aCheckbox in allCheckboxes
try
if name of aCheckbox is in targetNames and value of aCheckbox is 0 then
click aCheckbox
end if
end try
end repeat
set UnwantedCheckboxes to {"Time", "Plays", "Genre", "Year", "Track Number"}
repeat with aCheckbox in allCheckboxes
try
if name of aCheckbox is in UnwantedCheckboxes and value of aCheckbox is 1 then
click aCheckbox
end if
end try
end repeat
-- Dismiss the view panel cleanly
try
click button 1 of viewOptionsWindow
on error
perform action "AXPress" of button 1 of viewOptionsWindow
end try
delay 1.0
else
-- Emergency fallback close
keystroke "j" using {command down}
delay 0.5
end if
end tell
end tell
end tell