PDA

View Full Version : [Geektool] Problems creating my first custom script


kiercardo
Jan 3, 2013, 10:54 AM
Hi
I literally fallen in love with this geekleet (http://www.macosxtips.co.uk/geeklets/system/disk-capacity-meter/) and i'm trying to make something similar for cpu, but it simply doesn't work

This is the original tutorial for the diskspace
d13t

110923

Inspired by & adapted script from midnighttokerkate's [Circle Volume Indicator](http://www.macosxtips.co.uk/geeklets/system/circle-volume-indicator/)

INSTRUCTIONS
------------

1. Move DiskCapacityMeter folder to your preferred directory, eg to **Documents/Geektool/**

2. Edit the PATH variable in DCM.scpt to match the path of the DiskCapacityMeter folder,
eg **/Users/YOURUSERNAME/Documents/GeekTool/DiskCapacityMeter/**

3. Open GeekTool/NerdTool and set up a shell geeklet to do:

`osascript /PATH/DCM.scpt`

Where PATH is the path from step 2.

4. Then set up an image geeklet with image:

`file://localhost/PATH/temp.png`

Where PATH is the path from step 2. I placed the image geeklet bottom center of my screen and the 'blind' shell geeklet right under it. This is not ideal and somebody could make all this work without AppleScript… but hey, it works!

5. Set refresh rate of the geeklets to what you like, I prefer 3600 seconds.


and the original DCM.scpt
-- @d13t
-- 110923

-- Inspired by & adapted script from midnighttokerkate's Circle Volume Indicator
-- http://www.macosxtips.co.uk/geeklets/system/circle-volume-indicator/

-- In GeekTool/NerdTool set up shell geeklet with: osascript /Users/d/Documents/GeekTool/DiskCapacityMeter/DCM.scpt
-- In GeekTool/NerdTool set up image geeklet with image: file://localhost/Users/d/Documents/GeekTool/DiskCapacityMeter/temp.png
-- Set refresh rate to what you like, I prefer 3600 seconds

on run
-- Set the path to the directory of the DiskCapacityMeter folder
-- For example: ""
set pathName to "/Users/me/Documents/Geektool/DiskCapacityMeter/"

-- df -hl | grep 'disk0s2' | awk '{sub(/%/, "");print $5}'
-- Substitute % with ""
set usedSpace to (do shell script "df -hl | grep 'disk1s2' | awk '{sub(/%/, \"\");print $5}'") as integer

-- Getting the rounded number
set theNumber to (round (usedSpace / 5)) * 5

-- Replacing the image
do shell script ("cp " & pathName & "/img/" & theNumber & ".png " & pathName & "/temp.png")
end run



this is my script

on run

set usedSpace to (do shell script "top -l 1 | awk 'CPU usage' | awk '{sub(/%/, \"\"); print $7}'") as integer


-- Getting the rounded number
set theNumber to (round (usedSpace / 5)) * 5

-- Replacing the image
do shell script ("cp " & pathName & "/img/" & theNumber & ".png " & pathName & "/temp.png")
end run

and my desktop
http://img651.imageshack.us/img651/8803/schermata20130103alle17.png

I simply want CPU.scpt working in order to have a circle like the hdd capacity indicator

kiercardo
Jan 6, 2013, 04:01 PM
up

Ap0ks
Jan 8, 2013, 05:57 PM
I too couldn't get your script to work initially, but after a little bit of tweaking I managed to bash something together that seems to work


on run
-- Folder containing files
set pathName to "/Users/chollis/Documents/Geeklets/DCM"

-- Get user CPU usage from top
set usedCPU to (do shell script "top -l 1 | grep 'CPU usage'| awk '{sub(/%/, \"\");print $3}'") as integer

-- Get the rounded number
set theNumber to (round (usedCPU / 5)) * 5

-- Replace the temp image
set cpuUsage to pathName & "/img/" & theNumber & ".png"
set tempImage to pathName & "/temp.png"
do shell script ("cp " & cpuUsage & " " & tempImage)
end run


Hope that helps you achieve the final effect you're after :)

franzg
Feb 5, 2014, 04:24 AM
hi, i would really appreciate any help :) i'm new to writing script and learning how to delete things properly. The problem i am having is that i wrote a command in a shell, lets say something like date +"%b %d" then i closed the shell by pressing the X button because i didn't want the shell. I realized it looked good, so i open a shell and write the exact same command as before, but this time there's nothing in the shell. I've checked to make sure the font is large and in a visible colour and this does not resolve the issue.

thank you for any advice or help