This posting is older than 6 months and can contain outdated information.
Here is an updated, localized aware version of the script.
set shared to false
activate application "iTunes"
tell application "System Events"
set sharedname to localized string "135.006" in bundle path to application "iTunes"
set playlistname to localized string "135.014" in bundle path to application "iTunes"
tell process "iTunes"
repeat with the_row in every row of outline 1 of scroll area 1 of splitter group 1 of window 1
-- figure out the name
set the_name to value of static text 1 of the_row
-- the menu we look for to switch off connecting
-- (localized)
if (the_name = playlistname) then
set shared to false
end if
if shared then
-- for some reason we have to show the context menu
perform action "AXShowMenu" of the_row
-- and then dismiss it
key code {49}
end if
-- the menu we look for to switch on connecting
if the_name = sharedname then
set shared to true
log "Got shared"
end if
end repeat
end tell
end tell