I have been working on Android apps for a while and just released my first one! It allows you to remind yourself of movies that are upcoming.
Check it out at Android Market with the below QR code or head to the app website Movie Reminder.
I have been working on Android apps for a while and just released my first one! It allows you to remind yourself of movies that are upcoming.
Check it out at Android Market with the below QR code or head to the app website Movie Reminder.
Hi All,
Shift It version 1.1 has just been released. It has added an auto update feature and support for multiple monitors.
Check it out at Shift It [Google Code]
Hi everyone,
I have been working on this app for a while now. Shift it is an application that will allow you to manage your windows easily. The application can shift your focused window to a particular corner of the screen or fill the whole screen. All this is done using hotkeys. The application is open source,so you can download the source and have a go a it. The whole application was made using the previous posts. If you ever get stuck, please refer to the previous posts or leave comment here.
Please check out Shift It and Shift it – Hot Keys for more details.


As always, any suggestions are welcome.
Cheers,
Aravind
Tags: hot keys, Mac OS X, Shift it, window management
We are going to be using the LaunchServices/LSSharedFileList.h to modify the list of login items. This is only available in OS X 10.5 and above. To support systems less than 10.5, you would have to use Apple Events. This will not be covered in this post.
Methods
There are basically four methods we will have to use to add/remove a LoginItem. One will retrieve the list of LoginItems, the second will add a new item to that list, the third will remove an item from the list and that one is used to resolve the LoginItem with an URL.
The following method will retrieve the list of existing LoginItems
extern LSSharedFileListRef
LSSharedFileListCreate(
CFAllocatorRef inAllocator,
CFStringRef inListType,
CFTypeRef listOptions)
Parameters:
The second that we are going to look at will insert a new Login Item into the list, if it already does not exist. If it already exists, it will just move the item to the particular location in the list specified by the insertAfterThisItem parameter
extern LSSharedFileListItemRef
LSSharedFileListInsertItemURL(
LSSharedFileListRef inList,
LSSharedFileListItemRef insertAfterThisItem,
CFStringRef inDisplayName,
IconRef inIconRef,
CFURLRef inURL,
CFDictionaryRef inPropertiesToSet,
CFArrayRef inPropertiesToClear)
Parameters:
The other two parameters are not that important at this point of time and they can be NULL.
The third method will allow the application to be removed from the list of Login Items.
extern OSStatus
LSSharedFileListItemRemove(
LSSharedFileListRef inList,
LSSharedFileListItemRef inItem)
Parameters:
The last method is used to resolve the LoginItem with an URL when we are searching through the list of Login Items.
Implementation
For this example, I have created two methods. The first method will add your application to the login item and the second will remove the application from the list of Login Items.
-(void) addAppAsLoginItem{
NSString * appPath = [[NSBundle mainBundle] bundlePath];
// This will retrieve the path for the application
// For example, /Applications/test.app
CFURLRef url = (CFURLRef)[NSURL fileURLWithPath:appPath];
// Create a reference to the shared file list.
// We are adding it to the current user only.
// If we want to add it all users, use
// kLSSharedFileListGlobalLoginItems instead of
//kLSSharedFileListSessionLoginItems
LSSharedFileListRef loginItems = LSSharedFileListCreate(NULL,
kLSSharedFileListSessionLoginItems, NULL);
if (loginItems) {
//Insert an item to the list.
LSSharedFileListItemRef item = LSSharedFileListInsertItemURL(loginItems,
kLSSharedFileListItemLast, NULL, NULL,
url, NULL, NULL);
if (item){
CFRelease(item);
}
}
CFRelease(loginItems);
}
-(void) deleteAppFromLoginItem{
NSString * appPath = [[NSBundle mainBundle] bundlePath];
// This will retrieve the path for the application
// For example, /Applications/test.app
CFURLRef url = (CFURLRef)[NSURL fileURLWithPath:appPath];
// Create a reference to the shared file list.
LSSharedFileListRef loginItems = LSSharedFileListCreate(NULL,
kLSSharedFileListSessionLoginItems, NULL);
if (loginItems) {
UInt32 seedValue;
//Retrieve the list of Login Items and cast them to
// a NSArray so that it will be easier to iterate.
NSArray *loginItemsArray = (NSArray *)LSSharedFileListCopySnapshot(loginItems, &seedValue);
int i = 0;
for(i ; i< [loginItemsArray count]; i++){
LSSharedFileListItemRef itemRef = (LSSharedFileListItemRef)[loginItemsArray
objectAtIndex:i];
//Resolve the item with URL
if (LSSharedFileListItemResolve(itemRef, 0, (CFURLRef*) &url, NULL) == noErr) {
NSString * urlPath = [(NSURL*)url path];
if ([urlPath compare:appPath] == NSOrderedSame){
LSSharedFileListItemRemove(loginItems,itemRef);
}
}
}
[loginItemsArray release];
}
}
That is it. You can basically have a preference that asks the user whether he wants the app to open at login. Depending on the answer, you can invoke one of the method.
Good Luck.
Tags: Cocoa, Login Item, LSSharedFileList.h, LSSharedFileListCreate, LSSharedFileListInsertItemURL, LSSharedFileListItemResolve, Mac OS X, Startup Item
Jan 31
Posted by aravind88 in Carbon, Mac OS X | No Comments
Implementation
First, we will look at how to retrieve the window’s properties. In this example, we will look at how to retrieve the window’s position and size. To make it easier to modify these properties, we create a few variables to temporarily store the properties.
AXUIElementRef _systemWideElement;
AXUIElementRef _focusedApp;
CFTypeRef _focusedWindow;
CFTypeRef _position;
CFTypeRef _size;
I have assumed that you have already initialized the _systemWideElement. If not, you can use the following line to do so.
_systemWideElement = AXUIElementCreateSystemWide();
Then, we are going to use this AXUiElement to first retrieve the app that focus. Then we will retrieve the window that has focus. After which, we can get its properties by using the following method:
extern AXError AXUIElementCopyAttributeValue (
AXUIElementRef element,
CFStringRef attribute,
CFTypeRef *value);
Parameters:
Lets look at how this method can be used.
//Get the app that has the focus
AXUIElementCopyAttributeValue(_systemWideElement,
(CFStringRef)kAXFocusedApplicationAttribute,
(CFTypeRef*)&_focusedApp);
//Get the window that has the focus
if(AXUIElementCopyAttributeValue((AXUIElementRef)_focusedApp,
(CFStringRef)NSAccessibilityFocusedWindowAttribute,
(CFTypeRef*)&_focusedWindow) == kAXErrorSuccess) {
if(CFGetTypeID(_focusedWindow) == AXUIElementGetTypeID()) {
//Get the Window's Current Position
if(AXUIElementCopyAttributeValue((AXUIElementRef)_focusedWindow,
(CFStringRef)NSAccessibilityPositionAttribute,
(CFTypeRef*)&_position) != kAXErrorSuccess) {
NSLog(@"Can't Retrieve Window Position");
}
//Get the Window's Current Size
if(AXUIElementCopyAttributeValue((AXUIElementRef)_focusedWindow,
(CFStringRef)NSAccessibilitySizeAttribute,
(CFTypeRef*)&_size) != kAXErrorSuccess) {
NSLog(@"Can't Retrieve Window Size");
}
}
}else {
NSLog(@"Problem with App");
}
Now that we have retrieved the position and size of the window, we will look at how to modify these properties. In the following example, we are trying to move the window to the (0,0) coordinate and fill left half of the screen. To set a property, we will use the following method,
extern AXError AXUIElementSetAttributeValue (
AXUIElementRef element,
CFStringRef attribute,
CFTypeRef value);
The parameters are the same as the AXUIElementCopyAttributeValue method.
NSPoint thePoint;
thePoint.x = 0;
thePoint.y = 0;
//convert the NSPoint to CFTypeRef
_position = (CFTypeRef)(AXValueCreate(kAXValueCGPointType, (const void *)&thePoint));
if(AXUIElementSetAttributeValue((AXUIElementRef)_focusedWindow,
(CFStringRef)NSAccessibilityPositionAttribute,
(CFTypeRef*)_position) != kAXErrorSuccess){
NSLog(@"Position cannot be changed");
}
NSSize theSize;
NSSize _fullScreenSize = [[[NSScreen mainScreen] frame] size];
if(AXValueGetType(_size) == kAXValueCGSizeType) {
theSize.width = ((_fullScreenSize.width)/2);
theSize.height = _fullScreenSize.height;
// convert from NSSize to CFTypeRef
_size = (CFTypeRef)(AXValueCreate(kAXValueCGSizeType, (const void *)&theSize));
}
if(AXUIElementSetAttributeValue((AXUIElementRef)_focusedWindow,
(CFStringRef)NSAccessibilitySizeAttribute,
(CFTypeRef*)_size) != kAXErrorSuccess){
NSLog(@"Size cannot be modified");
}
There we go! That should do it.
Tags: AXUIElementCopyAttributeValue, AXUIElementSetAttributeValue, Carbon, CFTypeRef, Mac OS X, NSAccessibility, NSAccessibilityPositionAttribute, NSAccessibilitySizeAttribute, window
Since all the preferences are stored in file with a .prefPane extension, all we basically have to do it is
//opening the Universal Access Preference Pane.
[[NSWorkspace sharedWorkspace] openFile:@"/System/Library/PreferencePanes/UniversalAccessPref.prefPane"];
The list of Preference Pane are the .prefPane files in the folder /System/Library/PreferencePanes/. Adding on to the previous post, we would open the Preferences if the Accessibility API is not enabled.
if(!AXAPIEnabled()){
[[NSWorkspace sharedWorkspace] openFile:@"/System/Library/PreferencePanes/UniversalAccessPref.prefPane"];
[NSApp terminate:self];
}
AXUIElementRef _systemWideElement;
AXUIElementRef _focusedApp;
CFTypeRef _focusedWindow;
_systemWideElement = AXUIElementCreateSystemWide();
AXUIElementCopyAttributeValue(_systemWideElement,
(CFStringRef)kAXFocusedApplicationAttribute,(CFTypeRef*)&_focusedApp);
AXUIElementCopyAttributeValue((AXUIElementRef)_focusedApp,
(CFStringRef)NSAccessibilityFocusedWindowAttribute,(CFTypeRef*)&_focusedWindow)
Tags: Cocoa, prefPane, System Preferences
Jan 30
Posted by aravind88 in Carbon, Cocoa, Mac OS X | No Comments
Firstly, we need to check if the preference has been set. To do this we have to use one of the Accessibility APIs.
Boolean AXAPIEnabled (void);
This method returns true if the access for assistive devices have been enabled. False, otherwise. If access has not been enabled, we will inform the user to enable it and quit the app(for now. Next post we will look at how to open the preference pane).
Secondly, we need to create a system wide element that can listen to focused accessibility object regardless of which application is currently active.
AXUIElementRef AXUIElementCreateSystemWide (void);
We have to use this element to retrieve information about the focused application and then focused window. We cannot get the focused window directly. Therefore, we have to first get the application that is in focus and the get the window that is in focus. Note: We can only get copies of the above mentioned information. To do this, we have to use the following method.
AXError AXUIElementCopyAttributeValue (
AXUIElementRef element,
CFStringRef attribute,
CFTypeRef *value);
The allowed attributes can be found here. ‘Value’ refers to the value associated with the specified attribute. Thats it folks. Now we can look at the actual implementation.
Implementation
AXUIElementRef _systemWideElement;
if(!AXAPIEnabled()){
//exit
}
AXUIElementRef _focusedApp;
CFTypeRef _focusedWindow;
_systemWideElement = AXUIElementCreateSystemWide();
AXUIElementCopyAttributeValue(_systemWideElement,
(CFStringRef)kAXFocusedApplicationAttribute,(CFTypeRef*)&_focusedApp);
AXUIElementCopyAttributeValue((AXUIElementRef)_focusedApp,
(CFStringRef)NSAccessibilityFocusedWindowAttribute,(CFTypeRef*)&_focusedWindow)
That is all for now! Good luck. Comments are welcome.
Tags: Accessibility, AXUIElementCreateSystemWide, Carbon, Focused Window, Mac OS X, prefPane, System wide element, UiElement
What are HotKeys?
HotKeys are combinations of key presses that user uses to take advantage of a feature. For example, the Spotlight in Mac OS X has a default HotKey of Cmd+Space. Similarly, different applications use different HotKeys to simply the usage of the application.
Methods Required
OSStatus MyHotKeyHandler(EventHandlerCallRef nextHandler,EventRef theEvent,void *userData);
The above method is the one you would have to implement to handle the hot keys. The function name is not a issue, you can be creative with it.
InstallApplicationEventHandler( handler, numTypes, list, userData, outHandlerRef );
The above method will install the event handler with the OS. When the user presses the appropriate keys, the OS will invoke the handler with the userData and the EventRef.
extern OSStatus RegisterEventHotKey(
UInt32 inHotKeyCode,
UInt32 inHotKeyModifiers,
EventHotKeyID inHotKeyID,
EventTargetRef inTarget,
OptionBits inOptions,
EventHotKeyRef * outRef);
This is the method that actually registers for the HotKeys. The points below will give you some idea of how to use this method.
Implementation
First we are going to implement the method that handles the HotKey events.
OSStatus MyHotKeyHander(EventHandlerCallRef nextHandler,EventRef theEvent,void *userData){
//Do something once the key is pressed
EventHotKeyID hotKeyID;
GetEventParameter(theEvent,kEventParamDirectObject,typeEventHotKeyID,
NULL,sizeof(hotKeyID),NULL,&hotKeyID);
int temphotKeyId = hotKeyID.id; //Get the id, so we can know which HotKey we are handling.
switch(temphotKeyId){
//Now you know which HotKey. Do something...
}
}
Then we are going to install a ApplicationEventHandler.
EventTypeSpec _eventType;
_eventType.eventClass = kEventClassKeyboard;
_eventType.eventKind = kEventHotKeyPressed;
InstallApplicationEventHandler(&MyHotKeyHander,1,_eventType,self,NULL);
//Here i am returning 'self' as the user data. So when the MyHotKeyHandler
// is called, it will contain self as the data. You can
// declare any object you want and that will end up as the userData in
// MyHotKeyHandler.
Now the final step to register the HotKeys.
OSStatus error;
EventHotKeyID hotKeyID;
EventHotKeyRef hotKeyRef;
hotKeyID.signature='hk';
hotKeyID.id = 1;
error = RegisterEventHotKey(cmdKey+optionKey, 123 , hotKeyID,
GetEventDispatcherTarget(), 0, &hotKeyRef);
// cmd+option+(left arrow)
if(error){
//handle error
}
If you want to unregister the HotKey, all you would have to do is call the UnregisterEventHotKey method with the EventHotKeyRef.
OSStatus error;
EventHotKeyRef hotKeyRef = // The HotKeyRef for the HotKey you want to unregister;
error = UnregisterEventHotKey(hotKeyRef);
if(error){
//handle error
}
Thats it folks! Good luck! Comments are always welcome.
Tags: Carbon, Eventhotkeyref, HotKey, Mac OS X
What is a Menu Bar Extra?
They are extra menus that are visible at the right side of the menu bar. Some of the in-built menu extras are the battery indicator, time indicator. Menu bar extras are typically used to display application/system status information. Two things to note about the Menu bar extras are that
Some websites call this kind of application a menulet application or a status bar application.
Implementation
To start off, we create a new Project in Xcode.
Open Xcode. File->New Project. Choose the “Cocoa Application” and click “Choose”. Next, Xcode should ask you to give a name for the project. Pick a name and directory for the project. In this example, the project name will be “StatusMenuApp”. Once you have chosen a project name and location, click “Save”.
Xcode should have created a new project with some default files. The two folders “Classes” and “Resources” are the most important folders for this walk-through. You can ignore the remaining folders for this example.
First, we will add an NSMenu outlet in the In the StatusMenuAppAppDelegate.h to which the menus can be referenced to. Also we will add a NSStatusItem that will eventually become the status bar menu item.
@interface StatusMenuAppAppDelegate : NSObject {
NSWindow *window;
IBOutlet NSMenu *statusMenu;
NSStatusItem * statusItem;
}
@property (assign) IBOutlet NSWindow *window;
@end
We will now create the MenuItems that will be available in the application. To do this, we open the MainMenu.xib in the Interface Builder. For this example, we will not touch the existing Menu in nib. Drag and drop another “Menu” object from the Library into the Document window. Give each of the MenuItem a unique title. Now we have to link the Menu object to the statusMenu outlet. To do this, CTRL+click on the StatusMenuAppDelegate object and drag and release the pointer on the Menu object. This should open up a panel titled “Outlets”. This panel will show all the Outlets available in the StatusMenuAppDelegate class. In our example, there is only one outlet. Click on the ’statusMenu’ to link the Menu object to statusMenu. Finally, delete the Window object. Save the nib file and close Interface Builder.
Now we move on to actually creating the Status Bar Menu. In the “StatusMenuAppDelegate.m”, we override the function awakeFromNib. A awakeFromNibmessage is sent to every object that is loaded from a Nib(.nib or .xib) file. Firstly, we will create the NSStatusItem. To do so, we have to call
- (NSStatusItem *)statusItemWithLength:(CGFloat)length
The parameter length can take the following two values:
For this example, we will use the NSVariableStatusItemLength.
statusItem = [[[NSStatusBar systemStatusBar] statusItemWithLength:NSVariableStatusItemLength] retain];
Secondly, we have to add the statusMenu to the statusItem. To do so, we all the following code:
[statusItem setMenu:statusMenu];
Thirdly, we give a title for the statusItem. This will be seen in the Menu Extras.
[statusItem setTitle:@"Status"];
If you would like to see an image instead of text, you can use the following methods:
- (void)setImage:(NSImage *)image
-(void)setAlternateImage:(NSImage *)image
Lastly, we want to highlight the menu when the user clicks on it. So we use the following code.
[statusItem setHighlightMode:YES];
By default, the highlight mode will be set to NO.
The StatusMenuAppDelegate.m file should look like this now.
#import "StatusMenuAppDelegate.h"
@implementation StatusMenuAppDelegate
@synthesize window;
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
// Insert code here to initialize your application
}
-(void)awakeFromNib{
statusItem = [[[NSStatusBar systemStatusBar] statusItemWithLength:NSVariableStatusItemLength] retain];
[statusItem setMenu:statusMenu];
[statusItem setTitle:@"Status"];
[statusItem setHighlightMode:YES];
}
@end
Since we want the app to only appear on the status menu, the last step is the most important one.We need to modify the StatusMenu-Info.plist file. Double click to open this file. Add a new property with key “Application is agent (UIElement)” and value as TRUE(i.e. check the box). Your .plist should look like this.
Final output of the program should look like this:
Tags: Cocoa, Mac OS X, Menulet, NSMenuExtra, Status Bar
Hi All,
There was a database corruption. I will re-post everything in the next few days
Arclite theme by digitalnature | powered by WordPress