Archive for the ‘Mac OS X’ Category

How To Import Non-Commercial DVDs Into iMovie ‘08

Tuesday, December 18th, 2007

Hopefully this hasn’t already been discussed; I searched all over the web and couldn’t find a good answer, so I figured it out myself and thought I’d spread the word!

So I had a couple of DVDs of wedding footage shot by my wife’s great uncle, and I wanted to edit the footage in iMovie 08. First I tried Handbrake to create a M4V file, but no dice, iMovie wouldn’t read that format. Then I figured out this method: (more…)

Mac Tiger 10.5 Apple Registration Screen Loop Stuck

Sunday, December 16th, 2007

1. Turn off your Mac. Perhaps hold the power button down until it turns off.
2. Hold the SHIFT key down and startup. Be patient as it may take awhile.
3. DO NOT LOGIN yet. Click the back arrow (Restart).
4. Your computer should start installing the hazardous upgrades.
5. Allow your computer plenty of time to install and auto-restart.
6. You should be able to login and access all of the files you through were destroyed. (more…)

Getting PHP 5.2.x To Run on Mac Tiger 10.5

Sunday, December 16th, 2007

So, you decided to upgrade to Mac Tiger Workstation and your PHP service stopped working. No fear, as PHP will still work fine once you make a simple change to your Apache 2 configuration file. Previous versions of Mac OS 10.4 and below were using Apache 1 series, not Apache 2 series. You need only un-comment a single line in the Apache httpd.conf file. Knowing where it is and how to modify it is not something most developers bother with. Assuming you have the permissions to make the needed change, your PHP service will be up in mere moments. (more…)

UNIX Intro to Single-user mode

Sunday, March 18th, 2007

To get to single-user mode, hold down the command (i.e. cloverleaf or Apple)
and “s” keys as the system begins to boot. This will drop you into a command
line interface before the system has fully started up, giving you the chance
to check/repair things before much of the normal OS X environment starts up.

Single-user mode starts you with an extremely minimal environment — not
only is the normal graphical interface not running, neither are most of
the normal system daemons (init
and mach-init are the only ones), and the boot disk isn’t even fully mounted!
Usually, you want to bring at least a little more of OS X up in order to
get anything useful done. Exactly how much depends on what you want to do,
but usually you want to either just mount the boot volume
for write access
, or do that and then start the
various system daemons and components
(e.g. networking) that make up
most of the non-graphical parts of Mac OS X.


Mounting the boot volume for write access:

fsck -y
  - Check the boot volume’s file system, and repair if necessary
(the “-y” means “Yes, go ahead and fix any problems you find”). Always
do this first. Note that this may not be able to fix all problems in a
single pass, so if it finds and fixes anything (it’ll print “***** FILE
SYSTEM WAS MODIFIED *****”), run it again, and keep running it until it
comes back with something like “The volume Macintosh HD appears to be
ok.”

Note: If the volume has journalling enabled, you should get a message like

fsck_hfs: Volume is journaled. No checking performed.
fsck_hfs: Use the -f option to force checking.

In this case it should be reasonably safe to go ahead and mount the volume,
since the journal should have taken care of any necessary repairs. But I’m
paranoid, so I tend to recommend using fsck -yf to force a full
check.

See Apple’s TIL article
#106214
for more info.

mount -uw /
  - Remount the boot volume,
enabling write access. You need to do this before you can change anything on
disk, but always run fsck first.

Note: if this command works, it won’t give you any output (other than another
shell prompt). If it prints something like:
 root_device on / (local, read-only)
 devfs on /dev (local)


then you probably mistyped the command.


Starting system daemons and components:

Depending on what you need to accomplish in single-user mode, you may (or
may not) need to start up more of the operating system’s normal components
(access to disks other than the boot volume, networking, etc). This part of
the process works a bit differently depending on what version of Mac OS X
you’re using. Under 10.0 through 10.2, the
SystemStarter
command is all it takes. Under 10.3, you need
to register the Mach services, then launch
netinfod manually, then finally invoke
SystemStarter to finish the job.
Under 10.4, it gets easy again: you can use /etc/rc to
do the work for you.

After running any of these commands, do not attempt to continue the boot
with the exit command. If you aren’t sure what
version you have, use sw_vers to find out.

Starting daemons under 10.4:

sh /etc/rc
  - Under version 10.4, the normal startup script can be run by hand,
and it’ll do the necessary work of getting the system (mostly) up and
running, but not exit single-user mode or start the GUI.

Starting daemons under 10.3:

/usr/libexec/register_mach_bootstrap_servers
/etc/mach_init.d

  - This registers a bunch of programs to be triggered by mach-init,
which take care of setting up networking, directory services, disk arbitration,
etc. — see the config files in /etc/mach_init.d/ and

Apple’s web page on the boot process

(look for the section on Bootstrap Daemons) for more information.

Note: after this command finishes, several of the things it triggers will
print messages on the screen, possibly mixing in with whatever command you’re
trying to type, and making things generally confusing. You can force it
to reprint the command you’re working on by typing ^p^n (that is, hold down
the control key while pressing “p” and then “n”). Also, one of the messages
may imply that lookupd has failed; don’t worry, it seems to get restarted
normally.

(cd /var/db/netinfo; netinfod -s local)
  - Start up a netinfo server to handle the local domain (i.e. users,
groups, etc defined on this computer).

SystemStarter
  - Start up more of the system, including networking, NFS, and
many background daemons (basically, it runs all of the StartupItems). It does
not, however, start the Aqua interface; it leaves you with the single-user
command line when it’s done.

Note: this command prints out even more stuff than
/usr/libexec/register_mach_bootstrap_servers did. Don’t even try
to get a word in edgewise; I just wait until it finishes (it’ll print
“Startup complete.”), then press return to get a new command prompt.

Starting daemons under 10.0-10.2:

SystemStarter
  - Up through 10.2, this command would take care of starting pretty
much everything (except the GUI)… including everything that
register_mach_bootstrap_servers
and netinfod are needed for under 10.3.


Other Commands useful in Single-user mode:

pico
  - Edit text files (see the main entry for ).
The second line from the top of the screen may contain gibberish, and the keyboard
arrow-keys may not work (use control-characters
instead) but other than that it works normally. vi and emacs
are also available in single-user mode, although vi seems to have
problems with screen updating under at least some versions of OS X.

nicl -raw /var/db/netinfo/local.nidb
  - Edit the local Netinfo database (users & groups, etc) without going
through the netinfo daemon. Handy if the system can’t boot properly because
of a Netinfo configuration problem.

Note: do not use this form of the nicl command after starting the netinfod
server (either manually or with
SystemStarter).

Examples:

nicl -raw /var/db/netinfo/local.nidb

  create disabled

  move mounts disabled
  quit
Disable the NFS “mounts” directory (by creating a “disabled” directory and
moving mounts into it), which can bypass a hang at startup if the computer
tries to mount an unavailable NFS server.
nicl -raw /var/db/netinfo/local.nidb

  delete /localconfig/autologin username

  quit
Disable automatic login at boot time (normally controlled from the Login
pane in System Preferences), in order to avoid logging into a damaged account.

bless
  - Change the system’s boot settings (the “blessed” system). Useful to switch
back to OS 9 if OS X isn’t bootable, and you don’t want to juggle boot CDs.

Example:

bless -folder9 “/System Folder” -use9
Bless the OS-9 system folder named “System Folder” on the current (OS-X) boot
volume, and make OS-9 the default for booting from this volume.

tail
  - Print the last few entries in a log (or other text file). Useful to find
out what happened to get you into this mess.

Examples:

tail /var/log/system.log
print the last screenful of
entries from the main system log.
tail -1000 /var/log/system.log | more
print the last 1000
entries from the main system log, using more to
display them one screenful at a time (remember: in single-user mode, there’s
no way to scroll back like you can in a terminal window).

sw_vers
  - Check the operating system version. Useful to find out which procedure
to use to start system daemons.


Important files:

/var/db/.AppleSetupDone
  - This file, simply by existing, indicates that the computer has had
basic setup performed. If you delete this file, the Setup Assistant will
run on the next reboot, allowing you to create a new local admin account,
re-setup networking, etc.

/Library/Preferences/SystemConfiguration/
(10.3) or

/var/db/SystemConfiguration/ (10.0 - 10.2)
  - Despite its generic-sounding name, this directory is actually where
