• 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: Include Scripts?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Include Scripts?


  • Subject: Re: Include Scripts?
  • From: Jon Pugh <email@hidden>
  • Date: Mon, 20 Jul 2009 00:50:19 -0700

At 6:43 PM +0200 7/19/09, Frank Renner wrote:
>what, if any, is the easiest way to "include" a script that ist finally tested and used by many other scripts from all these other scripts?

One of the most useful features of Script Debugger is the ability to use Script Libraries, which are just scripts, without any effort.

I keep a number of scripts in my ~/Library/Application Support/Script Debugger 4.5/ Script Libraries folder.  I include them with just a click and call them without any boilerplate code.  It simply could not be easier.

Script Debugger does the load script stuff under the covers for you.  You can load multiple scripts this way, and share finished scripts with as many other scripts as you want.  If you update your library script, you'll update your script to use it at the next recompile.  The script files are not needed once the script has been saved though, they're copied into the script, so there's no run time dependencies.

By far one of my favorite features that Script Debugger offers.


However, I developed a system using "load script" before Script Debugger existed, and I think this is the best technique for straight AppleScript.  It has a couple bonus features.  The most important one is that it will update at runtime if the library script has been updated and exists in the proper place.  This spares you recompiling all your dependent scripts.

This example uses my SmartString script library.

<http://www.seanet.com/~jonpugh/software/SmartString.applescript>


-- the alias follows the file if it's moved or renamed
property ssFile : alias "/Users/jonpugh/Script Library/SmartString"
-- the modification date is burned in at compile time
property ssDate : modification date of (info for ssFile)
-- as is a copy of the loaded script object
property SmartString : load script ssFile

-- at run time
try
	-- we check the mod date
	set modDate to modification date of (info for ssFile)
	-- if newer
	if modDate > ssDate then
		-- load the newer one into our property,
		-- where the original was stored at compile time
		set SmartString to load script ssFile
		-- remember the date for the newly loaded file
		set ssDate to modDate
		--display dialog "I'm loaded"
	end if
on error m number n
	--display dialog m & return & n
end try
tell SmartString's SmartString
	setString("welcome to the machine")
	betweenStrings("wel", " to the")
end tell

You can avoid the double name by removing the "script" object from your saved script, just putting everything at the top level, but I don't like that since you can't have multiple objects in the file that way, but there's an argument to be made for doing it either way.

Enjoy and good luck.

Jon
 _______________________________________________
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

References: 
 >Include Scripts? (From: Frank Renner <email@hidden>)

  • Prev by Date: Re: QuicKeys and script activation
  • Next by Date: Re: QuicKeys and script activation
  • Previous by thread: Re: Include Scripts?
  • Next by thread: Re: Include Scripts?
  • Index(es):
    • Date
    • Thread