Passing variable between scripts

I need to pass a variable from one script to another. Most posts I’ve found are specific to a complex task. What I need a very simple answer to a very simple task. Here’s my two applescripts

First script includes the following codes that counts the number of files containing specific text and appends the count value “fileCountB” to the file name.

property baseFileNameB : "OpenEndive_0"
    set targetDir to POSIX file "/Applications/Endive Clients/"
    tell application "Finder"
    	set fileCountB to count of (files in folder targetDir whose name contains baseFileNameB)
    end tell

The second script deletes the first script that is named “OpenEndive0” & fileCountB

set newFileNameB to " OpenEndive_0" & fileCountB & ".app"
--Delete OpenEndive_0x() after quiting Endive
set myFile to "/Applications/Endive Clients/" & newFileNameB
try
	do shell script "rm -rf " & quoted form of myFile
end try

How do I pass the value of “fileCountB” to the second script?

If the second script is saved as an applet (don’t forget to turn off the Show Startup Screen option), then you can simply call a handler within the second script:

tell application "Second Script"
    deleteScript(fileCountB)
end

I’m using Automator to run the scripts. Is there a better way to launch the various scripts from one “applet”? Here’s all teh steps my Automator app does:

First Automator App

  1. CopyRename EndiveName.app
  2. CopyRename OpenEndive.app
  3. Run Applescript that appends file count number to both app names
    a. EndiveName1.app
    b. OpenEndive1.app
  4. Launch OpenEndive1.app (first script)
    a. Launches the EndiveName1.app
    b. Deletes EndiveName1.app once app is no longer running
    c. Launches DeleteOpenEndive.app (second script)
  5. Delete OpenEndive1.app

Need to pass the name of the OpenEndive1.app from the “first” script to the “second” script. Is there a better way to this than using Automator?

You could hold this value in an Automator variable and then use the variable in subsequent Automator actions.

Alternatively, could you put whatever code is in the EndiveName1 script in an Automator Run AppleScript action and avoid creating, renaming and deleting the EndiveName1 script.

I’ve rewritten everything as applets in lieu of using Automator and I can’t get the variable to pass to the last applet. I have to run the second applet separately because there will be multiple copies of it running simultaneously. I need to be able to delete each copy as it is finished running. To that I need to pass the correct filename to whatever or wherever the “delete file” routine is.

Example there could be EndiveName1, EndiveName2, and EndiveName3 all running at the same time. As each one is quit, I want to delete that file that was quit. And the apps will be quit out of sequence. i.e., EndiveName2 could be the first app quit, leaving 1 & 3 running.