Re: Converting an array to formatted text
Re: Converting an array to formatted text
- Subject: Re: Converting an array to formatted text
- From: Yvan KOENIG <email@hidden>
- Date: Sat, 15 Jul 2017 12:34:00 +0200
> Le 15 juil. 2017 à 00:11, @lbutlr <email@hidden> a écrit :
>
> I have the following code snippet:
>
> set theAlbum to album of current track
> set theArtist to artist of current track
> set myTracks to (name of every track of view of front window whose album
> contains theAlbum)
> set the clipboard to (myTracks as text)
>
> Which puts something like "Teen Age RiotSilver RocketThe Sprawl'Cross The
> BreezeEric's TripTotal TrashHey JoniProvidenceCandleRain
> KingKissabilityTrilogy" into the clipboard
>
> I'd like to have that list at least comma separated, though i'd like full
> control over it.
>
> Also, I would like to select based on album name AND artist, but I can't get
> that syntax right. Something along theses lines:
>
> set myTracks to (name of every track of view of front window whose album
> contains theAlbum and whose artist contains theArtist)
>
> But I seem to recall that there was an issue with multiple criteria in
> iTunes, so that may not be easily possible.
>
Are you really forced to pass the contents of myTracks in the clipboard?
myTracks is a list like {"Ahmad's Blues (Live)", "Stompin' At the Savoy
(Live)", "Autumn In New York (Live)", "It Could Happen to You (Live)", "Taboo
(Live)", "Secret Love (Live)", "Taking a Chance On Love (Live)", "Soft Winds
(Live)", "Autumn Leaves (Live)", "Our Delight (Live)", "So Beats My Heart for
You (Live)", "I Didn't Know What Time It Was (Live)", "You Don't Know Love Is
(Live)", "Aki & Ukthay (Live)", "Seleritus (Live)", "Tater Pie (Live)", "Ivy
(Live)", "Secret Love (Alternate Version) [Live]", "A Gal In Calico (Live)",
"Ole Devil Moon (Live)", "This Can't Be Love (Live)", "Let's Fall In Love
(Live)", "Should I? (Live)", "That's All (Live)", "I Wish I Knew (Live)", "The
Girl Next Door (Live)", "Cheek to Cheek (Live)", "Squatty Roo (Live)"}
When you convert it as text you get a long string with no way to retrieve the
individual strings.
The simpler scheme would be to keep myTracks as it is.
I tried to same it to the clipboard as is but when I extracted it I got the
object which is boring to treat.
So, if you really need to pass by the clipboard you may use something like :
tell application "iTunes"
set theAlbum to album of current track
set theArtist to artist of current track
set myTracks to (name of every track of view of front window whose
album contains theAlbum)
--> {"Ahmad's Blues (Live)", "Stompin' At the Savoy (Live)", "Autumn In
New York (Live)", "It Could Happen to You (Live)", "Taboo (Live)", "Secret Love
(Live)", "Taking a Chance On Love (Live)", "Soft Winds (Live)", "Autumn Leaves
(Live)", "Our Delight (Live)", "So Beats My Heart for You (Live)", "I Didn't
Know What Time It Was (Live)", "You Don't Know Love Is (Live)", "Aki & Ukthay
(Live)", "Seleritus (Live)", "Tater Pie (Live)", "Ivy (Live)", "Secret Love
(Alternate Version) [Live]", "A Gal In Calico (Live)", "Ole Devil Moon (Live)",
"This Can't Be Love (Live)", "Let's Fall In Love (Live)", "Should I? (Live)",
"That's All (Live)", "I Wish I Knew (Live)", "The Girl Next Door (Live)",
"Cheek to Cheek (Live)", "Squatty Roo (Live)"}
end tell
# concatenate the components using character id 0 as separator
set the clipboard to my recolle(myTracks, character id 0)
# Grab the contents of the clipboard and split it using character id 0 as
separator
set theTracks to my decoupe(the clipboard, character id 0)
--> {"Ahmad's Blues (Live)", "Stompin' At the Savoy (Live)", "Autumn In New
York (Live)", "It Could Happen to You (Live)", "Taboo (Live)", "Secret Love
(Live)", "Taking a Chance On Love (Live)", "Soft Winds (Live)", "Autumn Leaves
(Live)", "Our Delight (Live)", "So Beats My Heart for You (Live)", "I Didn't
Know What Time It Was (Live)", "You Don't Know Love Is (Live)", "Aki & Ukthay
(Live)", "Seleritus (Live)", "Tater Pie (Live)", "Ivy (Live)", "Secret Love
(Alternate Version) [Live]", "A Gal In Calico (Live)", "Ole Devil Moon (Live)",
"This Can't Be Love (Live)", "Let's Fall In Love (Live)", "Should I? (Live)",
"That's All (Live)", "I Wish I Knew (Live)", "The Girl Next Door (Live)",
"Cheek to Cheek (Live)", "Squatty Roo (Live)"}
#=====
on decoupe(t, d)
local oTIDs, l
set {oTIDs, AppleScript's text item delimiters} to {AppleScript's text
item delimiters, d}
set l to text items of t
set AppleScript's text item delimiters to oTIDs
return l
end decoupe
#=====
on recolle(l, d)
local oTIDs, t
set {oTIDs, AppleScript's text item delimiters} to {AppleScript's text
item delimiters, d}
set t to l as text
set AppleScript's text item delimiters to oTIDs
return t
end recolle
#=====
Yvan KOENIG running Sierra 10.12.5 in French (VALLAURIS, France) samedi 15
juillet 2017 12:33:41
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden