Showing posts with label Mac Operating System. Show all posts
Showing posts with label Mac Operating System. Show all posts

Sep 20, 2014

PATH variable

---------------------------------
Find the required location of the file, eg. java. Put the directory into the PATH variable.
touch ~/.bash_profile
open ~/.bash_profile

PATH=/opt/local/lib:/System/Library/Frameworks/Python.framework/Versions/2.5/bin:/opt/local/bin:/opt/local/sbin:/sw/bin:/sw/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/git/bin:/usr/texbin:/usr/X11/bin:/usr/X11R6/bin

source ~/.bash_profile


Python in OSX

Though OSX comes with a version of python, if another version is required here are some guidelines.


# I have used macport to install the desired version of python (eg., 2.7). This will be installed in the following directory.
cd /Library/Frameworks/Python.framework/Versions/
ls
2.7 Current

# Now move the installed version into the directory /System/Library/Frameworks/Python.framework/Versions/
where all other previously installed python version are.
sudo mv /Library/Frameworks/Python.framework/Versions/2.7 /System/Library/Frameworks/Python.framework/Versions/

# remove the older version of "Current" from /System/Library/Frameworks/Python.framework/Versions/

$ sudo chown -R root:wheel /System/Library/Frameworks/Python.framework/Versions/2.7
$ sudo rm /System/Library/Frameworks/Python.framework/Versions/Current

# create new symbolic link for the newly installed python version (eg, 2.7)
$ sudo ln -s /System/Library/Frameworks/Python.framework/Versions/2.7 /System/Library/Frameworks/Python.framework/Versions/Current

# remove the old python symbolic link
$ sudo rm /usr/bin/pydoc
$ sudo rm /usr/bin/python
$ sudo rm /usr/bin/pythonw
$ sudo rm /usr/bin/python-config 

# create the new symbolic links so that when you type on the terminal this is the desired python that would execute. This is because python
$ sudo ln -s /System/Library/Frameworks/Python.framework/Versions/2.7/bin/pydoc /usr/bin/pydoc
$ sudo ln -s /System/Library/Frameworks/Python.framework/Versions/2.7/bin/python /usr/bin/python
$ sudo ln -s /System/Library/Frameworks/Python.framework/Versions/2.7/bin/pythonw /usr/bin/pythonw
$ sudo ln -s /System/Library/Frameworks/Python.framework/Versions/2.7/bin/python-config /usr/bin/python-config

# update the ~/.bash_profile PATH variable to link the current python path
touch ~/.bash_profile
open ~/.bash_profile

PATH=/opt/local/lib:/System/Library/Frameworks/Python.framework/Versions/2.5/bin:/opt/local/bin:/opt/local/sbin:/sw/bin:/sw/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/git/bin:/usr/texbin:/usr/X11/bin:/usr/X11R6/bin

source ~/.bash_profile


Installed modules via macport successfully get installed into /opt/local/lib/python2.5/site-packages/
But when compiling a python script it doesn't find the path of the modules that are included using import statement such as 

import path
import json
import numpy
import Image

The following error message pops up "ImportError: No module named Image" or "ImportError: No module named simplejson".

Updating the PATH variables to point to the python version or macport installation path did not help. Explicit location of the installed modules needs to be shown to get rid of the error.

Add the path in the python code to show the path of the installed package. For example, to show the installed packages via macport find the path of the location of where the modules get installed:
$port content py25-numpy
It will show the /opt/local/lib/python2.5/site-packages/
Add the path using 
sys.path.append("/opt/local/lib/python2.5/site-packages/")

Similarly, for the downloaded package such as path, add the location of the downloaded copy using sys.path.append() method.
sys.path.append("~
/Desktop/seeing3d_renderer/seeing3d-master/pathpy/
)


One solution could be use the try-catch:
try:
    import json
except ImportError:
    import simplejson as json 


with open(access) as log_file:
Should be replaced with the following for the earlier python version such 2.5.
stream = None
log_file = None
try:
    stream = open(access, 'r')
    log_file = stream.readlines()
except IOError:
    print "Cannot find open the file", access

Jul 19, 2012

Profile in OSX

