Tuesday, July 29, 2014

#1 2012-05-06 04:49:53 am

nickharambee
Member
Registered: 2010-08-22
Posts: 84

Applescript referring to handler breaks script when in "tell.. iTunes"

Hi,

I am using the applescript below to convert all Uppercase characters entered in a input dialog box to lowercase.  However, when I enclose the first two lines in "tell application "iTunes/end tell" it breaks the script.  I get the error message:

"iTunes got an error: Can’t continue makeCaseLower."

Could someone help me get this handler working within an iTunes script?

Thanks,

Nick

Applescript:

set theLabel to text returned of (display dialog "Enter label for " with title "Enter Label for Album" default answer "" buttons {"Enter"} default button 1)
   
makeCaseLower(theLabel)
   
end if

on makeCaseLower(theString)
   set UC to "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
   set LC to "abcdefghijklmnopqrstuvwxyz"
   set C to characters of theString
   repeat with ch in C
       if ch is in LC then set contents of ch to item (offset of ch in UC) of LC
   end repeat
   return C as string
end makeCaseLower


Filed under: handler, iTunes, applescript

Offline

 

#2 2012-05-06 06:08:47 am

adayzdone
Member
From: New York
Registered: 2011-01-24
Posts: 478

Re: Applescript referring to handler breaks script when in "tell.. iTunes"

Try:

Applescript:

tell me to makeCaseLower(theLabel)

Offline

 

#3 2012-05-06 09:46:03 am

Yvan Koenig
Member
Registered: 2006-09-14
Posts: 1405

Re: Applescript referring to handler breaks script when in "tell.. iTunes"

I would code :

Applescript:


tell application "iTunes"
   tell current application to set theLabel to text returned of (display dialog "Enter label for " with title "Enter Label for Album" default answer "" buttons {"Enter"} default button 1)
   
   my makeCaseLower(theLabel)
   
end tell

on makeCaseLower(theString)
   set UC to "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
   set LC to "abcdefghijklmnopqrstuvwxyz"
   set C to characters of theString
   repeat with ch in C
       if ch is in LC then set contents of ch to item (offset of ch in UC) of LC
   end repeat
   return C as string
end makeCaseLower

(1) tell current application is used to get rid of error messages issued by every call to OSAX functions from a tell block

(2) the described error message was issued because iTiunes has no idea of what is the makeCaseLower object.
The « tell me to » syntax used by adayzdone is reolving the ambiguity exactly as the shorter « my ».

Yvan KOENIG (VALLAURIS, France) dimanche 6 mai 2012 16:45:55

Offline

 

Board footer

Powered by FluxBB

[ Generated in 0.049 seconds, 11 queries executed ]

RSS (new topics) RSS (active topics)