ChrisJenkins

Q: Applescript conflict with the iTunes constants 'error' and 'duplicate'

In AppleScript the keyword 'error' is a reserved word. Unfortunately iTunes also defines a constant called 'error used as a possible value for e.g. a track's iCloud status. As a result code such as:

 

if aTrack's cloud status is equal to purchased then

        set tCloudStatus to "purchased"

else if aTrack's cloud status is equal to matched then

        set tCloudStatus to "matched"

else if aTrack's cloud status is equal to uploaded then

        set tCloudStatus to "uploaded"

else if aTrack's cloud status is equal to ineligible then

        set tCloudStatus to "ineligible"

else if aTrack's cloud status is equal to removed then

        set tCloudStatus to "removed"

else if aTrack's cloud status is equal to duplicate then

        set tCloudStatus to "duplicate"

else if aTrack's cloud status is equal to subscription then

        set tCloudStatus to "subscription"

else if aTrack's cloud status is equal to no longer available then

        set tCloudStatus to "no longer available"

else if aTrack's cloud status is equal to not uploaded then

        set tCloudStatus to "not uploaded"

else if aTrack's cloud status is equal to error then

        set tCloudStatus to "error"

else

        set tCloudStatus to "unknown"

end if

 

Fails to even save as it complains about the use of 'error''. There is also a similar problem with 'duplicate' (that is also an AppleScript term).

 

Does anyone know how I can force the code to use the iTunes meaning of these terms and not the AppleScript meaning? I tried 'using terms from application "iTunes"' but that did not resolve the problem.

 

Thanks for any pointers...

 

Chris

  if aTrack's cloud

  else

  set tCloudStatus to "unknown"

  end if


Posted on May 29, 2016 1:02 PM

Close

Q: Applescript conflict with the iTunes constants 'error' and 'duplicate'

  • All replies
  • Helpful answers

Previous Page 2
  • by Hiroto,

    Hiroto Hiroto May 30, 2016 11:19 AM in response to ChrisJenkins
    Level 5 (7,348 points)
    May 30, 2016 11:19 AM in response to ChrisJenkins

    Hello

     

    Well, it is a known issue. AppleScript terminology is not usually loaded at run time but at compile time. Fortunately there's workaround.

     

    To get termilogy string from constant at run time in complied script run in applet or run by osascript, you need to manually load terminology. One way is to issue a magic event ascrgdut (applescript get dynamic user terminology) in tell block targeted to the application of which termilogy is to be loaded.

     

    The following script demonstrates how to use it.

     

     

    --loadTerminology(me) -- to load global terminology such as OSAX.
    
    tell application "iTunes"
        activate
        my loadTerminology(it) -- to load the target application's terminology
        display dialog (player state as string)
    end tell
    
    on loadTerminology(a)
        (*
            reference a : reference of which terminology is to be loaded.
        *)
        try
            tell a to «event ascrgdut» -- (AppleSCRipt : Get Dynamic User Terminology)
        end try
    end loadTerminology
    

     

     

     

    You may save this as a complied script and run it by osascript or save as an applet and run it, and see the effect of loadTerminology(). Without loading terminology, raw constant code will be shown, whereas with loading it, raw code is properly decompiled into corresponding terminology.

     

    (Note that if you compile and execute AppleScript source code (.applescript file) by osascript, raw code is decompiled into terminology without calling loadTerminology(). This is because osascript loads terminology in order to compile the source code and no need to reload it at run time.)

     

     

    Good luck,

    H

     

    PS. Although this and other methods already provided may work around the immediate problem, the terminology conflicts which cause the problem in the first place remain to be reported for correction.

Previous Page 2