FileMaker: Passing Multiple Script Parameters

This is going to be a post laying the foundation for more to come.

In FileMaker there is no native way to send multiple script parameter. All you have is a single line that you can type whatever you want into.That works well enough when you want to pass a single parameter but what if you want to pass multiple parameter to the script?

Different Methods

Word Count

Rather than just entering a single word in the script parameter box you can enter a string of words, kind of like a nonsensical sentence. You can then use the LeftWords(), RightWords(), and MiddleWords() functions to parse out any individual word (parameter) from the entire string.

There is 1 major downside to using a word count system and that is that the number of words for each parameter must be constant for every use case. For example, let's say that I need to pass a name pulled from a field as a parameter. If I design the script to be expecting a first name and a last name, what happens when the name passed has a first, last, and middle name? The middle name is another word which will throw off the word count being used. Or, what happens if one of those parameters is NULL and has no words to be counted.

Value Count

The value count method uses the same principle as the word count method but rather than counting words you are counting carriage returned values. The list of values can be constructed using the List() function or be separating the values in the string with a pilcrow ("¶"). Values can then be retrieved using the GetValue() function.

This solves the major problem with the word count method in that each value can contain as many or as few words as necessary. You are counting values and not words so multiple word parameters are fine as are NULL parameters. That is not to say that the value count is without problems. If you are pulling data directly from field in your database there is always the chance that a user has accidentally added a carriage return to the end of field. This carriage return in the data would be evaluated as an additional parameter by the calc engine.

Another problem, and my big concern, is that you need to remember what value number corresponds to which parameter for which script. You need to recall that, script A is looking for the Primary Key as the 1st value while the Last Name is the 4th value. Script D, however, may only need 2 parameter so the Primary Key is 1st and the Last Name is 2nd.

Delimiting Characters

