von Doppeltes Risiko » 17.06.2011, 22:07
So da ich immer mal wieder mit Geektool arbeite und es ja auch ein paar MacUser hier gibt,
dachte ich mal schreibe mal alle Codes die ich in letzter Zeit gesammelt habe hier rein
Adium
Code: Alles auswählen
#!/bin/bash
mypath=$1
osascript $mypath/adium.scpt 2>&1 #| awk '{ print "Now Playing: " $0}'
echo
Battery
Code: Alles auswählen
#!/bin/bash
asbreg=`ioreg -rc "AppleSmartBattery"`
maxcap=`echo "${asbreg}" | awk '/MaxCapacity/{print $3}'`;
curcap=`echo "${asbreg}" | awk '/CurrentCapacity/{print $3}'`;
prcnt=`echo "scale=2; 100*$curcap/$maxcap" | bc`;
printf "Battery: %1.0f%%\n" ${prcnt};
echo
# another way of doing it:
#echo "Battery"
#ioreg -w0 -l | grep DesignCapacity | awk '{ print substr($0,19,50) }' | sed 's/"//g'
#ioreg -w0 -l | grep MaxCapacity | awk '{ print substr($0,19,50) }' | sed 's/"//g'
#ioreg -w0 -l | grep CurrentCapacity | awk '{ print substr($0,19,50) }' | sed 's/"//g'
#EOF
Calendar
Code: Alles auswählen
#!/bin/bash
cal | sed "s/^/ /;s/$/ /;s/ $(date +%e) / $(date +%e | sed 's/./#/g') /"
Calendar Horizontal
Code: Alles auswählen
#!/bin/bash
myscriptpath=`echo $0 | rev | awk '{firstslash=index($0,"/");print substr($0,firstslash+1,length($0)); }' | rev`
# uncomment this line to have just the basic calendar with ||'s around the current day and weeks mashed together
#cal | sed -e '1d' -e '2p;2p;2p;2p' | sed -e '$!N;s/\n/ /' -e '$!N;s/\n/ /' -e '$!N;s/\n/ /' -e '$!N;s/\n/ /' | sed "s/^/ /;s/$/ /;s/ $(date +%e) /\|$(date +%e)\|/"
# uncomment this line to have weeks split by a space and today's date replaced with a ##
$myscriptpath/calendar.bash | sed -e '1d' -e '2p;2p;2p;2p' | sed -e '$!N;s/\n/ /' -e '$!N;s/\n/ /' -e '$!N;s/\n/ /' -e '$!N;s/\n/ /' | sed "s/^/ /;s/$/ /;s/ $(date +%e) /\|$(date +%e)\|/" | sed -e "s/^\ \ //"
echo
Computer Info
Code: Alles auswählen
#!/bin/bash
scutil --get ComputerName;
sw_vers | awk -F':\t' '{print $2}' | paste -d ' ' - - - ;
sysctl -n hw.memsize | awk '{print $0/1073741824"gb RAM"}';
sysctl -n machdep.cpu.brand_string;
External Address
Code: Alles auswählen
#!/bin/bash
echo "External :" `curl --silent http://checkip.dyndns.org | awk '{print $6}' | cut -f 1 -d "<"`
TimeOut
Code: Alles auswählen
#!/bin/bash
# FROM: http://www.cyberciti.biz/faq/shell-scripting-run-command-under-alarmclock/
##########################################################################
# Shellscript: timeout - set timeout for a command
# Author : Heiner Steven
# Date : 29.07.1999
# Category : File Utilities
# Requires :
# SCCS-Id. : @(#) timeout 1.3 03/03/18
##########################################################################
# Description
# o Runs a command, and terminates it (by sending a signal) after
# a specified time period
# o This command first starts itself as a "watchdog" process in the
# background, and then runs the specified command.
# If the command did not terminate after the specified
# number of seconds, the "watchdog" process will terminate
# the command by sending a signal.
#
# Notes
# o Uses the internal command line argument "-p" to specify the
# PID of the process to terminate after the timeout to the
# "watchdog" process.
# o The "watchdog" process is invoked by the name "$0", so
# "$0" must be a valid path to the script.
# o If this script runs in the environment of the login shell
# (i.e. it was invoked using ". timeout command...") it will
# terminate the login session.
##########################################################################
PN=`basename "$0"` # Program name
VER='1.3'
TIMEOUT=5 # Default [seconds]
Usage () {
echo >&2 "$PN - set timeout for a command, $VER
usage: $PN [-t timeout] command [argument ...]
-t: timeout (in seconds, default is $TIMEOUT)"
exit 1
}
Msg () {
for MsgLine
do echo "$PN: $MsgLine" >&2
done
}
Fatal () { Msg "$@"; exit 1; }
while [ $# -gt 0 ]
do
case "$1" in
-p) ParentPID=$2; shift;; # Used internally!
-t) Timeout="$2"; shift;;
--) shift; break;;
-h) Usage;;
-*) Usage;;
*) break;; # First file name
esac
shift
done
: ${Timeout:=$TIMEOUT} # Set default [seconds]
if [ -z "$ParentPID" ]
then
# This is the first invokation of this script.
# Start "watchdog" process, and then run the command.
[ $# -lt 1 ] && Fatal "please specify a command to execute"
"$0" -p $$ -t $Timeout & # Start watchdog
#echo >&2 "DEBUG: process id is $$"
exec "$@" # Run command
exit 2 # NOT REACHED
else
# We run in "watchdog" mode, $ParentPID contains the PID
# of the process we should terminate after $Timeout seconds.
[ $# -ne 0 ] && Fatal "please do not use -p option interactively"
#echo >&2 "DEBUG: $$: parent PID to terminate is $ParentPID"
exec >/dev/null 0<&1 2>&1 # Suppress error messages
sleep $Timeout
kill $ParentPID && # Give process time to terminate
(sleep 2; kill -1 $ParentPID) &&
(sleep 2; kill -9 $ParentPID)
exit 0
fi
Trashsize
Code: Alles auswählen
#!/bin/bash
du -sh ~/.Trash/ | awk '{print "Trash Size: " $1}'
echo
Weather
Code: Alles auswählen
#!/bin/bash
# Replace with the zipcode for the weather you want.
myzipcode=$1
myurl="http://printer.wunderground.com/cgi-bin/findweather/getForecast?query="$myzipcode
myweathercommand="lynx -dump "$myurl
myweatherresults=`$myweathercommand`
# uncomment for testing:
#echo $myweatherresults
echo "Weather for: $myzipcode"
# Temperature
echo $myweatherresults | awk '{start=index($0,"Temperature");end=index($0,"Humidity");start=start+12;end=end-4;print " " substr($0,start,end-start), substr($0,end+2,1)}'
# original version - this does 2 web calls, where the other way does 1
#echo `$myweathercommand | awk '/Temp/{printf $2, ": "; for (i=3; i<=3; i++) printf $i " " }'`
# new way is also more kind to website changes.
# Forecast
# this should be made more efficient by someone who knows regexp/awk better
echo $myweatherresults | awk '{start=index($0,"Conditions");str=substr($0,start+10,length($0)-start-10);start=index(str,"Conditions");end=index(str,"Visibility");start=start+11;print " " substr(str,start,end-start)}'
# original version - this does 2 web calls, where the other way does 1
# new way is also more kind to website changes.
#echo `$myweathercommand | awk '/Cond/ && !/Fore/ {for (i=2; i<=10; i++) printf $i " " }'`
echo
Day:
Code: Alles auswählen
date "+%A" | sed -e 's/Monday/Montag/g' -e 's/Tuesday/Dienstag/g' -e 's/Wednesday/Mittwoch/g' -e 's/Thursday/Donnerstag/g' -e 's/Friday/Freitag/g' -e 's/Saturday/Samstag/g' -e 's/Sunday/Sonntag/g'
Day Number:
Months:
Time:
UpTime:
Code: Alles auswählen
uptime | awk '{print "" $3 " " $4 " " $5 }' | sed -e 's/.$//g';
HDD SpaceInfo:
Code: Alles auswählen
#!/bin/sh
df -g | grep disk0s2 | awk '{print "Brain:",$2,"GB Cells,", $4, "GB Free"}'
df -g | grep disk0s3 | awk '{print "Daten :",$2,"GB total,", $3, "GB Belegt,", $4, "GB Free"}'[
Ich weiß bei vielen Leider nicht mehr wo ich sie her habe, aber wenn dann steht mit im Code
Ich hoffe ihr habt auch ein paar, für mich
So da ich immer mal wieder mit Geektool arbeite und es ja auch ein paar MacUser hier gibt,
dachte ich mal schreibe mal alle Codes die ich in letzter Zeit gesammelt habe hier rein :)
[b]Adium[/b]
[code]#!/bin/bash
mypath=$1
osascript $mypath/adium.scpt 2>&1 #| awk '{ print "Now Playing: " $0}'
echo
[/code]
[b]Battery[/b]
[code]#!/bin/bash
asbreg=`ioreg -rc "AppleSmartBattery"`
maxcap=`echo "${asbreg}" | awk '/MaxCapacity/{print $3}'`;
curcap=`echo "${asbreg}" | awk '/CurrentCapacity/{print $3}'`;
prcnt=`echo "scale=2; 100*$curcap/$maxcap" | bc`;
printf "Battery: %1.0f%%\n" ${prcnt};
echo
# another way of doing it:
#echo "Battery"
#ioreg -w0 -l | grep DesignCapacity | awk '{ print substr($0,19,50) }' | sed 's/"//g'
#ioreg -w0 -l | grep MaxCapacity | awk '{ print substr($0,19,50) }' | sed 's/"//g'
#ioreg -w0 -l | grep CurrentCapacity | awk '{ print substr($0,19,50) }' | sed 's/"//g'
#EOF
[/code]
[b]Calendar[/b]
[code]#!/bin/bash
cal | sed "s/^/ /;s/$/ /;s/ $(date +%e) / $(date +%e | sed 's/./#/g') /"[/code]
[b]Calendar Horizontal[/b]
[code]#!/bin/bash
myscriptpath=`echo $0 | rev | awk '{firstslash=index($0,"/");print substr($0,firstslash+1,length($0)); }' | rev`
# uncomment this line to have just the basic calendar with ||'s around the current day and weeks mashed together
#cal | sed -e '1d' -e '2p;2p;2p;2p' | sed -e '$!N;s/\n/ /' -e '$!N;s/\n/ /' -e '$!N;s/\n/ /' -e '$!N;s/\n/ /' | sed "s/^/ /;s/$/ /;s/ $(date +%e) /\|$(date +%e)\|/"
# uncomment this line to have weeks split by a space and today's date replaced with a ##
$myscriptpath/calendar.bash | sed -e '1d' -e '2p;2p;2p;2p' | sed -e '$!N;s/\n/ /' -e '$!N;s/\n/ /' -e '$!N;s/\n/ /' -e '$!N;s/\n/ /' | sed "s/^/ /;s/$/ /;s/ $(date +%e) /\|$(date +%e)\|/" | sed -e "s/^\ \ //"
echo
[/code]
[b]Computer Info[/b]
[code]#!/bin/bash
scutil --get ComputerName;
sw_vers | awk -F':\t' '{print $2}' | paste -d ' ' - - - ;
sysctl -n hw.memsize | awk '{print $0/1073741824"gb RAM"}';
sysctl -n machdep.cpu.brand_string;[/code]
[b]External Address[/b]
[code]#!/bin/bash
echo "External :" `curl --silent http://checkip.dyndns.org | awk '{print $6}' | cut -f 1 -d "<"`
[/code]
[b]TimeOut[/b]
[code]#!/bin/bash
# FROM: http://www.cyberciti.biz/faq/shell-scripting-run-command-under-alarmclock/
##########################################################################
# Shellscript: timeout - set timeout for a command
# Author : Heiner Steven
# Date : 29.07.1999
# Category : File Utilities
# Requires :
# SCCS-Id. : @(#) timeout 1.3 03/03/18
##########################################################################
# Description
# o Runs a command, and terminates it (by sending a signal) after
# a specified time period
# o This command first starts itself as a "watchdog" process in the
# background, and then runs the specified command.
# If the command did not terminate after the specified
# number of seconds, the "watchdog" process will terminate
# the command by sending a signal.
#
# Notes
# o Uses the internal command line argument "-p" to specify the
# PID of the process to terminate after the timeout to the
# "watchdog" process.
# o The "watchdog" process is invoked by the name "$0", so
# "$0" must be a valid path to the script.
# o If this script runs in the environment of the login shell
# (i.e. it was invoked using ". timeout command...") it will
# terminate the login session.
##########################################################################
PN=`basename "$0"` # Program name
VER='1.3'
TIMEOUT=5 # Default [seconds]
Usage () {
echo >&2 "$PN - set timeout for a command, $VER
usage: $PN [-t timeout] command [argument ...]
-t: timeout (in seconds, default is $TIMEOUT)"
exit 1
}
Msg () {
for MsgLine
do echo "$PN: $MsgLine" >&2
done
}
Fatal () { Msg "$@"; exit 1; }
while [ $# -gt 0 ]
do
case "$1" in
-p) ParentPID=$2; shift;; # Used internally!
-t) Timeout="$2"; shift;;
--) shift; break;;
-h) Usage;;
-*) Usage;;
*) break;; # First file name
esac
shift
done
: ${Timeout:=$TIMEOUT} # Set default [seconds]
if [ -z "$ParentPID" ]
then
# This is the first invokation of this script.
# Start "watchdog" process, and then run the command.
[ $# -lt 1 ] && Fatal "please specify a command to execute"
"$0" -p $$ -t $Timeout & # Start watchdog
#echo >&2 "DEBUG: process id is $$"
exec "$@" # Run command
exit 2 # NOT REACHED
else
# We run in "watchdog" mode, $ParentPID contains the PID
# of the process we should terminate after $Timeout seconds.
[ $# -ne 0 ] && Fatal "please do not use -p option interactively"
#echo >&2 "DEBUG: $$: parent PID to terminate is $ParentPID"
exec >/dev/null 0<&1 2>&1 # Suppress error messages
sleep $Timeout
kill $ParentPID && # Give process time to terminate
(sleep 2; kill -1 $ParentPID) &&
(sleep 2; kill -9 $ParentPID)
exit 0
fi
[/code]
[b]Trashsize[/b]
[code]#!/bin/bash
du -sh ~/.Trash/ | awk '{print "Trash Size: " $1}'
echo
[/code]
[b]Weather[/b]
[code]#!/bin/bash
# Replace with the zipcode for the weather you want.
myzipcode=$1
myurl="http://printer.wunderground.com/cgi-bin/findweather/getForecast?query="$myzipcode
myweathercommand="lynx -dump "$myurl
myweatherresults=`$myweathercommand`
# uncomment for testing:
#echo $myweatherresults
echo "Weather for: $myzipcode"
# Temperature
echo $myweatherresults | awk '{start=index($0,"Temperature");end=index($0,"Humidity");start=start+12;end=end-4;print " " substr($0,start,end-start), substr($0,end+2,1)}'
# original version - this does 2 web calls, where the other way does 1
#echo `$myweathercommand | awk '/Temp/{printf $2, ": "; for (i=3; i<=3; i++) printf $i " " }'`
# new way is also more kind to website changes.
# Forecast
# this should be made more efficient by someone who knows regexp/awk better
echo $myweatherresults | awk '{start=index($0,"Conditions");str=substr($0,start+10,length($0)-start-10);start=index(str,"Conditions");end=index(str,"Visibility");start=start+11;print " " substr(str,start,end-start)}'
# original version - this does 2 web calls, where the other way does 1
# new way is also more kind to website changes.
#echo `$myweathercommand | awk '/Cond/ && !/Fore/ {for (i=2; i<=10; i++) printf $i " " }'`
echo
[/code]
Day:
[code]date "+%A" | sed -e 's/Monday/Montag/g' -e 's/Tuesday/Dienstag/g' -e 's/Wednesday/Mittwoch/g' -e 's/Thursday/Donnerstag/g' -e 's/Friday/Freitag/g' -e 's/Saturday/Samstag/g' -e 's/Sunday/Sonntag/g'[/code]
Day Number:
[code]date +%d[/code]
Months:[code]
date +%B[/code]
Time:
[code]date +%H:%M [/code]
UpTime:
[code]uptime | awk '{print "" $3 " " $4 " " $5 }' | sed -e 's/.$//g';[/code]
HDD SpaceInfo:
[code]#!/bin/sh
df -g | grep disk0s2 | awk '{print "Brain:",$2,"GB Cells,", $4, "GB Free"}'
df -g | grep disk0s3 | awk '{print "Daten :",$2,"GB total,", $3, "GB Belegt,", $4, "GB Free"}'[[/code]
Ich weiß bei vielen Leider nicht mehr wo ich sie her habe, aber wenn dann steht mit im Code :) Ich hoffe ihr habt auch ein paar, für mich :)