TITLE
    AppleScript: Script Editor Error "Source Not Available"
Article ID:
Created:
Modified:
17171
2/10/95
3/18/99

TOPIC

    The script below, gives the error "Source not available" on repeated runs when the events log window is open and "Show Event Results" is checked. The script worked fine for a period of time, until suddenly this error started occurring.

    set FinderLib to load script (alias ((path to ┬ extensions folder as string) & "Scripting Additions:finderLib"))


DISCUSSION

    This script is actually getting a -1756 error. This can be determined by surrounding the given statement with an AppleScript try / on error processing statement. This error code is returned from a call to OSAGetSource function to decompile the script data, and obtain the equivalent source data. The problem is that finderLib is compiled and saved with Save As Run-Only which does not save the AppleScript text with the object for later editing and display.

    FinderLib was intended to be used with the "barely-scriptable" Finder of System 7.1 or the Finder 7.0 after ResEditing an aete resource into the Finder. AppleScript 1.0 came with Script Editor 1.0.1 and the finderLib facility. This version of the Script Editor did not have the event window logging capability that came with AppleScript 1.1 and Script Editor 1.1 and later.

    The Script Editor's event logging facility depends on being able to access the source AppleScript, to do event logging, AND show event results against a compiled AppleScript.╩As you found, if Show Event Results are not selected, the Script Editor can run the script just fine against a saved as Run-Only compiled script, since not as much logging detail is being requested.

    What probably happened is, you have upgraded to AppleScript 1.1 where the error will be noticed with finderLib, or you saved other loaded and compiled scripts as Run-Only. To use the full debugging facilities of the Script Editor against loaded compiled scripts, the scripts must be saved with the AppleScript source, for example not as Run-Only. In a compiled AppleScript, you can tell with a resource editor, whether it's saved as Run-Only or not by the presence of an "scpt" resource, which is where the compiled text is saved.

    The following event logs demonstrate what's happening. If you want to reproduce this, compile the miniFinderLib AppleScript, place it in the Scripting Additions folder and run the driving AppleScript from the Script Editor with full event logging. You will see the results similar to the first log. Note how the saved AppleScript text is displayed in the event logging window. Recompile miniFinderLib, save it as Run-Only and rerun the driving AppleScript. This will give the -1756 error or sources not available.

    The driving AppleScript:

    try
    set FinderLib to load script (alias ((path to ┬
    extensions folder as string) & "Scripting Additions:miniFinderLib"))
    tell FinderLib to emptyTrash()
    on error ErrMsg number ErrNmbr
    log ("Error " & ErrNmbr & ": " & ErrMsg)
    display dialog "Error " & ErrNmbr & ": " & ErrMsg
    end try


    The miniFinderLib script:

    on emptyTrash()
    --
    -- Asks the Finder to empty the trash
    --
    tell application "Finder" to empty trash
    end emptyTrash


    Script Editor log with Show Event Results against a compiled library with the source saved:

    tell current application
    path to extensions folder as string
    --> "Macintosh HD:System Folder:Extensions:"
    load script ┬
    alias "Macintosh HD:System Folder:Extensions:Scripting Additions:miniFinderLib"
    --> on emptyTrash()
    --
    -- Asks the Finder to empty the trash
    --
    tell application "Finder" to empty trash
    end emptyTrash
    end tell
    tell application "Finder"
    empty trash
    end tell


    Script Editor log without Show Event Results ?gainst a compiled library saved as Run-Only:

    tell current application
    path to extensions folder as string
    load script ┬
    alias "Macintosh HD:System Folder:Extensions:Scripting Additions:miniFinderLib"
    end tell
    tell application "Finder"
    empty trash
    end tell


    Script Editor log with Show Event Results against a compiled library saved as Run-Only:

    tell current application
    path to extensions folder as string
    --> "empty trash:Extensions:"
    load script ┬
    alias "Macintosh HD:System Folder:Extensions:Scripting Additions:miniFinderLib"
    (*Error -1756: Source not available.*)
    display dialog "Error -1756: Source not available."
    --> {button returned:"OK"}
    end tell

Document Information
Product Area: Apple Software
Category: AppleScript
Sub Category: General Topics

Copyright © 2000 Apple Computer, Inc. All rights reserved.