You could pass multiple parameters by using some rare or unique character as a delimiter between them. In the past I have used the pipe ("|"), the carrot ("^"), the backslash ("\"), and even greek symbols ("∂" and "Ω"). I then used a combination of the Position() and Middle() functions to extract the required text.

This solves the multiple word problem and the extra carriage return problem but it doesn't solve the "which value number is which parameter" problem. Also, there is always a chance that a user may, accidentally or otherwise, use your delimiter symbol in actual text.

Dictionary

The final, and my preferred, method is to use a dictionary to create a set of name/value pairs. This is a much more complex but much more robust way to do things.

Name/Value pairs are a method in which a value is paired with name that describes or identifies that value, thus Name/Value pairs. The syntax that is used to make the pairing is usually referred to as a dictionary because you have to create a syntax, or language, to encode and decode the data. The dictionary that you use is completely up to you as a developer. You can use steal one from someone else or create one on your own.

The most common example of name/value pairs is XML. In XML if you wanted to pass a room location as a parameter it may look like this:

<room>Indigo Ballroom B</room>

In this example the data, or value, that we are passing in "Indigo Ballroom B" and we have given it the arbitrary name of "room". We could have multiple parameter encoded in a similar way and as long as the name for each is unique it is easy to extract any parameter.

This solves all of the problems from the previous methods. It doesn't matter how many words are in each paramter or if the word count varies. It doesn't matter if there are extraneous carriage returns in the data. It also doesn't matter what order you pass the parameters in as long as you know what name you used to pass the value.

The dictionary that I use came directly from Six.Fried.Rice's Jesse Antunes and can be found here:

http://sixfriedrice.com/wp/passing-multiple-parameters-to-scripts-advanced/

Using the example from above, the parameter looks like this once it is passed "<:room:=Indigo Ballroom B:>". You have closing and opening character strings ("<:" and ":>") and a simple character string separating the name from the value (":="). The custom functions that Jesse provides also take care of escaping any characters that could cause trouble (for example, if your data contained colons, equal signs, etc.).

When you want to pass a parameter you use the custom function PassParameter(), i.e. PassParameter( "room" ; "Indigo Ballroom B" )

There are only 2 potential concerns with using this method. First, you have to have FileMaker Pro Advanced so that you can make the custom functions. Second, it is a bit more to type to encode the parameters but I gladly make that sacrifice for the ease of extraction.

When I want to extract a parameter all I have to do is use the GetParameter() function, i.e. GetParameter( "room" ). It doesn't matter how many words are in the room, how many carriage returns the room has in it, or where that room is located in all of Get( ScriptParameter ). It will find it, extract it, and decode it back to what it was when it was passed.

Use Cases

The next stop is showing how you can use the dictionary method to do more than just script parameters.

Relaunch...?

OK, seeing as how it's been 4 years since I wrote anything on here, I'm going to attempt to relaunch this thing. In order to do that I need to figure out 2 things: what do I want it to be and why did I stop in the 1st place?

Why did I stop? I would like to say that I stopped updating it because I was jusst so damn busy having so much fun and that there was no place in the new world for the blog. But that's not the case at all. Mostly at all has to do with laziness. I just got too lazy to update. And then after the laziness came the guilt, "I haven't updated in months, so when I do finally update I need to have something major to say, not just some stupid crap." And then after a while I just stopped thinking about it. That is why it's been 4 years since I've written anything.

What do I want this to be? That's always been a difficult question for me. Part of the impetus behinf this is professional ambition. I want to get my name out there and share some things that I've been working on professionally. The problem is that I've believe in keeping personal and professional things seperate. I feel that if I start a professional blog it shouldn't have anything about my personal life on it (why would you care about my vacations, etc.). Nor should a personal blog have long geeky posts about what I'm doing in FileMaker (no one in my personal community cares about the latest tricks for data representation).

So what does this all mean? What I'm going to try to do is this: I'm going to keep this blog professional and I'll leave the personal stuff to Twitter and Tumblr. That's not to say that there will never be anything up here that might blur in from the personal space, just that its primary focus is professional.

How am I going to accomplish this? I'm hoping that I can post somehitn up here once a week, for now. I have a lot of things that I want to talk about and tips and trick that I want to share but I don't want to go blog crazy and post 6 or 7 articles in the next 3 or 4 days and then have nothing to put up for a while. I'm hoping that pacing myself will help me get into the habit of writing. I'm also hoping that the iPad will help me with the writing. Having a tool with me all the time that I can use to write posts (or at least start to write posts) is something that I think will fit into my workflow much better. Finally, Im hoping that peer pressure will be a good thing here. I've got a set of Moo Cards made up with this URL on them that I will be handing out. I'm hoping that knowing that this site is actually being (somewhat) promoted will keep the pressure on.

That's it for now. Here we go again!

Mac Apps: Quicksilver

I've decided to start a list of my favorite Macintosh applications, more specifically applications that don't come with the computer. I know that there are LOTS of lists that you can find out there that do the same thing and I'm not about to claim that my list is better or more complete. I'm doing this mostly for my own posterity.


My first app, and definitely one of the most important, is Quicksilver. Quicksilver is a fantastic application that works kind of like Spotlight, kind of like Finder, kind of like Automator and kind of like a mouse.


Quicksilver is an application that runs (mostly in the background) waiting for you to hit a user defined hotkey. Hit the specific hotkey, the default is Ctrl + Space, and the application window pops up (see left).


The interface is broken up into two main parts. The left pane is often thought of as the object or noun pane. Just start typing the name of any application or folder on your computer and quicksilver instantly searches its massive index and lists everything that closely matches what you typed. If the top hit on the list isn't what you wanted all you have to do is arrow through the popup list to the one you want then tab to the next pane.


The second pane is the action or verb pane. Here you can select any action that you want to perform on the object from the first pane. The default action is usually "Open" since that is often what you will want to do with files, folders, and applications.


Just using Quicksilver like that, it becomes an alternative to the Finder and the Dock. Have an application that you use a lot, but not several times a day? Rather than put it in the dock, just let Quicksilver launch it. But Quicksilver is capable of so much more.


Need to e-mail someone in your address book a file. With Quicksilver you can select the file (or files, using the "Comma Trick"), zip them together, create an e-mail, attach the files to the e-mail, enter the recipient, and send the e-mail. You can do all of that without touching Finder or Mail.


One of my personal favorite uses for Quicksilver has to do with Twitter. I can write a tweet in Quicksilver and then select an Applescript called "Tweet" which will take what I've written and post it on Twitter.


There are lots of other places out there where you can learn more about Quicksilver. Merlin Mann is a Quicksilver guru who can do just about anything with the application. If you want to learn more check out the links below.


http://docs.blacktree.com/quicksilver/what_is_quicksilver
http://vjarmy.com/archives/2004/03/quicksilver_a_b.php
http://theappleblog.com/2006/02/14/quicksilver-tutorials-round-up/


Jaiku

I credit Leo Laporte with introducing me to Twitter. It was Leo, Alex Lindsay, and Merlin Mann that showed me that there was something more to Twitter than it just being a "silly little thing" that I thought it was at first.


But, now Leo has left Twitter due to trademark concerns. He has started up a Jaiku account and is now singing its praises. I got myself a Jaiku account and looked around it for a while. I don't like it. Actually, I really don't like it. They have a lot more features, which is kinda cool. They tried to keep the interface simple like Twitter had done but with all of the features they added the interface just ends up REALLY confusing. Plus half of those features go too far and make Jaiku into something more like a Tumblelog which is far more than I want or need. The main reason that I love Twitter is that it does one thing really well, not a dozen things half-assed.


So, in conclusion, I'm sticking with Twitter. Leo, I understand that you need to defend your trademark but you didn't need to leave Twitter to do that.


Stupid Qumana

So I did have a post that I was writing in Qumana. It was a pretty decent sized post, longer than most of the other stuff I usually post. But, then Qumana decided to freeze on me and, since there is no autosave feature, I lost it all. I've lost total interest in recreating that post right now so it's going to have to wait until later.


Let the Twittering Begin

So it's finally happened, I've gotten a Twitter account. If you don't know what Twitter is, go here. Then, following the same logic from my last post (that I won't use things if I have to go out and log into a webpage to use them) I've integrated Twitter into Quicksilver. Now I can post to Twitter using 5 keyboard keys (minus the message itself) which is sooo sweet (thank you Leo).


