20100828

simplest way to make an application bundle using nothing but notepad.

Create a Application Bundle in 3 easy steps ;)

No Xcode needed, just a filebrowser and a texteditor. While poking around with .app dirs I noticed that as soon as I provided a MacOS folder containing something executable named the same as the app, my tiger box happily starts to run it without needing or checking a .plist or anything....

Sweet :) 
here goes ;) 


* in the terminal:
 bash$ mkdir -p MyShinyShellScriptWrapper.app/MacOS  
 bash$ echo -e "#!/bin/bash\necho \$(date) >  ~/Desktop/proofofexecution.txt" \  >MyShinyShellScriptWrapper.app/MacOS/MyShinyShellScriptWrapper 
 bash$ chmod 755 MyShinyShellScriptWrapper.app/MacOS/MyShinyShellScriptWrapper 



* or in the finder:
Open a finder window and create a new folder.  Open it and in it create a MacOS folder, now decide on a name. Create a new (plain) text document in the newly created folder and name it YourProgramName
 Now type these two lines in the textdocument:
#!/bin/bash
echo $(date) > ~/Desktop/proofofexecution.txt
Right! Close the file and save it as YourProgramName without an extension. (eg no .txt or .html or .whatever)
Right click on the file and  select Get Info.  Here you.... pfff, here you DONT find a set permissions to executable.
Anyway, open up a Terminal and type chmod 755 YourProgramName and close it off/ (is this even neccessary?)
Now go 2 levels up in the folder and rename the folder that you created in the beginning to  YourProgramName.app

Now it should've turned into an application with a broken icon. This is good :) Double click the icon to start it up!

Nothing much happened? The script runs in the background and takes a nanosecond to finish so nothing much should happen, but on your Desktop 
You should now see a new file called proofofexecution containing a timestamp.

Shweeet





How to make a shell script into a apple macintosh app application bundle using nothing but common household tools ;-)



dd
Sweet :)

10.4: Remapping keys in Mac OS X 10.4

10.4: Remapping keys in Mac OS X 10.4 

10.4: Remapping keys in Mac OS X 10.4 System 10.4
The Mac OS X 10.4 Keyboard & Mouse preference pane provides a way to remap certain keys. However, the interface doesn't expose the full functionality -- a common problem with Apple software. Note that this guide assumes you'using the bash shell.

Read on to learn...
  • What keys can be remapped without the use of any third–party software?
  • How do I remap those keys?
  • How do I remap the Caps Lock key to the Escape key?