So turns out that on Mac OS X Snow Leopard as well as Mac OS X Lion, the file that's loaded is called .profile, not .bashrc. What you want to do is create a file in ~/.profile and call it .profile (if it doesn't already exists). Put whatever information you needed to load with each instance of bash there (Thanks, thepurplepixel).
A couple of side notes: The period in front of the file marks it as invisible to Finder and the ls command by default.
To list invisible files using the ls command from Terminal, use the -a as a parameter as such: ls -a The ~ symbol stands for /Users/YourUserName where YourUserName is your username's shortname.

Edit: Chris Page notes (correctly) that whatever you place in a .profile file will apply to whatever shell you're using (i.e. zhs, bash, et cetera). If you want the contents to affect only the bash shell, place the contents in a .bash_profile file instead of a .profile file.

Dec 20, 2011

Double sided disabled during printing in OSX

Whenever I add a new printer the double-sided option is generally disabled. It is not about installing the printer driver in OSX. Just let the system know that it should allow duplex printing. Change the settings from system preference. Here is the helpful instruction to enable the setting.
Reference: enabling-two-sided-duplex-printing-on-mac

May 15, 2011

While loop in bash

# remove the last line
function ProcessDistFile {

# Overwrite the file with nothing.
# echo -n > $1

# Write the lines in reverse order
let startFrom=$2-1
if [[ $startFrom -ge 0 ]]
then
while [ $startFrom -ge 0 ]
do
# echo ${lines[$j]} >> $1 # the array is accessible since global. Does not need to be passed
echo "Element is ${lines[$startFrom]}"
startFrom=$[$startFrom-1]
done
fi


}

While Loop Reference

Function call in bash

#!/bin/ksh
# Function manual reference
# Array manual reference
# the util funciton (reverse of cat FILE) tac FILE does not work in OSX. Use tail -r FILE instead
function ProcessStatFile {

# Overwrite the file with nothing.
echo -n > $1

# Write the lines in reverse order
for j in {9..0}
do
echo ${lines[$j]} # the array is accessible since global. Does not need to be passed
done

}