I've also set up an integration between Twitter and my Wordpress blog. This means that my blog will auto-create a daily digest of all of my tweets throughout that day. You'll get to see all of my testing tweets from when I was setting up the Quicksilver integration.


I can already tell that Twitter will be the end of me... and by the end of me I mean that it's going to suck up a lot of my time. I think that "micro blogging" is the perfect blogging for me.


Also, this is my test post for Qumana. Thoughts? (like anyone actually reads this... HA!)


EDIT: I've removed the link between my blog and Twitter. I'm going to try and keep things compartmentalized for now. You can still read my tweets at http://twitter.com/merlyn383.

10.4.9

I don't often badmouth apple, but damn! The 10.4.9 update was atrocious. I ran the update from software update and did the requisite restart without problem. Then, during boot, my MBP hung on the loading screen for like 10 minutes causing me to do a hard restart. Then everyhting booted up just fine and seemed to be working, until I opened Mail.

I got the "Your application has been updated, do you want to allow the application to access the keychain files from the old application" mesage which I told to "Allow". Then the real fun started. The window went grey and did it's thing updating whatever needed to be updated for the next 3 minutes. While it was being updated my computer strained to even open up a finder window. Then the window disappeared and I thoguht all was well, only to be greated by the same window again where I clicked "Allow" again and the whole process repeated itself. Then it all happened again.

As if to add insult to injury, my computer picked that moment to auto-sync with .Mac rendering my computer utterly useless for the next 20 minutes as I was assaulted by 4 more keychain windows and the occasional Little Snitch message. So, I waited semi-patiently for my computer to finish all of its business so that I could use it again. As soon as it was done I went to Apple's support page and downloaded the 10.4.9 combo updater.

I figured that since the update seemed to screw my computer up, perhaps it was a bad install. I downloaded and reran the update and did the restart. It booted back to the login screen without error this time (which I considered a good sign) and seemed to be working like it's old self again. I launched Mail and the same windows appeared but they disappeared as soon as I clicked "Allow". I decided to push my luck and did a manual sync, and that's when things started to suck again. Opening up Activity Monitor, I noticed that a process called "securityd" had decided that it required over a gig of real ram and almost 2 gig of virtual memory. A quick google search for securityd brought me to this article at Merlin Mann's 43folders.com (a great website run by a fantastic techie). One terminal command later followed by ANOTHER restart and everything works fine now.

The good news is that everything seemed to install fine on my PowerMac G5 and my Mac Mini but damn was my MacBook Pro a bitch. I can't wait to go to work today and see how busy the genius bar is with people who are having issues with their updates.

I'm Back

OK, so I started a blog and then jsut let it flounder for a few days. But, here we go again. One of the reasons that I haven't posted in forever is that everytime I considered doing it I would think of all the things that had happened that I flet that I "needed" to talk about, and then all of that updating, writing, and apologizing for not writing turned me off of the idea. So, therefore, I've made the decision not to go back and talk about everything that has happened in the last month and rather I am just going to look forward and be more diligent about updating as stuff happens.

Hello World

OK, I'm going to try blogging one more time, and this time it hopefully sticks. Part of the reason that I'm changing my bloging app is that I want to be able to but tags on my posts, or as they are refered to in WordPress, catagories. So, I went for the cheap route and got a WordPress blog. Eventually I'm hopig to upgrade it to a MovableType blog, but that requires me to get a bit too geeky. Anyway, that's all for now.