What keys can be remapped without the use of any third–party software? (The following list shows the key name on the left, and that key's value on the right.)
  • None — –1
  • Caps Lock — 0
  • Shift (Left) — 1
  • Control (Left) — 2
  • Option (Left) — 3
  • Command (Left) — 4
  • Keypad 0 — 5
  • Help — 6
  • Shift (Right) — 9
  • Control (Right) — 10
  • Option (Right) — 11
  • Command (Right) — 12
  • Kernel Panic — 16
Be warned that the code 16, when used as the destination of a mapping, actually causes a kernel panic on keypress -- as I've found out the hard way.

How do I remap those keys?
  1. Remap one of the keys available in the Keyboard & Mouse preference pane in order to make the following steps easier.
  2. Locate the hidden property list file used to store the settings. It's in your user's Library/Preferences/ByHost folder, and is named.GlobalPreferences.000d*. I assume there'll be only one such file; you'll need to verify that. From here on, that file and path are referred to as$FILE.
  3. Duplicate the file and convert it to the XML property list format:
    $ cp $FILE ~/keys-binary.plist
    $ plutil -convert xml1 -o ~/keys-xml.plist ~/keys-binary.plist
  4. Open the resulting XML file and locate thecom.apple.keyboard.modifiermapping key. Its value is an array containing several entries, each in turn containingHIDKeyboardModifierMappingSrc and HIDKeyboardModifierMappingDstkeys. The values of those keys are described in the table above. Make the changes you wish to make, and save your work.
  5. Convert the file back to the binary property list format, and put it back in the correct location:
    $ plutil -convert binary1 -o ~/keys-binary.plist ~/keys-xml.plist
    $ cp ~/keys-binary.plist $FILE
  6. Log out and back in to apply changes.
How do I remap the Caps Lock key to the Escape key?

Unfortunately, this will require the use of a third–party program. I used a free trial version of Keyboard Maestro by Stairways Software. First, remap the Caps Lock key to the Help key, following the instructions above. Then, in Keyboard Maestro:
  • Create a new macro.
  • Add a Simulate Keypress action, with an User Keystroke — the Escape key.
  • Add a Hot Key trigger, set to the Help key.
  • In the Preferences section, enable the Launch Engine at Login option. While you're at it, you might also want to disable all other unnecessary features.
An always up–to–date version of this guide can be found on my blog...

20100827

multitail bus error on osx

I tried to install and use multitail this morning.

sudo port install multitail

everything seems to build/install

multitail /opt/local/apache2/logs/access_log /opt/local/apache2/logs/ 
error_log

gives me a "Bus error" - along with 2 processes running tail...

Installs and runs just fine on Panther (just checking)

I can download and build the source in my home directory. That works  
just fine, and runs.

For entertainment value I created /opt/local/etc/multitail.conf (from  
the /opt/local/etc/multitail.conf.new file)

Bus error stopped happening...

Executed in subshell, trap on exit


#!/bin/bash
# --- subshell_trap.sh -------------------------------------------------
# Example script for handling bash errors.  Exit on error.  Trap exit.
# This script is supposed to run in a subshell.
# See also: http://fvue.nl/wiki/Bash:_Error_handling

    # Let shell functions inherit ERR trap.  Same as `set -E'.
set -o errtrace 
    # Trigger error when expanding unset variables.  Same as `set -u'.
set -o nounset
    #  Trap non-normal exit signals: 1/HUP, 2/INT, 3/QUIT, 15/TERM, ERR
    #  NOTE1: - 9/KILL cannot be trapped.
    #+        - 0/EXIT isn't trapped because:
    #+          - with ERR trap defined, trap would be called twice on error
    #+          - with ERR trap defined, syntax errors exit with status 0, not 2
    #  NOTE2: Setting ERR trap does implicit `set -o errexit' or `set -e'.
trap onexit 1 2 3 15 ERR


#--- onexit() -----------------------------------------------------
#  @param $1 integer  (optional) Exit status.  If not set, use `$?'

function onexit() {
    local exit_status=${1:-$?}
    echo Exiting $0 with $exit_status
    exit $exit_status
}



# myscript



    # Allways call `onexit' at end of script
onexit

http://www.gfxcoder.us/wiki/programming/bash


Handy BASH reference (link)

robust script writing (link)

lockfile
lockfile a.lock
#do stuff hererm -f a.lock

date (link)

Spicing up your shell script (link)

parameters (link)

Tutorials

misc (linklink)
functions (link)

timing commands
/usr/bin/time -o outfile -v command # prints verbose stats into outfile from running command

BASH internal variables (link)

for loops (link)
for i in 1 2 3 4 5
do
  echo "Welcome $i times"
done

for i in {1..5}
do
  echo "Welcome $i times"
done

for i in {0..10..2} # skip by 2s, only BASH 4.0+
do
  echo "Welcome $i times"
done

for (( c=1; c<=5; c++ ))
do
  echo "Welcome $c times"
done

for i in 1 2 3 4 5
do
  echo "Welcome $i times"
  if ( condition )
  then
    break
  fi
done
# continue - jumps to beginning of loop with next iteration

for file in /etc/*
do
  if [ "${file}" == "/etc/resolv.conf" ]
  then
    echo "file ${file} found!"
  fi
done

files="$@"
for f in $files
do
  if [ -f ${f} ]
  then
    echo "{f} is a file"
  else
    echo "${f} is not a file"
  fi
done

pausing with read (link)
$ read -p "Press enter to quit..."                   # reads one line
$ read -n 1 -p "Press any key to start backup..."    # reads only one char
$ read -n 1 -s -t 5                                  # reads one char, no echo, 5sec timeout
$ read -n 1 -s key                                   # reads one char, no echo, stores in ${key}

terminate commands after timeout (link)
#!/bin/bash
# License: BSD License
# As Example we start 3 production processes in the background
# always record PID in PRODPID

sleep 50 &
PRODPID[1]=$!

sleep 20 &
PRODPID[2]=$!

# multiple processes in a subshell as example
(sleep 20 ; sleep 10 ; sleep 5)&
PRODPID[3]=$!

export PRODPID

# record own PID
export PID=$$


# define exit function
exit_timeout() {
  echo "Timeout. These processes are not finished:"
  for i in ${PRODPID[@]} ; do
    ps -p $i |grep -v "PID TTY      TIME CMD"
    if [ $? == 0 ] ; then
      # process still alive
      echo "Sending SIGTERM to process $i"
      kill $i
    fi
  done
  # timeout exit
  exit
}

# Handler for signal USR1 for the timer
trap exit_timeout SIGUSR1

# starting timer in subshell. It sends a SIGUSR1 to the father if it timeouts.
export TIMEOUT=30
(sleep $TIMEOUT ; kill -SIGUSR1 $PID) &

# record PID of timer
TPID=$!

# wait for all production processes to finish
wait ${PRODPID[*]}

# Normal exit
echo "All processes ended normal"

# kill timer
kill $TPID
or (link)
runtime=${1:-1m}
mypid=$
cp /Database/Client_db_200802110231.BAK .&
cpid=$!
sleep $runtime
kill -s SIGTERM $cpid
echo "Both processes are terminated".



catching traps (link)
# trap [commands] [traps]
trap "echo Booh!" SIGINT SIGTERM


aoeu
aoeu

20100824

aomk

maybe a raving loony, and even mentally retarded, BUT i really do Avoid at all costs to upload magic to ungrateful fucks like you, just as i did many times in the past to fuck users who are now on AOM, NEO, MT, EXO, and the rest of the copy magic sites




-- map{ map{tr|10|# |;print} split//,sprintf"%.8b\n",$_} unpack'C*',unpack'u*',"5`#8<3'X`'#8^-@`<-CPP`#8V/C8`"