How does the called script receive the parameter list?
Off the top of my head, I’d say that the called script needs a on run handler.
on run myParameters
end run
on run {parameter1, parameter2}
end run
That’s right. Save a compiled script along these lines:
on run {dialog_message, dialog_title}
display dialog dialog_message with title dialog_title
end run
Then call it from an app or Script Editor like this:
set s to choose file of type "osas" (* or whatever *)
run script s with parameters {"Hello World.", "Greetings"}
I didn’t realize that the script had to be saved as an application - that was it. Thanks Bruce and Kai
Hmm. I believe you can still save it a script.
The called script gets passed a date as text and writes it to a text file. The result is always strange. An example:
list{unprintable character}TEXT{what appears to be a $ symbol}Tuesday, January 10, 2006 9:32:26 PM
the date has been coerced to a string but still does this. The rest of the file is fine
Looks like you’re getting a glimpse of the underlying structure of the data - probably looks a bit like the result of this:
{{date:current date}} as string
Curious… a compiled script works fine for me - as long as everything’s coerced OK.
How are you running the calling script?
That’s because you’re writing a list to the file with the read/write commands.
What I always do is pass a list as a rule. Then you know you always need to get the item first.
gl,
For instance, your calling script might look like this:
set f to choose file – the compiled script
set d to (current date) as string
run script f with parameters {d}
Your compiled script might look like this:
on run p
set d to item 1 of p
set f to choose file name
set rn to (open for access f with write permission)
try
set eof rn to 0
write d to rn
close access rn
on error
close access rn
beep 2
– oops add a return here ← EDITTED
end try
set r to (read f)
return r
end run
Since the parameter is already a list it won’t be coerced to list by the ‘run script’.
gl,
Kel; That’s my script to a tee, with other stuff written, of course, and a nice explanation too. Yours works (as expected). The part I was missing was that a List was being passed and needed to be unloaded: set item 1 to a, item 2 to b, and then write a, b, etc. Thanks.
Hi Adam,
Glad you got it working. As reminder, you can get your parameters easier especially when you have more than 1 with:
set the_list to {1,2,3}
set {a,b,c} to the_list
It just takes me longer to type brackets and isn’t worth it with one item. I think you know this already.
gl,