most of the computer’s network settings are stored (especially in the file
named “preferences.plist”). Moving or renaming this directory will force the
OS to build a default set of network settings on the next reboot (i.e. one
location named “Automatic”, DHCP on all ethernet & AirPort interfaces, etc).
If your network settings get hosed to the point where the computer won’t boot,
this is the easy way out.

/Library/Logs/ and

/var/log/
  - Where the log files are kept. Generally, logs relating to the core
unix (Darwin) parts of the operating system can be found in /var/log/,
while the Apple-proprietary system components log to /Library/Logs/.
When in doubt, look both places. And check out the main system log,
/var/log/system.log — all sorts of interesting events wind up there.
Note: old logs are often archived in gzip (compressed) format; to read these,
you can do something like:

zcat /var/log/system.log.1.gz | more
decompress the
most recent archived system log, and use more to display it one
screenful at a time.


Getting Out of Single-user mode:

exit
  - Continue the boot process (i.e. go to multi-user mode). Note that
if you’ve made any significant changes (or started any daemons, run
SystemStarter, or anything like that),
it’s safer to reboot instead.

reboot
  - Reboot the computer.

shutdown -h now
  - Shut the computer down.


Misc. Notes:

In single-user mode, the shell behaves a little differently than normal (more
so under earlier versions of OS X). For one thing, the default shell may be
different (zsh under 10.0-10.2, bash under 10.3); unless you’re extremely
familiar with the peculiarities of your regular shell, you probably won’t
notice this (except that the shell prompt’ll be different from normal).

Also, the keyboard may not be fully configured in
single-user mode
, so the arrow keys don’t work for command line editing (or
in text editors, either); but you can use control characters (i.e. hold down
the control key - that’s control, not command - and type a letter) instead:
 ^p - previous line, equivalent to up-arrow

 ^n - next line, equivalent to down-arrow

 ^b - back a character, equivalent to left-arrow

 ^f - forward a character, equivalent to right-arrow

 ^a - back to the beginning of the line

 ^e - forward to the end of the line

UNIX Pipelines And I/O Redirections

Sunday, March 18th, 2007

Many unix commands take text-like input and/or produce text-like output. It’s
sometimes useful to be able to control where the input comes from and output
goes (via redirection), or even pass the output from one command to another’s
input (via pipes). This can be used to do fairly complex things, for example
the following command will print a list of mispelled words in the file fnord.txt
(it’s sort of a primitive spellchecker):


tr ‘A-Z’ ‘a-z’ <fnord.txt | tr -cs ‘a-z’ ‘\n’ | sort | uniq | comm -23 - /usr/share/dict/words

What this does is pass the contents of fnord.txt to the tr command
to translate uppercase letters to lowercase; the output from that is piped to
another tr command that turns everything except lowercase letters into
line breaks (effectively putting each word on a seperate line); that’s piped to
sort which puts the lines (words) in alphabetical order; that’s piped
to uniq, which gets rid of duplicate words; that’s piped to comm,
which compares the words to the dictionary, and prints whatever’s not in the
dictionary. (Unfortunately, this tends to include plurals, past tense verbs, words
that came into use after 1934… it’s really not a very good spellchecker.)

Most of the times pipes and redirects are used aren’t nearly that complicated.
In fact, there are fairly few idioms that get used over and over. I’ve tried to
illustrate them in the examples below.

Note: pipes and redirects are actually done by the shell interpreter you’re
running. The simple pipes and redirects described here work essentially the same
in all shells, but most shells can also perform other, more obscure, kinds of pipes
and redirects (e.g. redirecting error messages along with/instead of standard
output). For more details, read the man
page for the shell you’re using. BTW, the default shell under OS-X is
tcsh (except in single-user mode, where it’s zsh).

>
- Redirect output from a command to a file on disk. Note: if the
file already exist, it will be erased and overwritten without warning, so be
careful.

Example:

ps -ax >processes.txt
Use the
ps command to get a list of processes
running on the system, and store the output in a file named processes.txt

>>
- Append output from a command to an existing file on disk.

Example:

ps -ax >>processes.txt
Tack the current process list
onto the end of the file processes.txt

<
- Read a command’s input from a disk file, rather than the user. Be careful
not to type “>” by mistake, or you’ll erase the contents of the file
you’re trying to read from.

Example:

niload -d -r / . </var/backups/local.nidump
Use the
niload command to load data from the file /var/backups/local.nidumpinfo
into the current NetInfo domain. Without input redirection, you’d have to type
the NetInfo data into the terminal by hand (and God help you if you got the
syntax slightly wrong…)

