-- Simple script to run another script that contains global variables (properties).
-- Background:
-- Scripts started via the Eudora plug-in "Scripts" won't save their properties
-- on exit; this is a work-around in the shape of a helper script that runs another
-- script and saves properties if the control key was pressed. This is done for a
-- particular situation where the script that is loaded and executed only needs its
-- global variables saved if the control key was pressed. If you want the properties
-- saved every time then simply remove the "if saveAtEnd then" condition at the end.

-- The path to the script to execute is built the following way:
-- when run via the Scripts plug-in in Eudora, this script will
-- get the path of the Eudora application as the result of the
-- "path to me" command. We will look for the script to execute
-- (it is named "Check Selected Personalities") in the folder
-- "Scripts:Called Scripts" which is in turn found within the 
-- "Eudora Stuff" folder. Put simply, we remove the application name 
-- from the path to Eudora, then add the string
--    ":Eudora Stuff:Scripts:Called Scripts:Check Selected Personalities".
-- This will be a complete path to the script file we want.

-- Markus Frischknecht, copyright 1998. Use this script as you wish, it's free.
-- mailto:mfrischknecht@access.ch


if "Control" is in (keys pressed) then
	-- get personality to check with called script
	set saveAtEnd to true
else
	set saveAtEnd to false
end if


set varMe to (path to me) as string -- == path to Eudora when called by Scripts plug-in

set savedDels to AppleScript's text item delimiters

set AppleScript's text item delimiters to ":"

(text items 1 through -2 of varMe) as string -- path only, don't include name of application

-- set scriptProperties to result & ":Called Scripts:Check Selected Personalities"

set scriptProperties to result & ¬
	":Eudora Stuff:Scripts:Called Scripts:Check Selected Personalities"


set AppleScript's text item delimiters to savedDels -- restore delimiters

set scpt to load script scriptProperties -- load script

-- now possible to run loaded script
run scpt

-- and save it, incl. properties
if saveAtEnd then -- only save if global has changed
	store script scpt in alias scriptProperties with replacing
end if