Showing posts with label OSX. Show all posts
Showing posts with label OSX. Show all posts

Sunday, February 11, 2018

OSX MAMP, Update PHP Version

Hello,

So recently I was working on Laravel Lumen framework where we need PHP 7.1.3 version. In my OSX XAMPP was using php version 7.1.1

So here in this blog I am going to explain step by step procedure.

Step 1: Go to MAMP website and download the new version of PHP. Go to following link

MAMP Downloads

On left side you will see column with title "Additional PHP versions"

There you will find list of PHP versions for OSX, download the one which you want and extract it. Copy it to

MAMP\bin\php folder.

For example if you download php version 7.1.3 then you will get folder with name

php7.1.3

Now you have to make two changes.

First edit path in your bash profile and update the existing path of PHP to newer version.


export PATH=/Applications/MAMP/bin/php/php7.1.3/bin:$PATH

After this quit the MAMP and restart it. It should work. No wait still it may not work for you.  As you go to MAMP preference screen, you will see that still it's using old version and new version is not displayed there.


That's because, by default free version of MAMP displays only last two folder here. So trick is to delete old folder or rename it and now your version of PHP will be displayed. Select it click on OK, restart MAMP and that's it now you get newer version of PHP. 

Hope this helps you.



Monday, May 29, 2017

Force Quit an App in Mac OSX from Terminal

Hello,

Recently I faced an issue with OpenOffice app on MAC. For some reason following open office window is displayed every time I open a document.


And then no matter what I do it does not go away. I tried force quit. Tried to close it from Activity monitor but it does not work. So then only option I had is to kill it with terminal. You can use this procedure to kill any unresponsive app in your OSX. 

First of all we have to find out process id of the unresponsive app. Since the app is unresponsive, it must be consuming lots of CPU resources. To find out this, open terminal and type following command.

top -o cpu

It will show following window. 


As you can see in first column we have PID and in second column we have app name. Find out PID from the name of unresponsive application and then type following command in terminal.

kill PID

 And it will kill unresponsive app. Hope this helps you.

Wednesday, May 24, 2017

How to exit the Vim editor?

Every time I use vi editor on terminal in OSX or Linux, I face issue on exiting Vim editor on terminal. So in this blog I am going to explain complete procedure on exiting vim editor on terminal in OSX or Linux.

What is Vim editor?

Vim is a highly configurable text editor built to make creating and changing any kind of text very efficient. It is included as "vi" with most UNIX systems and with Apple OS X.

How to Use Vim on Terminal?

Go to terminal and type following command

vi "NameOfFile"

and it will open Vim editor like this.



This is blank file. To start editing file press "I" key and then you can start editing file.

Now the tricky part is exiting vim editor on terminal. Here are exact procedure.

Hit the Esc key, vim goes into command mode.

Type Shift key + : and you will see : at bottom of the file.

Now you have to type command to tell editor what you want to do with the file. Here are some options you have.

q to quit
q! to quit without saving
wq to write and quit
wq! to write and quit even if file has only read permission
x to write and quit
qa to quit all
Now press "Return key" and it will exit vim editor.

Tuesday, March 7, 2017

Mac OSX Set Edit PATH Variable

If you are using MAC OSX for development for say android, Laravel, Sencha , Java, Composer then you must have faced this issue. There are SDKs for this development and it's installed some where in your disk and it has certain executable which you can use on command line. For example to create laravel application on your disk you can go to terminal and go to place where you want to create your application and type following command.

laravel new MyApp

But most of the time you get an error command not found. Same with the other development. So if you are using OSX and get command not found error on your terminal, that means you have to set PATH of that command to your PATH variable in OSX. In this blog I am going to mention how to do this.

$PATH variable is very similar to environment variable on windows. Once you add path of command to $PATH variable, you can execute that command from anywhere in terminal. If you want to see what is current values in your $PATH variable. You can go to terminal and type following command.

echo $PATH

and it will show you current values stored in your path. Easy and best way to set value in $PATH variable is through bash_profile file. On OSX each user will have bash_profile file that has this $PATH variables stored. Here you can append new PATH to your SDK to execute certain command. For that first of all open bash_profile file. Go to terminal and type following command.

nano ~/.bash_profile

It will open your bash_profile file. It will look something like this.



