Author Topic: q8as: running a script from another script  (Read 2333 times)

0 Members and 1 Guest are viewing this topic.

Offline 4610036

  • Jr. Member
  • **
  • Posts: 50
  • Karma: 0
  • Gender: Female
q8as: running a script from another script
« on: April 13, 2009, 12:41:33 PM »
hey there
i know this is prbly too basic... but

i have created a slug_script that gathers variables and then uses them for slugline.
then i need to use those variables again in the pdf creation name.

1. how do i tell it to run the slug_script first (saved as a separate app or script)?
2. will i be able to keep the variable values? -- this is key since otherwise there's no point running them.

i read about script bundles, but not sure if this is the answer, or is just for things like associated graphics and sounds.
also subroutines seem to have a different purpose. the slug_script is quite long. it would be nice to just reference it.
any help would be (as always) MOST appreciated. 
many thanks
m./

Offline cdms

  • Full Member
  • ***
  • Posts: 111
  • Karma: 6
  • Gender: Male
Re: q8as: running a script from another script
« Reply #1 on: April 14, 2009, 03:39:16 AM »
You can run a script from within another script but you cannot directly keep the variable names between the two. You need to return the value(s), probably as a list if there are multiples. You will then collect these in the calling script. So in the calling script you would have;

set theValues to run script "Path:to:SlugScript"

and at the end of the slug script you would have

return theValues

Having said that I'm not sure this is the way you should go. If your slug has already been created, and you named the text box it was in, you should be able to retrieve the box by name and read the data out of it, without having to run the slug script again.

set theValues to contents of first text box whose name is "Slug Text"

Hopefully one of these approaches will give you what you need.

Offline Publi-Script

  • Administrator
  • Hero Member
  • *****
  • Posts: 596
  • Karma: 16
  • Gender: Male
  • Automate your Life!
    • Publi-Script.com
Re: q8as: running a script from another script
« Reply #2 on: April 14, 2009, 09:03:48 AM »
Hi 4610036 (and welcome to this forum)

It is actually quite simple to have multiple scripts interact with each other. Consider the following scripts:

Script A (the "called upon" script):
Quote
001     on run {param1, param2, param3}
002          set PercentValue to 100 * param2 / param3
003          set DialogSTR to "Hi " & param1 & "!" & return & param2 & " out of " & param3 & " is equal to " & PercentValue & "%"
004          set Dialog to display dialog DialogSTR buttons {"Ok"} with icon note
     
005          return PercentValue
006     end run

Script B (the "calling" script):
Quote
001     property Script_A : alias "path to Script A"

002     set UserName to "Bob"
003     set Numerator to 3
004     set Denomitator to 24

005     set aScript to load script Script_A
006     set PercentValue to run script aScript with parameters {UserName, Numerator, Denomitator}

Hope this helps!
« Last Edit: January 24, 2010, 04:11:38 PM by Publi-Script »
Michel Lemieux
Forum Administrator
-------------------------
OS X 10.6.4
Quark 6.5 / 7.5 / 8.1.6
Adobe Design Premium CS / CS2 / CS3 / CS4 / CS5
Script Debugger 4.5

Offline 4610036

  • Jr. Member
  • **
  • Posts: 50
  • Karma: 0
  • Gender: Female
Re: q8as: running a script from another script
« Reply #3 on: April 15, 2009, 09:47:07 PM »
thanks for the welcome. i'm so new to this. thanks to you guys i've managed to overcome some hurdles and keep going where i might have stalled. no one else i know does this and i'm delighted to have found you and ... well i could go on and on. :-)

cdms great idea on using the slugline as a source, however it would take almost as much juggling to get it back to the "raw" format.
you both suggest returning the values from the script(s).  i admit ive been grappling with it since reading both your posts yesterday morning.  trying to take a loooong script and reparcel it so i can pull out pieces to repurpose in varying scripts. its a whole difft way of thinking and ive not had success so far.

i think i'm being too literal when i think to say:

return jobnum, coname, proofno as list???

however, i didnt want another day to go by without saying a big thank you. i'm trying to only text wen i'm stumped and u all keep coming thru.
m./

Offline Publi-Script

  • Administrator
  • Hero Member
  • *****
  • Posts: 596
  • Karma: 16
  • Gender: Male
  • Automate your Life!
    • Publi-Script.com
Re: q8as: running a script from another script
« Reply #4 on: April 15, 2009, 11:17:32 PM »
Just try

return {jobnum, coname, proofno}

But remember that you actually lose those variable names in the transfer. In other words, AppleScript will ONLY return the values of those variables. So you will have to reassign those returned values to other variables:

In my earlier example, my "called" script only returned 1 value that I assigned to my PercentValue variable. So I used:
set PercentValue to run script aScript with parameters {UserName, Numerator, Denomitator}

For a script that is meant to return multiple values you need to set multiple variables in a similar manner:
set {jobnum, coname, proofno} to [whatever script (or handler) that returns those values]

HTH
Michel Lemieux
Forum Administrator
-------------------------
OS X 10.6.4
Quark 6.5 / 7.5 / 8.1.6
Adobe Design Premium CS / CS2 / CS3 / CS4 / CS5
Script Debugger 4.5

Offline 4610036

  • Jr. Member
  • **
  • Posts: 50
  • Karma: 0
  • Gender: Female
Re: q8as: running a script from another script
« Reply #5 on: January 24, 2010, 04:04:50 PM »
michel and cdms
i just wanted to say a quick thank you.  I posed this question months ago and admit that i was a bit overwhelmed and generally trying to get results without fully understanding the steps or what the *&# i was doing. Now, with a LITTLE more experience this makes perfect sense (so far)... tho i'm pretty sure i'll keep trying to get results and figure out how i got there afterwards.   ;D
thanks!