Fwd: get lyrics from Music app
Fwd: get lyrics from Music app
- Subject: Fwd: get lyrics from Music app
- From: Jim Weisbin via AppleScript-Users <email@hidden>
- Date: Sun, 6 Nov 2022 22:01:34 -0500
This was an easy fix.
> set results to (every file track whose name contains theName)
Changed that to
set results to (every file track whose name is theName)
and
> set results to (every file track whose id contains myID)
changed to
set results to (every file track whose id is myID)
Now it’s fast
Thanks all.
> Begin forwarded message:
>
> On November 6, 2022 at 5:21:46 PM EST, Jim Weisbin <email@hidden>
> wrote
>
> So this actually works, but it’s slow. The reason is, I have to first get a
> list of tracks that match the user’s input, then have the user choose from
> that list of names and ID's. I have to somehow tie the ID to the name the
> user chooses, but I can’t just have the user choose from the “results” array,
> because no names in there. So I make a separate array of names and ID’s and
> then have the user choose one, and then I have to search for that ID, which
> is the slow part. If anyone knows a better way please let me know.
>
> set theName to the text returned of (display dialog "What is the track name?"
> default answer "")
> -- display dialog theName
> tell application "Music"
> activate
> set myTrackList to {}
> set myNameList to {}
> try
> set results to (every file track whose name contains theName)
> on error
> beep
> display dialog "nothing found"
> return
> end try
> repeat with i in results
> set my_track to i
> set myProperties to get properties of i
> set myName to get name of myProperties
> set myTrackID to get id of myProperties
> set myRecord to myName & "::" & myTrackID
> copy myRecord to the end of myNameList
> end repeat
> set theArray to {}
> set myID to {}
> if myNameList is equal to {} then
> beep
> display dialog "nothing found"
> return
> end if
> set myNameChoice to choose from list myNameList
> set oldDelimiters to AppleScript's text item delimiters
> set AppleScript's text item delimiters to "::"
> set theArray to every text item of myNameChoice as string
> set myID to last text item of theArray
> --display dialog myID
> set AppleScript's text item delimiters to oldDelimiters
> set results to (every file track whose id contains myID)
> set my_track to first item of results
> set myProperties to get properties of my_track
> set myLyrics to get lyrics of myProperties
> if myLyrics is equal to "" then
> beep
> display dialog "no lyrics found"
> else
> set the clipboard to myLyrics
> tell application "System Events" to tell process "Finder"
> set frontmost to true
> click menu item "show Clipboard" of menu "Edit" of menu
> bar 1
> end tell
> end if
> end tell
Jim Weisbin | C.T.O. | Human | Post Human | 27 West 20th Street | Suite 801 |
New York, NY | 10011 | (917) 375-2272 | 2046 Broadway | Santa Monica, CA |
90404 |
_______________________________________________
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