October 2010

Recursive in C#

public partial class _Default : System.Web.UI.Page
{
List lst = new List();
int mainnode = 0;
protected void Page_Load(object sender, EventArgs e)
{
if(!Page.IsPostBack)
RadTreeView1.Nodes.Insert(0, new RadTreeNode(“Table of Content”));
}

protected void Button1_Click(object sender, EventArgs e)
{
updatemainnode();
lst.Add(“end”);

gv1.DataSource = lst;
gv1.DataBind();
}

public void updatemainnode()
{
for (int i = 0; i 0)
{
mainnode = i;
string str = i.ToString();
lst.Add(str);
updatesubnode(RadTreeView1.Nodes[i]);
ViewState[“BookIndex”] = null;
}
}
}

public void updatesubnode(RadTreeNode treenode)
{
if (ViewState[“BookIndex”] == null)
{
ViewState[“BookIndex”] = mainnode;
}

for (int i = 0; i 0)
{
ViewState[“BookIndex”] = strBookindex;
updatesubnode(treenode.Nodes[i]);
}
}
string strnew = ViewState[“BookIndex”].ToString();
if (strnew.Contains(“.”))
{
strnew = strnew.Remove(strnew.LastIndexOf(“.”));
ViewState[“BookIndex”] = strnew;
}
}
}

Mouse click event using Apple Script

set “Google” as Home page for test this application…

tell application “Safari”
activate
tell application “Safari”
run
tell application “System Events”
tell process “Safari”
click at {50, 100}
end tell
end tell
end tell
end tell

System tray menu in MAC OS x application

1. Open interface builder create NSMenu from Tools->Library. And create NSMenuItem “Active” and “Quit”.
2. “Active” select “Sent Action” -> “Window Server” and select “deminiature” action.
3. “Quit” select “Sent Action” -> “Application” and select “terminate” action.
4. “Menu” select “Outlet” ->ServerControll (applcation name control)
5. In “ServerController.h” file
IBOutlet NSMenu *menu;
NSStatusItem *statusItem;
NSImage *statusImage;
NSImage *statusHightlightImage;
6. In “ServerController.m” file
//Used to detect where our files are
NSBundle *bundle = [NSBundle mainBundle];
statusItem = [[[NSStatusBar systemStatusBar] statusItemWithLength:NSVariableStatusItemLength] retain];
[statusItem setEnabled:YES];
[statusItem setMenu:menu];
[statusItem setHighlightMode:YES];
[statusItem setToolTip:@”KB Keys”];
statusImage = [[NSImage alloc] initWithContentsOfFile:[bundle pathForResource:@”appicon” ofType:@”png”]];
[statusItem setImage:statusImage];
statusHightlightImage = [[NSImage alloc] initWithContentsOfFile:[bundle pathForResource:@”hoverappicon” ofType:@”png”]];
[statusItem setHighlightMode:YES];
[statusItem setAlternateImage:statusHightlightImage];

ESC handle by AppleScript

tell application “System Events”
tell application “TextEdit” to activate
tell application “TextEdit” to run
keystroke “s” using {command down}
key code 53
end tell

——————-

tell application “System Events”
tell application “TextEdit” to activate
tell application “TextEdit” to run
keystroke “s” using {command down}
key code 53 –esc
–key code 36 — enter
–key code 32 –space bar

end tell

–tell process “Microsoft Messenger”
–keystroke “omg testing lol”
–key down shift
–delay 0.2 — adjust delay as needed
–key code 36
–key up shift
–keystroke “testing line 2” & return

AppleScript in Cocoa Class

//message= TextEdit:f
NSString *string = message;
// split the text by the : to get an array containing { “AAA”, “BBB” }
NSArray *splitText = [string componentsSeparatedByString:@”:”];

// form a new string of the form “BBB AAA” by using the individual entries in the array
NSString *cellText = [NSString stringWithFormat:@”%@ %@”, [splitText objectAtIndex:1], [splitText objectAtIndex:0]];

NSString *cmdKey = [NSString stringWithFormat:@”%@”, [splitText objectAtIndex:1]];
NSString *app = [NSString stringWithFormat:@”%@”, [splitText objectAtIndex:0]];
//NSLog(cellText);
//NSLog(cmdKey);
//NSLog(app);

textView.string = message ;

//run and activate application
NSString *script = [ NSString stringWithFormat:@”tell application \”%@\” to run”,app];
NSAppleScript *run = [[NSAppleScript alloc] initWithSource:script ];
[run executeAndReturnError:nil];

NSString *script1 = [ NSString stringWithFormat:@”tell application \”%@\” to activate”,app];

NSAppleScript *run1 = [[NSAppleScript alloc] initWithSource:script1 ];
[run1 executeAndReturnError:nil];
NSString *cmd = [NSString stringWithFormat:@”tell application \”System Events\” to keystroke \”%@\” using command down”, cmdKey];
NSAppleScript *playScript;
playScript = [[NSAppleScript alloc] initWithSource:cmd];

if([playScript isCompiled] == NO){
[playScript compileAndReturnError:nil];
}

id exerror = [playScript executeAndReturnError:nil];

if(exerror == nil){
NSLog(@”Script Failed”);
}

NSLog(@”keystorke should be execute”);