|
- Pass the output of one command to another for further processing.

Examples:

ps -ax | grep Finder
Use the
ps command to get a list of processes
running on the system, and pass the list to
grep to search for lines containing
“Finder”. (Usually, it’ll find two: the Finder, and the processes executing
grep Finder.)
lsof | more
Use the lsof command to list all open
files in use on the system, and pass the list to
more to display it one screen at a
time (rather than just spewing the whole thing directly to the terminal).

tee
- Used in the middle of a pipeline, this command allows you to both redirect
output to a file, and pass it to further commands in the pipeline.

Examples:

ps -ax | tee processes.txt | more
Use the
ps command to get a list of processes
running on the system, store it in the file processes.txt, and also pass it to
more to display it one screen at a
time. Note that you could get the same result with the two commands:


ps -ax >processes.txt
more processes.txt

Changing File Permissions Using Unix Commands

Sunday, March 18th, 2007

The following
information will help you to use Unix commands to change file permissions.
If you have not already done so, you may want to review the document Unix
File Permissions
. Please note that Unix can be a very user-unfriendly
environment. For a start-to-finish tutorial on working in the Unix environment,
please see Unix for Web Designers.

Directions
for:

Single-user
sites

The steps
for correcting permissions errors on single-user sites are as follows:

  1. establish
    a secure connection (using SecureCRT or NiftyTelnet - both are available
    from Software Central) to the server
    which houses your web pages
  2. issue
    the Unix command chmod for any files or directories which need
    to be changed.
Scenario:
User mst3k is getting a permissions error when trying to view his
web site at http://www.people.virginia.edu/~mst3k.

After
logging into blue.unix.virginia.edu with SecureCRT, mst3k issues
the following on the Unix command line:

cd public_html

to go to
the directory where his web page is stored. He then views the permissions
by issuing the command:

ls -l
home.html

and sees
the following output:

-rw-r—–
1 mst3k staff 724 Jan 17 2001 home.html

Permissions
are organized into three major groupings. In this example the permissions
for user are rw-, the permissions for group
are r–, and the permissions for other are .

This file
is not viewable on the web because “other” does not have
read permissions. To correct the problem, mst3k issues the command:

chmod
o+r home.html

To verify
that the command produced the desired results, mst3k again issues the
command:

ls -l
home.html

and sees
the following output:

-rw-r–r–
1 mst3k staff 724 Jan 17 2001 home.html

Provided
that the permissions of the parent directories are correct, the
page should now be viewable on the web.

The following
chart outlines the recommended permission settings for the files and directories
in single-user web sites:

Recommended
Permissions for single-user web sites

File
Permissions

User

Group

Other

read

read

read

write

-

-

-

-

-

rw-r–r–

 

Directory
Permissions

User

Group

Other

read

-

-

write

-

-

execute

execute

execute

rwx–x–x


Group-maintained
sites

The steps
for correcting permissions errors on group-maintained sites are as follows:

  1. establish
    a secure connection (using SecureCRT or NiftyTelnet - both are available
    from Software Central) to the server
    which houses your web pages
  2. Verify
    that the group ownership of your files is correct
  3. issue
    the Unix command chmod for any files or directories which need
    to be changed.
Scenario:
User mst3k is getting a permissions error when trying to edit the
file home.html in the group-maintained site http://www.virginia.edu/somesite

After
logging into minerva.acc.virginia.edu with SecureCRT, mst3k issues
the following on the Unix command line:

cd
/www/doc/somesite

to
go to the directory where the web page is stored. He then views
the permissions by issuing the command:

ls
-l home.html

and
sees the following output:

-rw-r–r–
1 abc2d staff 724 Jan 17 2001 home.html

There
are two problems with this file: (1) The group ownership
is not correct; (2) group write permissions have not been
set.

To
correct this problem, mst3k goes to find the owner of the file -
abc2d. Only the owner of the file may change the group ownership
or permissions.

abc2d
then logs into her account and repeats the steps above. To change
the group ownership, she issues the command:

chgrp
somegrp home.html

where
somegrp is the group that was designated for this web site.
She then adds group write permissions by issuing the command:

chmod
g+w home.html

