• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Reload Library?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Reload Library?


  • Subject: Re: Reload Library?
  • From: Stan Cleveland <email@hidden>
  • Date: Thu, 19 May 2016 14:30:43 -0700

On May 19, 2016, at 01:20 PM, Christopher Stone <email@hidden> wrote:

If I have a library: ~/Library/Script Libraries/z_TestAE.scptd

And I call a handler from it with another script:

---------------------------------------------
use zTestLb : script "z_Test"
use scripting additions

set theText to zTestLb's TEST_LIBRARY_HANDLER()
display alert theText
---------------------------------------------

Then I change the library handler and save it. I also recompile and save the calling script.

FastScripts will still call the originally loaded version of the library and NOT the updated version.

This also happens with some peculiarities in Script Debugger 5.

Is there a way to force the library to be reloaded in the calling script?

Hi Chris,

I've also had issues with retention of code from older library versions. Don't remember the specifics at the moment, but I do use Debugger and FastScripts. I usually load libraries using has's AppleMods Loader system, but I have used the method below for special cases.

The instructions and sample code below are for a "big hammer" that's almost guaranteed to eliminate the problem. It really does reload every library on every run. Even if a script aborts execution due to an error and retains loaded libraries in its saved state, the initial call to loadTextLibrary would replace any leftover code.

Regards,
Stan C.

---------------------------------------------
1. Save your libraries (in some convenient folder location) as text files with the ".applescript" file extension.
2. In your calling script, add a property for each library to be used and add the loadTextLibrary handler.
3. At the start of the script, define each library property by calling the handler.
4. Call handlers from the defined libraries as desired.
5. At the end of the script, clear each library property to prevent retention.
6. You may need to tweak the handler if you use HFS paths, rather than POSIX ones.
---------------------------------------------
property _Filer : missing value -- library for disk/folder/file operations

on run
-- load library
set _Filer to loadTextLibrary("/Users/stanc/TextLibraries/filer.applescript")


-- example call to library routine
set desk to "/Users/stanc/Desktop/"
set usingQuotedForm to true
set {targetPath, showingInvisibles} to {desk, false}
set {dirList, errText} to _Filer's directoryList(targetPath, showingInvisibles, usingQuotedForm)
-- another example call
set sourcePath to desk & "Test.text"
set targetPath to desk & "Junk/Test.txt"
set {itemMoved, errText} to _Filer's fileOrDirectoryMove(sourcePath, targetPath, usingQuotedForm)


-- clear library to prevent retention
set _Filer to missing value
end run

on loadTextLibrary(textLibraryToLoad)
-- convert a script text file into a script object
return run script "script s" & return & ¬
(read textLibraryToLoad as «class utf8») & ¬
return & "end script " & return & "return s"
end loadTextLibrary
---------------------------------------------

 _______________________________________________
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

  • Follow-Ups:
    • Re: Reload Library?
      • From: Christopher Stone <email@hidden>
References: 
 >Reload Library? (From: Christopher Stone <email@hidden>)

  • Prev by Date: Re: Reload Library?
  • Next by Date: Re: Reload Library?
  • Previous by thread: Re: Reload Library?
  • Next by thread: Re: Reload Library?
  • Index(es):
    • Date
    • Thread