Here go to end of the file and add your new PATH here. For that first of you have to find out absolute path of command on your disk. For example in case of laravel. SDK is stored at path

/Users/hirendave/.composer/vendor/bin

Same way for your command and SDK you have to find out the exact path and add it $PATH variable. Go to end of the file and add path. For example for laravel.

export PATH=/Users/hirendave/.composer/vendor/bin:$PATH

Here we are just appending new value to existing values. To save this click

control + X

It will show below message.


Save modified buffer (ANSWERING "No" WILL DESTROY CHANGES) ?  

Type Y here and hit enter. It will confirm from you to save changes to .bash_profile file. Hit enter again and it will close the file and take you back to terminal. Now close all the terminal and launch it again and type the command it will surely work.

So for all the command you want to use on terminal, you can use this trick to save path in $PATH variable to that can be used from anywhere in terminal.

Friday, April 10, 2015

Cocoa OSX NSTextField Select All Text On Focus

Hello,

Recently I was working on MAC application where there was a requirement to select text inside NSTextField as soon as user focus it. In this blog I am going to explain how to do this.

First add a class to your project and name is CustomTextField. It will create two files CustomTextField.h and CustomTextField.m

Open CustomTextField.h file and add following code to it.

#import

@interface CustomTextField : NSTextField


@end

Now open CustomTextField.m file and add following code to it.

#import "CustomTextField.h"

@implementation CustomTextField

- (void)drawRect:(NSRect)dirtyRect {
    [super drawRect:dirtyRect];
    
    // Drawing code here.
}

- (BOOL)becomeFirstResponder
{
    BOOL result = [super becomeFirstResponder];
    if(result){
        [self performSelector:@selector(selectText:) withObject:self afterDelay:0];
    }
    return result;
}
@end

As you can see we have added event handler for becomeFirstResponder event. This event is fired as soon as user focus the text field. In that function we are selecting text by calling selector selectText with zero second delay. This will immediately select the text as soon as user focus on it. Now go to your Storyboard or xib file and select the TextField in which you want this behavior. 

Go to identity inspector and select the class CustomTextField for your textfield.

That's it.You can also do additional stuff like changing background color on focus.

[self setBackgroundColor:[NSColor clearColor]];
[self setBackgroundColor:[NSColor redColor]];

Hope this helps you. 

Saturday, February 1, 2014

Create Simple MAC OSX application with WebView and Load URL in it

Hello,

In this blog post we will see how to create a simple MAC OSX application with webview, which loads a URL in webview. This types of application are very useful when you have nicely designed web application and you want to convert it to MAC OSX app. Using this approach, you don't have to create separate OSX application. To create this application , you will need Xcode. Open the Xcode and select "Create New xCode project". Select OS X -> Application - > Cocoa Application. It will show following window.

Enter product name, Organization Name, Company Identifier, Class Prefix of your choice and click on Next. It will ask for the location to save the project. Select the location and create project. Once the project is created, you will see following type of file stricture in Xcode.

It may be different for in you based on entered class prefix by you. After this open AppDelegate.h file. Add following line after line #import <Cocoa/Cocoa.h>

#import <WebKit/WebKit.h>

After this add following line after @property (assign) IBOutlet NSWindow *window;

@property (assign) IBOutlet WebView *webView;

Once done open MainMenu.xib file. Select window as displayed in following image and add webview as show in the following image.


After that we have to add IBOutlet for that Select App delegate from the right pane and Control + Drag from it to Webview. It will show context menu with Webview. Select the webview and it will add IBOutlet. See the following image.


Now we have to load URL in Webview. Open your AppDelegate.m file and find the applicationDidFinishLaunching function and add following code to it.

NSRect frame=[NSScreen mainScreen].frame ;
[self.window setFrame:frame display:YES animate:YES];

Above lines will open the window in fullscreen mode. 

NSURL *url = [NSURL URLWithString:@"http://davehiren.blogspot.com"];
NSURLRequest *urlRequest = [NSURLRequest requestWithURL:url];
[[[self webView] mainFrame] loadRequest:urlRequest];
[self.window setContentView:self.webView];

Above lines will load the URL in webview. You can also set title of window with

[self.window setTitle:@"title"];

When you run the app you should see following screen.

That's it, your application is ready. You can change the URL the way you want.