Hello everyone, Im very new to AppleScript and I come to seek help.
Im having trouble using “choose from list”. I want to be able to select any of all the possible combinations from my list. What I can’t do is select the top and bottom in the list while missing out the middle one. Is there a solution to this please.
Here is small part of my script which is to be used in creating a playlist in iTunes by a specific artist and artist type.
choose from list {"Artist", "Album Artist", "Composer"} default items {"Artist"} with title "Choose an Artist Type" with multiple selections allowed without empty selection allowed
if the result is not false then
copy the result to user_selection
end if
Membership in this forum requires that the webmaster know your real name and email address.
An AppleScript application can be written to do really evil things to the machine running it. We simply can not and will not allow members to include scripts in our forums or to link to binaries of scripts on external servers if the webmaster doesn’t know exactly who the author is. In fact, there is legislation in force and some pending legislation (HIPAA, FACTA and Gramm-Leach-Bliley {GBL}) that apply to MacScripter, LLC, so we must be cautious.
Rather than trying to hide your last name, you are encouraged to use a non-revealing user name and that is all visitors to MacScripter sections will ever see. Your real name is never available to the public {or sold to others}, nor is your true email address exposed. If a user wishes to contact you directly they can do so from the links on the scripts info page.
Hello Adam, I apologize for not being forthcoming with my last name. This is hopefully now resolved as I have made contact with Ray and Im now posting this message :D.
I have found a workaround to the problem by adding to the default items. This is only a viable solution due to the low number of items is my list. I am still looking for a better solution and one that works with more than three items.
Here is a working version of the full script, It’s my first script thats does more that just beep so if you have any tips for tidying it up, They would be appreciated.
-- This script will create a new playlist for iTunes based on your chosen artist.
--This will name the playlist
repeat
display dialog "Choose a name for your new playlist." default answer "My Cool Playlist" buttons {"Cancel", "OK"} default button 2 with title "Name your Playlist"
copy the result as list to {playlist_name}
if playlist_name is not "" then exit repeat
end repeat
--This will name the Artist
repeat
display dialog "Enter the Artist for whom you will create a Playlist." default answer "Beatles" buttons {"Cancel", "OK"} default button 2 with title "Choose an Artist"
copy the result as list to {chosen_artist}
if chosen_artist is not "" then exit repeat
end repeat
--This will choose an Artist Type
choose from list {"Artist", "Album Artist", "Composer"} default items {"Artist", "Composer"} with title "Choose an Artist Type" with multiple selections allowed without empty selection allowed
if the result is not false then
copy the result to user_selection
--This will create the playlist
tell application "iTunes"
make playlist with properties {name:playlist_name}
if user_selection is {"Artist"} then
duplicate (every track of playlist 1 whose artist contains chosen_artist) to playlist playlist_name
else if user_selection is {"Album Artist"} then
duplicate (every track of playlist 1 whose album artist contains chosen_artist) to playlist playlist_name
else if user_selection is {"Composer"} then
duplicate (every track of playlist 1 whose composer contains chosen_artist) to playlist playlist_name
else if user_selection is {"Artist", "Album Artist"} then
duplicate (every track of playlist 1 whose artist contains chosen_artist) to playlist playlist_name
duplicate (every track of playlist 1 whose album artist contains chosen_artist) to playlist playlist_name
else if user_selection is {"Album Artist", "Composer"} then
duplicate (every track of playlist 1 whose album artist contains chosen_artist) to playlist playlist_name
duplicate (every track of playlist 1 whose composer contains chosen_artist) to playlist playlist_name
else if user_selection is {"Artist", "Composer"} then
duplicate (every track of playlist 1 whose artist contains chosen_artist) to playlist playlist_name
duplicate (every track of playlist 1 whose composer contains chosen_artist) to playlist playlist_name
else if user_selection is {"Artist", "Album Artist", "Composer"} then
duplicate (every track of playlist 1 whose artist contains chosen_artist) to playlist playlist_name
duplicate (every track of playlist 1 whose album artist contains chosen_artist) to playlist playlist_name
duplicate (every track of playlist 1 whose composer contains chosen_artist) to playlist playlist_name
end if
activate
set view of front browser window to playlist playlist_name
try
play playlist playlist_name
end try
--If no artist is found, playlist can be removed or kept
set new_artist_playlist to every track of playlist playlist_name
if new_artist_playlist is {} then
beep
display dialog "Remove the empty playlist." buttons {"Keep", "Remove"} default button 2 with title "There is no Artist of that name" with icon 2
if the button returned of the result is "Remove" then
delete playlist playlist_name
if player state is playing then
set view of front browser window to (get the current playlist)
end if
end if
end if
end tell
end if
I don’t understand what your saying here. When I run this I am able to select Artist & Composer without selecting Album Artist. Is that what you are having problems doing?
you can select non consecutive items very easily by pressing the command key
Your if - else contruction can be made shorter (Note: without empty selection allowed is not needed because this is the default setting)
...
set user_selection to choose from list {"Artist", "Album Artist", "Composer"} default items {"Artist", "Composer"} with title "Choose an Artist Type" with multiple selections allowed
if the result is false then return
tell application "iTunes"
make playlist with properties {name:playlist_name}
if user_selection contains {"Artist"} then duplicate (every track of playlist 1 whose artist contains chosen_artist) to playlist playlist_name
if user_selection contains {"Album Artist"} then duplicate (every track of playlist 1 whose album artist contains chosen_artist) to playlist playlist_name
if user_selection contains {"Composer"} then duplicate (every track of playlist 1 whose composer contains chosen_artist) to playlist playlist_name
end tell
...
Yes, When I run that section of script I can NOT select Artist & Composer without Album Artist also being selected.
Thanks for the tips Stefan but will making the two lines into one only work for the part that you quoted or can I use it for the next section where I need to issue two commands after there is a multiple selection, Perhaps separated by the & character.
-- This script will create a new playlist for iTunes based on your chosen artist.
--This will name the playlist
repeat
display dialog "Choose a name for your new playlist." default answer "My Cool Playlist" buttons {"Cancel", "OK"} default button 2 with title "Name your Playlist"
copy the result as list to {playlist_name}
if playlist_name is not "" then exit repeat
end repeat
--This will name the Artist
repeat
display dialog "Enter the Artist for whom you will create a Playlist." default answer "Beatles" buttons {"Cancel", "OK"} default button 2 with title "Choose an Artist"
copy the result as list to {chosen_artist}
if chosen_artist is not "" then exit repeat
end repeat
--This will choose an Artist Type
set user_selection to choose from list {"Artist", "Album Artist", "Composer"} with prompt "To select non sequential items" & return & " Use the Command key" default items {"Artist"} with title "Choose an Artist Type" with multiple selections allowed
if the result is false then return
--This will create the playlist
tell application "iTunes"
make playlist with properties {name:playlist_name}
if user_selection contains {"Artist"} then duplicate (every track of playlist 1 whose artist contains chosen_artist) to playlist playlist_name
if user_selection contains {"Album Artist"} then duplicate (every track of playlist 1 whose album artist contains chosen_artist) to playlist playlist_name
if user_selection contains {"Composer"} then duplicate (every track of playlist 1 whose composer contains chosen_artist) to playlist playlist_name
activate
set view of front browser window to playlist playlist_name
try
play playlist playlist_name
end try
--If no artist is found, playlist can be removed or kept
set new_artist_playlist to every track of playlist playlist_name
if new_artist_playlist is {} then
beep
display dialog "Remove the empty playlist." buttons {"Keep", "Remove"} default button 2 with title "There is no Artist of that name" with icon 2
if the button returned of the result is "Remove" then
delete playlist playlist_name
if player state is playing then
set view of front browser window to (get the current playlist)
end if
end if
end if
end tell
end