I was working on my lyric grabber program and I must have deleted a certain line of code on accident or something because i have a push button that searches for lyrics (you’ll understand when you see the code), but now when its clicked it does absolutely nothing…it used to work fine. I have tried fixing it but i am horrible at spotting small erros which this undoubtely is. If someone could find it and point it out that would be great. TIA.
-- Serenade.applescript
-- Serenade
-- Created by Collin on 11/08/06.
-- Copyright 2006 Hendosoft. All rights reserved.
property cur_track : ""
property cur_song : ""
property cur_artist : ""
property theLyrics : ""
property song_name : ""
on clicked theObject
if the name of theObject is equal to "listen" then
set buttonstate to enabled of button "lyric_search" of window "mainWindow"
if buttonstate is equal to true then
set enabled of button "lyric_search" of window "mainWindow" to false
else
set enabled of button "lyric_search" of window "mainWindow" to true
end if
set checkstate to contents of button "listen" of window "mainWindow"
if checkstate is equal to true then
using terms from application "iTunes"
tell application "iTunes"
if exists (database ID of current track) then
set cur_track to the current track
set cur_song to the name of the current track
set cur_artist to the artist of the current track
end if
end tell
end using terms from
set theSong to cur_song
set theArtist to cur_artist
using terms from application "iTunes"
tell application "iTunes"
set theLyrics to the lyrics of cur_track
end tell
end using terms from
tell window "mainWindow"
set the contents of text view "lyrics" of scroll view "lyrics" to theLyrics
end tell
if theLyrics is equal to "" then
try
set theSong to edittext(theSong)
set theArtist to edittext(theArtist)
set ASTID to AppleScript's text item delimiters
set AppleScript's text item delimiters to {" "}
set theSong to text items of theSong
set theArtist to text items of theArtist
set AppleScript's text item delimiters to {"-"}
set theSong to theSong as Unicode text
set theArtist to theArtist as Unicode text
set AppleScript's text item delimiters to {""}
get "http://www.lyricsdir.com/" & theArtist & "-" & theSong & "-lyrics.html"
do shell script "/usr/bin/curl --user-agent '' " & quoted form of result
set theLyrics to result
set AppleScript's text item delimiters to {"<div id=\"lyrics\">"}
set theLyrics to (last text item of theLyrics) as Unicode text
set AppleScript's text item delimiters to {"</div>"}
set theLyrics to first text item of theLyrics
set AppleScript's text item delimiters to {"<br />"}
set theLyrics to text items of theLyrics
set AppleScript's text item delimiters to {""}
set theLyrics to text 2 thru -1 of (theLyrics as Unicode text)
set AppleScript's text item delimiters to ASTID
tell window "mainWindow"
set contents of text view "lyrics" of scroll view "lyrics" to theLyrics
end tell
using terms from application "iTunes"
tell application "iTunes"
set cur_track to the current track
set the lyrics of cur_track to theLyrics
end tell
end using terms from
on error
display alert "Attention" as caution message "Lyrics could not be found for " & cur_song & ". They might not exist in the site database or you may not have an active connection to the internet. Manually putting these lyrics in iTunes will result in the lyrics showing up in Serenade." default button "Ok" attached to window "mainWindow"
tell window "mainWindow"
set contents of text view "lyrics" of scroll view "lyrics" to ""
end tell
end try
else if the name of theObject is equal to "search_btn" then
set theSong to contents of text field "song_title" of drawer "search_drawer" of window "mainWindow"
set theArtist to contents of text field "song_artist" of drawer "search_drawer" of window "mainWindow"
set theSong to edittext(theSong)
set theArtist to edittext(theArtist)
set ASTID to AppleScript's text item delimiters
set AppleScript's text item delimiters to {" "}
set theSong to text items of theSong
set theArtist to text items of theArtist
set AppleScript's text item delimiters to {"-"}
set theSong to theSong as Unicode text
set theArtist to theArtist as Unicode text
set AppleScript's text item delimiters to {""}
get "http://www.lyricsdir.com/" & theArtist & "-" & theSong & "-lyrics.html"
do shell script "/usr/bin/curl --user-agent '' " & quoted form of result
set theLyrics to result
set AppleScript's text item delimiters to {"<div id=\"lyrics\">"}
set theLyrics to (last text item of theLyrics) as Unicode text
set AppleScript's text item delimiters to {"</div>"}
set theLyrics to first text item of theLyrics
set AppleScript's text item delimiters to {"<br />"}
set theLyrics to text items of theLyrics
set AppleScript's text item delimiters to {""}
set theLyrics to text 2 thru -1 of (theLyrics as Unicode text)
set AppleScript's text item delimiters to ASTID
tell window "mainWindow"
set contents of text view "lyrics" of scroll view "lyrics" to theLyrics
end tell
end if
end if
end if
end clicked
on awake from nib theObject
try
using terms from application "iTunes"
tell application "iTunes"
if exists (database ID of current track) then
set cur_track to the current track
set cur_song to the name of the current track
set cur_artist to the artist of the current track
end if
end tell
end using terms from
set theSong to cur_song
set theArtist to cur_artist
using terms from application "iTunes"
tell application "iTunes"
set theLyrics to the lyrics of cur_track
end tell
end using terms from
tell window "mainWindow"
set the contents of text view "lyrics" of scroll view "lyrics" to theLyrics
end tell
if theLyrics is equal to "" then
set theSong to edittext(theSong)
set theArtist to edittext(theArtist)
set ASTID to AppleScript's text item delimiters
set AppleScript's text item delimiters to {" "}
set theSong to text items of theSong
set theArtist to text items of theArtist
set AppleScript's text item delimiters to {"-"}
set theSong to theSong as Unicode text
set theArtist to theArtist as Unicode text
set AppleScript's text item delimiters to {""}
get "http://www.lyricsdir.com/" & theArtist & "-" & theSong & "-lyrics.html"
do shell script "/usr/bin/curl --user-agent '' " & quoted form of result
set theLyrics to result
set AppleScript's text item delimiters to {"<div id=\"lyrics\">"}
set theLyrics to (last text item of theLyrics) as Unicode text
set AppleScript's text item delimiters to {"</div>"}
set theLyrics to first text item of theLyrics
set AppleScript's text item delimiters to {"<br />"}
set theLyrics to text items of theLyrics
set AppleScript's text item delimiters to {""}
set theLyrics to text 2 thru -1 of (theLyrics as Unicode text)
set AppleScript's text item delimiters to ASTID
tell window "mainWindow"
set contents of text view "lyrics" of scroll view "lyrics" to theLyrics
end tell
using terms from application "iTunes"
tell application "iTunes"
set cur_track to the current track
set the lyrics of cur_track to theLyrics
end tell
end using terms from
end if
on error
using terms from application "iTunes"
tell application "iTunes"
if exists (database ID of current track) then
set song_name to the name of the current track
end if
end tell
end using terms from
if song_name is equal to "" then
tell window "mainWindow"
set contents of text view "lyrics" of scroll view "lyrics" to ""
end tell
end if
end try
end awake from nib
on idle theObject
set checkstate to contents of button "listen" of window "mainWindow"
if checkstate is equal to true then
try
using terms from application "iTunes"
tell application "iTunes"
if exists (database ID of current track) then
set cur_track to the current track
set cur_song to the name of the current track
set cur_artist to the artist of the current track
end if
end tell
end using terms from
set theSong to cur_song
set theArtist to cur_artist
using terms from application "iTunes"
tell application "iTunes"
set theLyrics to the lyrics of cur_track
end tell
end using terms from
tell window "mainWindow"
set the contents of text view "lyrics" of scroll view "lyrics" to theLyrics
end tell
if theLyrics is equal to "" then
set theSong to edittext(theSong)
set theArtist to edittext(theArtist)
set ASTID to AppleScript's text item delimiters
set AppleScript's text item delimiters to {" "}
set theSong to text items of theSong
set theArtist to text items of theArtist
set AppleScript's text item delimiters to {"-"}
set theSong to theSong as Unicode text
set theArtist to theArtist as Unicode text
set AppleScript's text item delimiters to {""}
get "http://www.lyricsdir.com/" & theArtist & "-" & theSong & "-lyrics.html"
do shell script "/usr/bin/curl --user-agent '' " & quoted form of result
set theLyrics to result
set AppleScript's text item delimiters to {"<div id=\"lyrics\">"}
set theLyrics to (last text item of theLyrics) as Unicode text
set AppleScript's text item delimiters to {"</div>"}
set theLyrics to first text item of theLyrics
set AppleScript's text item delimiters to {"<br />"}
set theLyrics to text items of theLyrics
set AppleScript's text item delimiters to {""}
set theLyrics to text 2 thru -1 of (theLyrics as Unicode text)
set AppleScript's text item delimiters to ASTID
tell window "mainWindow"
set contents of text view "lyrics" of scroll view "lyrics" to theLyrics
end tell
using terms from application "iTunes"
tell application "iTunes"
set cur_track to the current track
set the lyrics of cur_track to theLyrics
end tell
end using terms from
end if
on error
tell window "mainWindow"
set contents of text view "lyrics" of scroll view "lyrics" to ""
end tell
end try
end if
end idle
on edittext(someText)
return do shell script "/usr/bin/python -c \"import sys; print unicode(sys.argv[1], 'utf8').lower().encode('utf8')\" " & quoted form of someText
-- Remove anything that is not alphanumeric or a space
return do shell script "echo " & quoted form of someText & " | /usr/bin/ruby -ne 'print $_.delete(\"^a-z\", \"^A-Z\", \"^0-9\", \"^ \")'"
end edittext
on launched theObject
show window "mainWindow"
tell application "iTunes" to activate
end launched
on should quit after last window closed theObject
return true
end should quit after last window closed
Woah. That is one big block of code. It’s hard to understand.
There is also alot of repeating going on. You should learn how to code handlers (i think that’s what it’s called), sometimes also called methods. It would be much easier than having to code the ‘curl’ shell script every single time, then parsing all the
s, and typing that like 5 times. It’s easier to understand by us here, and makes programming easier in the long run for you. It also makes the file size smaller.
Also, what is the name of your button? Is it ‘Listen’? Because that is the only button listed under the ‘clicked’ handler. I think.
maybe you could show me an example of what your talking about. And there is another button called “search_btn” which is the button that isn’t working. I know what a method is but how do you make a method in Applescript? (I have only done them in SilverCreator) I would like to see this code shortened but I am …well…still quite new at Applescript, and I don’t really know how…
Not sure if it’s the main problem, but that needs to be changed; Only the first shell script is going to be run.
on edittext(someText)
-- Make text lowercase and remove anything that is not alphanumeric or a space
return do shell script "/usr/bin/python -c \"import sys; print unicode(sys.argv[1], 'utf8').lower().encode('utf8')\" " & quoted form of someText & " | /usr/bin/ruby -ne 'print $_.delete(\"^a-z\", \"^A-Z\", \"^0-9\", \"^ \")'"
end edittext
Also, I think you could replace the strings in the shell script while you’re at it.
on edittext(someText)
-- Make text lowercase and remove anything that is not alphanumeric or a space, then replace spaces with hyphens
return do shell script "/usr/bin/python -c \"import sys; print unicode(sys.argv[1], 'utf8').lower().encode('utf8')\" " & quoted form of someText & " | /usr/bin/ruby -ne 'print $_.delete(\"^a-z\", \"^A-Z\", \"^0-9\", \"^ \").gsub(\" \", \"-\")'"
end edittext
PS: hendo13, these two scripts are examples of a subroutine/handler/function/method (whichever concept you’re familiar with). See also: Defining and Calling Subroutines
thanks Bruce, I have shortened the code a little but still haven’t been able to spot the error. this is my code now (its still fairly long:/)
-- Serenade.applescript
-- Serenade
-- Created by Collin on 11/08/06.
-- Copyright 2006 Hendosoft. All rights reserved.
property cur_track : ""
property cur_song : ""
property cur_artist : ""
property theLyrics : ""
property song_name : ""
on clicked theObject
if the name of theObject is equal to "listen" then
set buttonstate to enabled of button "lyric_search" of window "mainWindow"
if buttonstate is equal to true then
set enabled of button "lyric_search" of window "mainWindow" to false
else
set enabled of button "lyric_search" of window "mainWindow" to true
end if
set checkstate to contents of button "listen" of window "mainWindow"
if checkstate is equal to true then
using terms from application "iTunes"
tell application "iTunes"
if exists (database ID of current track) then
set cur_track to the current track
set cur_song to the name of the current track
set cur_artist to the artist of the current track
end if
end tell
end using terms from
set theSong to cur_song
set theArtist to cur_artist
using terms from application "iTunes"
tell application "iTunes"
set theLyrics to the lyrics of cur_track
end tell
end using terms from
tell window "mainWindow"
set the contents of text view "lyrics" of scroll view "lyrics" to theLyrics
end tell
if theLyrics is equal to "" then
try
set theSong to edittext(theSong)
set theArtist to edittext(theArtist)
get "http://www.lyricsdir.com/" & theArtist & "-" & theSong & "-lyrics.html"
do shell script "/usr/bin/curl --user-agent '' " & quoted form of result
set theLyrics to result
set AppleScript's text item delimiters to {"<div id=\"lyrics\">"}
set theLyrics to (last text item of theLyrics) as Unicode text
set AppleScript's text item delimiters to {"</div>"}
set theLyrics to first text item of theLyrics
set AppleScript's text item delimiters to {"<br />"}
set theLyrics to text items of theLyrics
set AppleScript's text item delimiters to {""}
set theLyrics to text 2 thru -1 of (theLyrics as Unicode text)
tell window "mainWindow"
set contents of text view "lyrics" of scroll view "lyrics" to theLyrics
end tell
using terms from application "iTunes"
tell application "iTunes"
set cur_track to the current track
set the lyrics of cur_track to theLyrics
end tell
end using terms from
on error
display alert "Attention" as caution message "Lyrics could not be found for " & cur_song & ". They might not exist in the site database or you may not have an active connection to the internet. Manually putting these lyrics in iTunes will result in the lyrics showing up in Serenade." default button "Ok" attached to window "mainWindow"
tell window "mainWindow"
set contents of text view "lyrics" of scroll view "lyrics" to ""
end tell
end try
else if the name of theObject is equal to "search_btn" then
set theSong to contents of text field "song_title" of drawer "search_drawer" of window "mainWindow"
set theArtist to contents of text field "song_artist" of drawer "search_drawer" of window "mainWindow"
set theSong to edittext(theSong)
set theArtist to edittext(theArtist)
get "http://www.lyricsdir.com/" & theArtist & "-" & theSong & "-lyrics.html"
do shell script "/usr/bin/curl --user-agent '' " & quoted form of result
set theLyrics to result
set AppleScript's text item delimiters to {"<div id=\"lyrics\">"}
set theLyrics to (last text item of theLyrics) as Unicode text
set AppleScript's text item delimiters to {"</div>"}
set theLyrics to first text item of theLyrics
set AppleScript's text item delimiters to {"<br />"}
set theLyrics to text items of theLyrics
set AppleScript's text item delimiters to {""}
set theLyrics to text 2 thru -1 of (theLyrics as Unicode text)
tell window "mainWindow"
set contents of text view "lyrics" of scroll view "lyrics" to theLyrics
end tell
end if
end if
end if
end clicked
on awake from nib theObject
try
using terms from application "iTunes"
tell application "iTunes"
if exists (database ID of current track) then
set cur_track to the current track
set cur_song to the name of the current track
set cur_artist to the artist of the current track
end if
end tell
end using terms from
set theSong to cur_song
set theArtist to cur_artist
using terms from application "iTunes"
tell application "iTunes"
set theLyrics to the lyrics of cur_track
end tell
end using terms from
tell window "mainWindow"
set the contents of text view "lyrics" of scroll view "lyrics" to theLyrics
end tell
if theLyrics is equal to "" then
set theSong to edittext(theSong)
set theArtist to edittext(theArtist)
get "http://www.lyricsdir.com/" & theArtist & "-" & theSong & "-lyrics.html"
do shell script "/usr/bin/curl --user-agent '' " & quoted form of result
set theLyrics to result
set AppleScript's text item delimiters to {"<div id=\"lyrics\">"}
set theLyrics to (last text item of theLyrics) as Unicode text
set AppleScript's text item delimiters to {"</div>"}
set theLyrics to first text item of theLyrics
set AppleScript's text item delimiters to {"<br />"}
set theLyrics to text items of theLyrics
set AppleScript's text item delimiters to {""}
set theLyrics to text 2 thru -1 of (theLyrics as Unicode text)
tell window "mainWindow"
set contents of text view "lyrics" of scroll view "lyrics" to theLyrics
end tell
using terms from application "iTunes"
tell application "iTunes"
set cur_track to the current track
set the lyrics of cur_track to theLyrics
end tell
end using terms from
end if
on error
using terms from application "iTunes"
tell application "iTunes"
if exists (database ID of current track) then
set song_name to the name of the current track
end if
end tell
end using terms from
if song_name is equal to "" then
tell window "mainWindow"
set contents of text view "lyrics" of scroll view "lyrics" to ""
end tell
end if
end try
end awake from nib
on idle theObject
set checkstate to contents of button "listen" of window "mainWindow"
if checkstate is equal to true then
try
using terms from application "iTunes"
tell application "iTunes"
if exists (database ID of current track) then
set cur_track to the current track
set cur_song to the name of the current track
set cur_artist to the artist of the current track
end if
end tell
end using terms from
set theSong to cur_song
set theArtist to cur_artist
using terms from application "iTunes"
tell application "iTunes"
set theLyrics to the lyrics of cur_track
end tell
end using terms from
tell window "mainWindow"
set the contents of text view "lyrics" of scroll view "lyrics" to theLyrics
end tell
if theLyrics is equal to "" then
set theSong to edittext(theSong)
set theArtist to edittext(theArtist)
get "http://www.lyricsdir.com/" & theArtist & "-" & theSong & "-lyrics.html"
do shell script "/usr/bin/curl --user-agent '' " & quoted form of result
set theLyrics to result
set AppleScript's text item delimiters to {"<div id=\"lyrics\">"}
set theLyrics to (last text item of theLyrics) as Unicode text
set AppleScript's text item delimiters to {"</div>"}
set theLyrics to first text item of theLyrics
set AppleScript's text item delimiters to {"<br />"}
set theLyrics to text items of theLyrics
set AppleScript's text item delimiters to {""}
set theLyrics to text 2 thru -1 of (theLyrics as Unicode text)
tell window "mainWindow"
set contents of text view "lyrics" of scroll view "lyrics" to theLyrics
end tell
using terms from application "iTunes"
tell application "iTunes"
set cur_track to the current track
set the lyrics of cur_track to theLyrics
end tell
end using terms from
end if
on error
tell window "mainWindow"
set contents of text view "lyrics" of scroll view "lyrics" to ""
end tell
end try
end if
end idle
on edittext(someText)
-- Make text lowercase and remove anything that is not alphanumeric or a space, then replace spaces with hyphens
return do shell script "/usr/bin/python -c \"import sys; print unicode(sys.argv[1], 'utf8').lower().encode('utf8')\" " & quoted form of someText & " | /usr/bin/ruby -ne 'print $_.delete(\"^a-z\", \"^A-Z\", \"^0-9\", \"^ \").gsub(\" \", \"-\")'"
end edittext
on launched theObject
show window "mainWindow"
tell application "iTunes" to activate
end launched
on should quit after last window closed theObject
return true
end should quit after last window closed
Ok, I pasted that code into my Xcode, and used the handy Find command to show that you tried to call “search_btn” in a ‘if then’ block. All those 'if’s and 'else’s and 'then’s were so confusing, that you forgot to put a ‘end if’ somewhere!
UPDATE: I think i fixed it for you. You forgot to ‘end if’ before you checked if ‘name of theobject is “search_btn”’ near line 61.
I also put the code to get the lyrics in a method, called ‘getlyrics()’.
It should work the same.
Before- 244 lines
Now- 191 lines!
-- Serenade.applescript
-- Serenade
-- Created by Collin on 11/08/06.
-- Copyright 2006 Hendosoft. All rights reserved.
property cur_track : ""
property cur_song : ""
property cur_artist : ""
property theLyrics : ""
property song_name : ""
on clicked theObject
if the name of theObject is equal to "listen" then
set buttonstate to enabled of button "lyric_search" of window "mainWindow"
if buttonstate is equal to true then
set enabled of button "lyric_search" of window "mainWindow" to false
else
set enabled of button "lyric_search" of window "mainWindow" to true
end if
set checkstate to contents of button "listen" of window "mainWindow"
if checkstate is equal to true then
using terms from application "iTunes"
tell application "iTunes"
if exists (database ID of current track) then
set cur_track to the current track
set cur_song to the name of the current track
set cur_artist to the artist of the current track
end if
end tell
end using terms from
set theSong to cur_song
set theArtist to cur_artist
using terms from application "iTunes"
tell application "iTunes"
set theLyrics to the lyrics of cur_track
end tell
end using terms from
tell window "mainWindow"
set the contents of text view "lyrics" of scroll view "lyrics" to theLyrics
end tell
if theLyrics is equal to "" then
try
getlyrics()
tell window "mainWindow"
set contents of text view "lyrics" of scroll view "lyrics" to theLyrics
end tell
using terms from application "iTunes"
tell application "iTunes"
set cur_track to the current track
set the lyrics of cur_track to theLyrics
end tell
end using terms from
on error
display alert "Attention" as caution message "Lyrics could not be found for " & cur_song & ". They might not exist in the site database or you may not have an active connection to the internet. Manually putting these lyrics in iTunes will result in the lyrics showing up in Serenade." default button "Ok" attached to window "mainWindow"
tell window "mainWindow"
set contents of text view "lyrics" of scroll view "lyrics" to ""
end tell
end try
end if
end if
else if the name of theObject is equal to "search_btn" then
set theSong to contents of text field "song_title" of drawer "search_drawer" of window "mainWindow"
set theArtist to contents of text field "song_artist" of drawer "search_drawer" of window "mainWindow"
getlyrics()
tell window "mainWindow"
set contents of text view "lyrics" of scroll view "lyrics" to theLyrics
end tell
end if
end clicked
on awake from nib theObject
try
using terms from application "iTunes"
tell application "iTunes"
if exists (database ID of current track) then
set cur_track to the current track
set cur_song to the name of the current track
set cur_artist to the artist of the current track
end if
end tell
end using terms from
set theSong to cur_song
set theArtist to cur_artist
using terms from application "iTunes"
tell application "iTunes"
set theLyrics to the lyrics of cur_track
end tell
end using terms from
tell window "mainWindow"
set the contents of text view "lyrics" of scroll view "lyrics" to theLyrics
end tell
if theLyrics is equal to "" then
getlyrics()
tell window "mainWindow"
set contents of text view "lyrics" of scroll view "lyrics" to theLyrics
end tell
using terms from application "iTunes"
tell application "iTunes"
set cur_track to the current track
set the lyrics of cur_track to theLyrics
end tell
end using terms from
end if
on error
using terms from application "iTunes"
tell application "iTunes"
if exists (database ID of current track) then
set song_name to the name of the current track
end if
end tell
end using terms from
if song_name is equal to "" then
tell window "mainWindow"
set contents of text view "lyrics" of scroll view "lyrics" to ""
end tell
end if
end try
end awake from nib
on idle theObject
set checkstate to contents of button "listen" of window "mainWindow"
if checkstate is equal to true then
try
using terms from application "iTunes"
tell application "iTunes"
if exists (database ID of current track) then
set cur_track to the current track
set cur_song to the name of the current track
set cur_artist to the artist of the current track
end if
end tell
end using terms from
set theSong to cur_song
set theArtist to cur_artist
using terms from application "iTunes"
tell application "iTunes"
set theLyrics to the lyrics of cur_track
end tell
end using terms from
tell window "mainWindow"
set the contents of text view "lyrics" of scroll view "lyrics" to theLyrics
end tell
if theLyrics is equal to "" then
getlyrics()
tell window "mainWindow"
set contents of text view "lyrics" of scroll view "lyrics" to theLyrics
end tell
using terms from application "iTunes"
tell application "iTunes"
set cur_track to the current track
set the lyrics of cur_track to theLyrics
end tell
end using terms from
end if
on error
tell window "mainWindow"
set contents of text view "lyrics" of scroll view "lyrics" to ""
end tell
end try
end if
end idle
on edittext(someText)
-- Make text lowercase and remove anything that is not alphanumeric or a space, then replace spaces with hyphens
return do shell script "/usr/bin/python -c \"import sys; print unicode(sys.argv[1], 'utf8').lower().encode('utf8')\" " & quoted form of someText & " | /usr/bin/ruby -ne 'print $_.delete(\"^a-z\", \"^A-Z\", \"^0-9\", \"^ \").gsub(\" \", \"-\")'"
end edittext
on getlyrics() --method to get lyrics...
set theSong to edittext(theSong) --convert the texts
set theArtist to edittext(theArtist)
get "http://www.lyricsdir.com/" & theArtist & "-" & theSong & "-lyrics.html"
do shell script "/usr/bin/curl --user-agent '' " & quoted form of result
set theLyrics to result
set AppleScript's text item delimiters to {"<div id=\"lyrics\">"}
set theLyrics to (last text item of theLyrics) as Unicode text
set AppleScript's text item delimiters to {"</div>"}
set theLyrics to first text item of theLyrics
set AppleScript's text item delimiters to {"<br />"}
set theLyrics to text items of theLyrics
set AppleScript's text item delimiters to {""}
set theLyrics to text 2 thru -1 of (theLyrics as Unicode text)
end getlyrics
on launched theObject
show window "mainWindow"
tell application "iTunes" to activate
end launched
on should quit after last window closed theObject
return true
end should quit after last window closed
set buttonstate to enabled of button "lyric_search" of window "mainWindow"
if buttonstate is equal to true then
set enabled of button "lyric_search" of window "mainWindow" to false
else
set enabled of button "lyric_search" of window "mainWindow" to true
end if
.with this:
tell button "lyric_search" of window "mainWindow" to set enabled to not enabled
not will effectively get the opposite of the current value.
A wonderful bit of code! On the surface I would read that as setting the enabled to “false.” However, when applying binary logic to the statement…like I said, “a wonderful bit of code!” Never would have thought of that myself!