Finally,
she verifies that the changes were made by issuing the command:

ls
-l home.html

and
sees the following output:

-rw-rw-r–
1 abc2d somegrp 724 Jan 17 2001 home.html

Provided
that mst3k is a member of the group somegrp, he will now be able
to edit the file.

The following
chart outlines the recommended permission settings for the files and directories
in group-maintained web sites:

Recommended
Permissions for group-maintained web sites

File
Permissions

User

Group

Other

read

read

read

write

write

-

-

-

-

rw-rw-r

 

Directory
Permissions

User

Group

Other

read

read

-

write

write

-

execute

execute

execute

rwxrwx–x

Miscellaneous UNIX Commands

Sunday, March 18th, 2007

man
- display online documentation (”manual pages”) for a command.

Example:

man ls
displays detailed documentation on the ls command

apropos
- list the manual pages relating to a particular keyword.

Example:

apropos file
list manual pages that mention “file” in their
summary line.

find
- Scan a directory structure for files matching certain criteria, and
either print their names or do nearly anything else with them. Similar to
Sherlock, but very unixlike (i.e. terse, cryptic, case sensitive, and extremely
powerful if you understand it well enough).

Examples:

find / -name foo
Search the entire file structure
(including all mounted volumes) for files named exactly “foo”, and print
their paths.

Note: under some conditions (especially involving complex NetInfo networks)
this may search infinitely amongst various network volumes. Use the
-x option to avoid this (see next example).

find -x / -name foo
Search just the boot volume (the
-x prevents it from crossing to other volumes) for files named
exactly “foo”, and print their paths.
find . -name ‘*foo*’
Search the current directory and
all subdirectories for files whose names contain “foo”. You need to use
the quote-marks in the command, or something incomprehensible will happen.
find . -mtime -2
Search the current directory and
all subdirectories for files modified within the last 2 days. (Note: this
may also find some files with confused modification dates — i.e. files that’re
marked as having been modified in the future. -mtime -0 would find
ONLY the files with future modification dates.
find -x / -user george -print0 | xargs -0 chown eva
Search just
the boot volume for files owned by George, and assign them to Eva instead.
Note: you must be root to do this (otherwise, you’ll get a lot
of error messages).
find ~/Documents -type f -print0 | xargs -0 grep -il birthday
Search all documents (using the grep
command) in my personal Documents folder, and print a list of files containing
the string “birthday” (either upper or lowercase). (The “-type f
is there so it won’t try to search directories, or other non-document-ish things;
-i” tells grep to ignore upper/lowercase distinctions, and
-l” means print the filenames [actually paths], not the matching
contents.)

locate
- Scan a database for files with a given name, and print their names.
Faster than find, but requires that the database be built in advance
(and be up to date).

Notes:

  • In order to see all files, and have permission to build the database,
    the script to build/update the database should run as root.
  • Because the database contains a complete list of files on the disk,
    (including those in private directories), and is readable by anyone, this
    can … have security implications. If it worries you, just don’t build
    the database in the first place.
  • locate’s matching rules can be rather counterintuitive, mainly because
    it searches the entire path, not just the filename, for a match to what
    you tell it to search for. Together with the fact that if your search
    string doesn’t contain any wildcards it searches as though you specified
    wildcards at the beginning and end of the search string, this means it
    may not do exactly what you expected.

Examples:

sudo /usr/libexec/locate.updatedb
Switch to root (see
sudo) and build/update the database.
locate foo
Search the database for files with names
containing “foo”, or in folders with names containing “foo”, and print
their paths.
locate ‘*.jpg’
Search the database for files with names
ending in “.jpg” (but not in folders ending in “.jpg”), and print their
paths.

open
- Open a file in the GUI (essentially equivalent to double-clicking
the file in the finder).

Examples:

open ~Documents/foo
Open the file “foo” in my Documents
folder.
open -a /Applications/TextEdit.app ~/Documents/foo
Use
the application TextEdit to open “foo” (equivalent to drag-and-dropping foo
on TextEdit).

Need a web and database programmer? Contact The PHP Kemist

eCommerce Web Site Design | PHP Web Programmers | Website Development & Search Engine Optimization
Network Security Programmers | Shopping Carts For eCommerce | Internet & Search Engine Marketing
Salt Lake City Utah Website Design | Bay Area California Website Design | San Jose California Website Design