FILES=./*.txt
for f in $FILES
do
echo "Processing $f file..."

#store the lines in an array
old_IFS=$IFS
IFS=$'\n'
lines=($(tail -r $f)) # array
IFS=$old_IFS

# Select the particular file ending with _statFile.txt


# Overwrite the file with nothing.
ProcessStatFile $f # the file name parameter is passed. Accessed as $1.

done

Write on a file and use of Array in bash

#!/bin/ksh
# Array Reference
# Array reference 2
# Write on a file reference
# the util funciton (reverse of cat FILE) tac FILE does not work in OSX. Use tail -r FILE instead
FILES=./*.txt
for f in $FILES
do
echo "Processing $f file..."
# take action on each file. $f store current file name
#store the lines in an array
old_IFS=$IFS
IFS=$'\n'
lines=($(tail -r $f)) # array
IFS=$old_IFS

echo -n > $f # - n option writes without a new line. Here I write nothing on the file. Just overwrite the file with empty string.

for j in {9..0}
do
echo ${lines[$j]} >> $f # >> option appends on the file. > overwrites on the file.
done
done

If else bash in OSX

#!/bin/ksh
# If Else reference
FILES=./*.txt
for f in $FILES
do
echo "Processing $f file..."
# take action on each file. $f store current file name
let i=1
tail -r $f | while read line;
do
echo $line
let j=i+1
i=j
if [[ $j != 10 ]]
then echo "value of j $j"
fi

done

done

Read a text file in bash

#!/bin/ksh
# http://mandrivausers.org/index.php?/topic/21998-reading-a-text-file-line-by-line-with-bash/
FILES=./*.txt
for f in $FILES
do
echo "Processing $f file..."
# take action on each file. $f store current file name
while read LINE
do
echo $LINE
done < $f

done

Transfering text files in between a set of directories

#!/bin/ksh
# String manipulation
FILES=../Output/*
for f in $FILES
do
echo "Processing $f file..."
# take action on each file. $f store current file name
# string length
echo "length is ${#f}"
# substring of length 15 in variable f from the position 10. # g=${f:10:15}
# f contains file name in the format ../Output/ImmediateRecall10MinSet1_kuiper_OK
g=${f#*/} # delete the ../ from the begining
g=${g#*/} # Now delete the Ouput/ from the begining
g=${g%_*} # Now delete the _OK from the back
g=${g%_*} # Now delete the _kuiper from the back
echo "g is $g"
cp $f/*.txt $g/
done

May 13, 2011

Shell programming: Simple for loop to create folders

#!/bin/ksh
# http://www.softpanorama.org/Scripting/Shellorama/arithmetic_expressions.shtml
#let i=3

for i in {0..2}
do
for j in {0..9}
do
let m=i*10+j
echo "m is $m"
mkdir Hello$m
done
done

More resource here

May 9, 2011

Unix copy with regular expression

measlog0, measlog2, measlog3, measlog4, measlog5, measlog6, measlog7, measlog8, measlog9, measlog10, measlog11.

I'd like to copy these files to different directory, using "cp" command with some regular expressions:

1. cp measlog?? /tmp/testdir

2. cp measlog*[0-9] /tmp/testdir

3. cp measlog[0-90-9] /tmp/testdir

4. for fn in measlog*
do cp $fn /tmp/testdir
done

5. cp measlog[0-9] measlog[0-9][0-9] /somedir

echo cp measlog[0-9] measlog[0-9][0-9] /somedir

cp knows nothing about regular expresions (or more accurately, filename generation) so the echo will show you what cp will see.

Reference

Apr 29, 2011

Importing Bookmarks into "Opera"

Recently I am into the Opera Browser. I am liking it. Something happened to my Firefox browser. It just was not enabling the auto-suggestion, when I type in the names in the address bar. I tried suggested approaches (by doing a google) to solve this issue. It seems nothing was working for me. I am suspecting this misbehavior happened due to my sudden impulse for upgrading Firefox to its latest version(Version 4.0). Though it is good to enhance the browser to latest version, unfortunately it does not work on some bengali website that I accidentally visit (e.g., Sachalayatan et cetera). That led me to uninstall Version 4.0 and revert back into my older version.

I decided to import those saved bookmarks that I saved for a period of more than a year. Here are the steps I followed:
1. Go to the Bookmarks tab.
2. Select Manage Bookmarks.
3. Choose the File tab from several others(Add, Open, Properties, Delete, etc)
4. Pick Import from Firefox Bookmarks.(from the various others Import from Opera, Import from Safari etc)
5. Point it to the location of the bookmarks.html file that is saved in your computer. In Mac OSX,
it is stored in /Users/currentUser/Library/Application support/Profiles/xxxx.default/bookmarks.html
Alternately, I saved the bookmarks.html file in a known location by exporting it from the Firefox menus.

Helpful other hints.

Apr 25, 2011

Iomega: Portable USB Hard Drive

I got a 500GB Portable Iomega Hard Drive. Its skin resembles Macbook that blends well with my laptop when attached. Apart from slight glitch(when I dismounted the cable without giving a software command before), it is working well. $116 seems worth investing for backing up my data.

Mar 27, 2011

Opera as default browser in Mac OSX

Mac OS X

You can set Opera as your default browser on your Macintosh by doing the following:
Open Safari.
In the Safari menu, select Preferences > General.
Under "Default Web Browser", select Opera.

Note: On Mac OS X 10.2, you can also select a default browser using System Preferences > Internet > Web > Default Web Browser.

Mar 22, 2011

My machine performance

Md-Alimoor-Rezas-MacBook:~ alimurreza$ top

Processes: 50 total, 2 running, 48 sleeping, 230 threads 13:09:45
Load Avg: 0.19, 0.22, 0.24 CPU usage: 8.83% user, 5.58% sys, 85.58% idle
SharedLibs: 5504K resident, 4608K data, 0B linkedit.
MemRegions: 18163 total, 584M resident, 15M private, 254M shared.
PhysMem: 446M wired, 1121M active, 277M inactive, 1843M used, 203M free.
VM: 117G vsize, 1040M framework vsize, 161523(0) pageins, 10405(0) pageouts.
Networks: packets: 1507335/1442M in, 1138087/181M out.
Disks: 181528/3605M read, 106422/6801M written.

Tuning Mac OSX performance
Insufficient RAM
Freeing space
Running maintenance script

Game engines

Unity engine   Unreal engine Godot engine