Monday, December 11, 2017

#1 2002-03-11 08:14:11 am

Trash Man
Sanitation Department
Registered: 2005-10-20
Posts: 5336

Passing Data from one script to another?

Been trying to get the following to work:
1st script saved as an application:

Applescript:

on run {var, var2}
display dialog var & var2 end run
When I run the next script from the script editor:
run script "Mac OS X:Users:cpalma:Desktop:test" given paramenters:{"Hello", "World"}
or
run application "Mac OS X:Users:cpalma:Desktop:test" given paramenters:{"Hello", "World"}

they both fail... any thoughts? or suggestions..
Thanks,


One mans trash is another mans treasure

Offline

 

#2 2002-03-11 11:05:53 am

Trash Man
Sanitation Department
Registered: 2005-10-20
Posts: 5336

Re: Passing Data from one script to another?

: Been trying to get the following to work: 1st script saved as an application:

Applescript:

: on run {var, var2}

: display dialog var & var2 end run

: When I run the next script from the script editor: run script "Mac OS
: X:Users:cpalma:Desktop:test"
given paramenters:{"Hello",
: "World"}

: or

Applescript:

: run application "Mac OS X:Users:cpalma:Desktop:test" given
: paramenters:{"Hello", "World"}

: they both fail... any thoughts? or suggestions..

: Thanks,

: Claudio



Applescript:

tell application "Mac OS X:Users:cpalma:Desktop:test"
launch
ignoring application responses
run("Hello", "World")
end ignoring
end tell

You could eliminate the "ignoring" if your called script returns a value


One mans trash is another mans treasure


Filed under: Mac

Offline

 

#3 2002-03-11 11:24:54 am

Trash Man
Sanitation Department
Registered: 2005-10-20
Posts: 5336

Re: Passing Data from one script to another?

Applescript:

: tell application "Mac OS X:Users:cpalma:Desktop:test"
: launch
: ignoring application responses
: run("Hello", "World")
: end ignoring
: end tell

You could eliminate the "ignoring" if your called
: script returns a value.



Thanks, I tried the above code, but now it gave this Error:
("Hello","World") doesn't understand the run message

It does not return a value...

Claudio


One mans trash is another mans treasure


Filed under: Mac

Offline

 

#4 2002-03-11 11:42:53 am

Andrew Herzog
Member
Registered: 2002-11-20
Posts: 28

Re: Passing Data from one script to another?

I have had the same problem in the past. I found that depending on the version of the OS, or probably the version AppleScript, that you had to code it differently. Below is a snippet of code for you to look at. OSVer has been set previously to the version of the Operating System.

Applescript:

if OSver < 9 then --use codes that work with system versions less than 9
tell application AppToUse
launch
set {SpecList, GenSpec, ErrorList} to (run {PBarPage, SpecList, GenSpec})
end tell --application
else --use codes that work with system 9
set {SpecList, GenSpec, ErrorList} to run script AppToUse with parameters {PBarPage, SpecList, GenSpec}
end if

: Thanks, I tried the above code, but now it gave this Error:
: ("Hello","World") doesn't understand the run message
: It does not return a value...
: Claudio


Andrew Herzog

Offline

 

#5 2002-03-11 12:49:32 pm

Trash Man
Sanitation Department
Registered: 2005-10-20
Posts: 5336

Re: Passing Data from one script to another?

: I have had the same problem in the past. I found that depending on the
: version of the OS, or probably the version AppleScript, that you had to
: code it differently. Below is a snippet of code for you to look at. OSVer
: has been set previously to the version of the Operating System.

Applescript:

: if OSver < 9 then --use codes that work with system versions less than 9
: tell application AppToUse
: launch
: set {SpecList, GenSpec, ErrorList} to (run {PBarPage, SpecList, GenSpec})
: end tell --application
: else --use codes that work with system 9
: set {SpecList, GenSpec, ErrorList} to run script AppToUse with parameters
: {PBarPage, SpecList, GenSpec}
: end if


Thanks!
I finally got it to work using this code:
tell application "Mac OS X:Users:cpalma:Desktop:test" launch run script with parameters {"Hello", "World"} end tell
Claudio


One mans trash is another mans treasure


Filed under: Mac

Offline

 

#6 2002-03-11 02:25:33 am

Trash Man
Sanitation Department
Registered: 2005-10-20
Posts: 5336

Re: Passing Data from one script to another?

... would be not to use the run handler at all. For this sort of task, I think it's more sensible to leave the run handler to do what it's best at: handling the run event sent by the applet shell. Instead, create a new handler to perform the task you need:

Applescript:

on doSomething(var, var2)
display dialog var & var2
end doSomething

on run
display dialog "Hey! Don't run me directly." giving up after 5
end run

And then run the following code in your Script Editor:

Applescript:

tell application "Mac OS X:Users:cpalma:Desktop:test"
launch
ignoring application responses
doSomething("Hello", "World")
end ignoring
end tell

Simple and logical. Plus you can put as many different handlers into the script as you like.

--

Going a little further into it: depending on what it is you're actually trying to do, there may be better approaches than using a script application that launches and quits every time you want to use it. Two possibilities:

1. The "script server" approach, where you save your script applet as a stay-open application so that it's always available and you don't have to muck about with "launch" each time.

2. The "library" approach, where you use the Standard Additions' "load script" feature to 'import' the script you want:

Applescript:

set theDoSomethingModule to load script "Mac OS X:Users:cpalma:Desktop:test"

tell theDoSomethingModule to doSomething("Hello", "World")

Both are very powerful, valuable techniques. They're also extremely easy to use (I use them all the time these days and often wonder how I ever did without).

HTH


One mans trash is another mans treasure


Filed under: Mac

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)