Scripting     Basics    AppleScript     IrcII scripting
Version History

Snak Manual

Connecting to a server
Joining channels
Sending messages
Keeping track of people
Customization and settings
Using DCC
IRC commands


IrcII scripting

ircII (pronounced irk-two) is the second of the two scripting languages that Snak supports. The language is used in several irc clients with minor variations which means that there is a large body of existing scripts that can be adapted or used directly.

Scripts made in this language can be used side by side with scripts written in AppleScript. A small ircII script is frequently the fastest way to create simple command aliases. You can create an Action to run a command when a certain event happens. This command can use the full range of the ircII language.

Some very large and complex ircII scripts are available, but they can be hard to understand. It helps to have a programming background and be familiar with a language like C if you want to make complicated scripts in ircII or modify existing ircII script packages.

One of the largest and most powerful such packages is called PurePak and is included with Snak. PurePak can be a rich source for tips and inspiration once you have grasped the basics.

The ircII language is rich, expressive and complex. It has many intricacies and while simple aliases and commands are easily within the grasp of a beginner, large programs and script packages should be written in AppleScript unless you really want to learn the ircII language.

There are a number of web sites that contain scripts for the ircII client, and Snak is able to use most of those with only minor modifications.

The site contains scripts and also an extensive command reference and script guide that is highly recommended. Its location is:

It has chapters on the full syntax of the commands and the correct way to use them. Among the wealth of information in the guide is the full description of the various conditional operators like "if", branching commands like "while", and the full range of expressions that can be written in ircII. If you want to learn ircII scripting, the guide is highly recommended.

It's not possible to access data outside of Snak using the ircII language because it's processed entirely inside the application. AppleScript can be used to tie together multiple applications and access outside data because it's processed by the operating system in cooperation with the application.

Where to start

Snak comes with a number of script files from the regular distribution of ircII, and you are encouraged to open them in a text editor like BBEdit or SimpleText to see what you can do. Open the Scripts folder by choosing "Show Script Folder" in the windows menu. That will cause the Finder to display the folder where it is. Open the folder itself by doubleclicking it.

You will notice the useful /oops alias in the file called basical which uses an user defined variable.

In the file action you will find an example of the "if" statement. This example sets a string containing the possessive (his/her/the) depending on a gender variable.

That gender variable is defined in the file action, so if you are a woman, you may want to change the gender to "F" in order to get the correct possessive. For more elaborate examples, look in the script files that came with the program.

Example 1: The /J <channel> alias

A simple example is the /j alias. It's simply used as an abbreviation for the normal /join command. If you look in the script file basical you'll see that alias j is defined as /join. /join is a built in command and can be used on the input line with a parameter, and so can /j.

When you type /j, the program will replace the alias with its definition, which in this case is /join.

Example 2: The /op <nick> alias

A slightly more elaborate example is /op. In order to convey operator status on someone you normally have to type
/mode <channelname> +o <nick>

However the /op alias is defined as "/mode $C +o" and can be used to simplify this.

You can now convey op status by typing "/op <nick>". The alias makes use of a built-in scripting variable $C, and when the programs finds a variable in an alias the variable will be replaced by its value before executing the command.

Later in this chapter you will find a full list of the available variables and see what they represent, and $C contains the name of the current channel.

The <nick> part of the /mode command shown above is supplied by the <nick> parameter you typed after /op .

Example 3: The /oops <nick> alias

The alias /oops is is used to correct a message that went to, let's say John when it should have gone to Mary. The syntax is simply "/oops <intended nick>"

/oops is defined as

alias oops {
     ^assign alias.oops $B
     msg $. Sorry, that wasn't meant for you.
     msg $0 $alias.oops

Two new variables appear here : $B which always contain the text of your last message, and $. which is the last nick you messaged. The ^ character makes the assignment "silent", meaning no message is output when the line is processed.

The first line copies the text of the last message to an intermediate variable called "alias.oops".

The second line sends a message to the last nick we messaged (John) to say "Sorry, that wasn't meant for you"."

Third line resends the original text (stored in the intermediate variable) to the nick that was the first parameter to the alias (Mary)

In addition to variables like $C and $B there is also $0 ($zero) to $9 ($nine).

Numerical variables like that will be replaced by the corresponding argument from the input line. $0 will be replaced by the first argument, $1 will be replaced by the second argument and so on. If the message is "one two three four", $0 would be "one", $1 is "two" etc. The numeric variables can be combined in a number of ways.

Example 4: The consoleClick alias

The aliases can be run from the input field, and you can also run a particular script when you double click on a user in either the user list or the notify list. The default command for a double click in the notify list is "ConsoleClick". ConsoleClick is an alias, which is defined as "/msg $E $0-".

This looks cryptic, but remember that a /msg always takes two pieces of input : the nick and the message. When Snak interprets the alias it replaces $E with the currently selected nick, and $0- with the entire contents of the input line.

Scripting variables
  • Snak supports the numerical variables $0 thru $9. The numerical variables can be used individually or in ranges:
  • $n- gives argument n through the last argument.
  • $n-m gives arguments n through m.
  • $-m gives the first argument through m.
  • $* gives the entire contents of the input line. Same as $0-
  • $. Nick of the last person to whom you sent a message.
  • $, Nick of the last person who sent you a message.
  • $: Nick of the last person who joined the channel.
  • $; Nick of the last person who sent a message to the channel.
  • $? Brings up a dialog where you can enter text. Syntax is $?="explanation"
  • $B Text of the last message you sent.
  • $C The name of the channel.
  • $E Nick of the first selected user in the user list.
  • $F User and host information about the first selected user in the user list.
  • $I Name of the channel you were last invited to join.
  • $J The text of the last private message you received. Used in the Respond contextual menu item to pass the text into the query window.
  • $K The character (/) that is used to make the program process some input as a command.
  • $N Your nick.
  • $T Name of the current channel or query window.
  • $W The current selection in the userlist. The nicks are separated by space.
User defined script variables

In the file action you can see an example of the how to affect the execution of the alias depending on outside values. As mentioned before, scripting is really a form of programming, and a programming languages has conditional statements.

This example demonstrates the "if" statement which takes one of two branches depending on a test. The syntax for this statement is
IF (<variable-expression>) {<true-command/s>} [{<false-command/s>}]
and the example in the file is

     if (GENDER) {
          if ([$GENDER] == [F]) {
               assign POSSESSIVE her
          } {
               assign POSSESSIVE his
          assign POSSESSIVE the

This is actually two "if" statements inside each other. The outermost one test if the variable GENDER is defined at all. If not then it assigns "the" to the variable POSSESSIVE.

If GENDER is defined then the program runs the innermost "if" which tests its value, and assigns "her" to POSSESSIVE if it's "F". Otherwise POSSESSIVE will be set to "his"


Snak is Copyright © 1997-2006 Kent Sorensen. All Rights Reserved.
Logo design by energetics-design.