Ruby, MAC, Geektool Question, File Access Rights

Ruby, Mac, Geektool question, file access rights?

Geektool runs all the commands from / so relative path names will not work when trying to run growlnotify.

puts Dir.pwd  #outputs "/"

You will need to pass the absolute paths of the images to growlnotify.

The current path can be retrieved with

File.dirname(__FILE__)

So you would use

theAuthorImage = File.dirname(__FILE__)

case theAuthor
when 'James' : theAuthorImage += '/images/me32.png'
when 'Zuzu' : theAuthorImage += '/images/Zuzu32.png'
end

cmd = "/usr/local/bin/growlnotify '#{theAuthor} says' -m '#{theMessage}' -n 'Laurens Notes' --image '#{theAuthorImage}'"
puts cmd
system cmd

Mac OS X options for running a Ruby file in the background repeatedly

Geektool ended up working out for my needs after all.

Need help using GeekTool with system_profiler and networksetup

I modified my geek tool script a little bit and omitted the Signal to Noise ration thing. Here is what the new AirportStatus.sh file looks like:

#! /bin/bash

# echo -e "\033[0;30m" echo in black
# echo -e "\033[0;31m" echo in red
# echo -e "\033[0;32m" echo in green
# echo -e "\033[0;33m" echo in yellow
# echo -e "\033[0;34m" echo in blue
# echo -e "\033[0;35m" echo in magenta
# echo -e "\033[0;36m" echo in cyan
# echo -e "\033[0;37m" echo in white

# echo -e "\033[4;37m" echo in white underlined

echo -e "\033[4;33m" "Airport"

# Get Airport status from OS X
Status=$(ifconfig en1 | awk '/status/ {print $2}')

if [ "$Status" = "inactive" ];
then echo -e "\033[0;31m" "Status: " $Status "\nNot connected to wireless AP."
else echo -e "\033[0;32m" "Status" $Status

# Get wireless stats from OS X

WiFi=$(networksetup -getairportnetwork en1 | awk '{print $4 " " $5 " " $6 " " $7 " " $8}')
WiFi_IP=$(networksetup -getinfo Wi-Fi | grep -v IPv6 | awk '/IP address/ {print $3}')
SubMask=$(networksetup -getinfo Wi-Fi | awk '/Subnet mask/ {print $3}')
TRate=$(system_profiler SPAirPortDataType | awk '/Transmit/' | sed 's/[^0-9]//g')

# Get bytes in/out

# get the current number of bytes in and bytes out
myvar1=$(netstat -ib | grep -e en1 -m 1 | awk '{print $7}') # bytes in
myvar3=$(netstat -ib | grep -e en1 -m 1 | awk '{print $10}') # bytes out

#wait one second
sleep 1

# get the number of bytes in and out one second later
myvar2=$(netstat -ib | grep -e en1 -m 1 | awk '{print $7}') # bytes in again
myvar4=$(netstat -ib | grep -e en1 -m 1 | awk '{print $10}') # bytes out again

# find the difference between bytes in and out during that one second
subin=$(($myvar2 - $myvar1))
subout=$(($myvar4 - $myvar3))

# convert bytes to megabytes
mbin=$(echo "scale=2 ; $subin/1048576;" | bc)
mbout=$(echo "scale=2 ; $subout/1048576 ; " | bc)

usedMB=$(echo "scale=2 ; $mbin+$mbout ; " | bc)
AvailBW=$(echo "scale=2 ; $TRate-$usedMB ; " | bc)

echo -e "\033[0;37m" "Wi-Fi AP: " "\033[0;36m" $WiFi "\033[0;37m" "\nIP Address: " "\033[0;36m" $WiFi_IP $3 "\033[0;37m" "\nSubnet Mask: " "\033[0;36m" $SubMask "\033[0;37m" "\nTransmit Rate: " "\033[0;36m" $TRate " Mbps\n" "\033[0;37m" "Data In: " "\033[0;36m" $mbin "Mbps" "\n" "\033[0;37m" "Data Out: " "\033[0;36m" $mbout "Mbps\n" "\033[0;37m" "Available Bandwidth: " "\033[0;36m" $AvailBW " Mbps"

fi

I checked the for active status, assuming that it was initially inactive. If not, then I put in the massive if statement where all the variables are initialized and the computations are done. There is only one call to system_profiler, the one that retrieves the transmission rate, but I wanted to see the "line speed" of my wireless network. This works, not as well as I would have liked, but it was still a good exercise in learning a little bit about where to get information on my Mac, and how to use both awk and see. I still have a lot to learn, but this has been exciting thus far.

Ruby system command not working outside console

Is growlnotify in the PATH that TextMate uses?

Try passing the complete path to growlnotify: ie /usr/local/bin/growlnotify

Coffee Script Replace

First of all, thanks for spreading a word about Übersicht and this widget! They're awesome!

The separator for items in the ~/Desktop/today.txt file is an asterisk * character.

Here's is how my ~/Desktop/today.txt looks like:

answer a beyonddynamic’s question on stackoverflow
*
reading widget’s source code
*
taking a screenshot
*
posting an answer on stackoverfow

Sentences could be written on one line if you prefer. New lines are optional.

screenhot



Related Topics



Leave a reply



Submit