|
|
#1 |
|
Prospect
Join Date: Jul 2010
Posts: 7
|
How can you pass an empty variable to optional parameters?
Hey guys,
I am dipping my toes on creating Applescript libraries but I am stuck on a situation. So far, I am trying to create a mock example of an entry using all the parameters available for the "display dialog" command and then selectively pass the information I want to it to give me the desired outcome. This is where I am right now... Code:
on display_dialog_box(dialog_text, default_answer, hidden_answer, button_1, button_2, button_3, default_button, cancel_button, with_title, with_icon, giving_up_after)
set theResult to display dialog dialog_text ¬
default answer default_answer ¬
hidden answer hidden_answer ¬
buttons {button_1, button_2, button_3} ¬
default button default_button ¬
cancel button cancel_button ¬
with title with_title ¬
with icon with_icon ¬
giving up after giving_up_after
end display_dialog_box
I tried using "", null, missing value... but I can't figure it out. The reason I am trying to do this is to avoid making all sorts of combinations for what is basically the same subroutine. The knowledge I am getting from this will make me understand how to optimize my code on much more complex subroutines. Thanks for reading this far! |
|
|
|
|
|
#2 |
|
Site Admin
Join Date: Jan 2002
Location: Montreal
Posts: 31,938
|
AppleScript is not designed to be terse.
If you are trying to make your AppleScript as terse as possible, you are probably doing it wrong.
__________________
hayne.net/macosx.html |
|
|
|
|
|
#3 |
|
League Commissioner
Join Date: Sep 2003
Location: Tokyo
Posts: 6,044
|
you'll probably have to wrap each parameter in an "if the parameter is not empty..." bit.
But I can't determine what this routine is doing for you - all the action does is repackage the parameters nearly word-for-word. In this case i would just put the display dialog inline and customize as necessary. |
|
|
|
|
|
#4 |
|
Prospect
Join Date: Jul 2010
Posts: 7
|
acme.mail.order, I am just trying to use this as an example for learning. I have other programs that passing empty parameters for them in the method i am trying to figure out would make programming them much easier. Adding those "if..." statements would only make programming longer and complex, but I guess going through the long route is the only way to do it.
hayne, I guess you are right about that. I never encountered any script/tutorial that resembles what I am trying to do before, and now I know why. Applescript design limitation... |
|
|
|
|
|
#5 |
|
MVP
Join Date: Dec 2009
Location: Pembroke, Ontario
Posts: 2,051
|
It's not really an AS limitation. Basic functionality is implemented and it's up to you to use the classes you want for your purposes.
You could try: Code:
on doStuff(x,y,z) if x is missing value then -- x is nil and specific parts should be used end if if y is missing value then -- y is nil... etc end if actuallyDoSomething() end doStuff -- and now you can call it like this: doStuff(missing value, missing value, 3) |
|
|
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|