Geektool Problems creating my first custom script

Discussion in 'UI Customization' started by kiercardo, Jan 3, 2013.

  1. macrumors newbie

    Joined:
    Jan 3, 2013
    Location:
    Rome, IT
    #1
    Hi
    I literally fallen in love with this geekleet and i'm trying to make something similar for cpu, but it simply doesn't work

    This is the original tutorial for the diskspace

    and the original DCM.scpt
    Code:
    -- @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

    Code:
    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
     
  2. thread starter macrumors newbie

    Joined:
    Jan 3, 2013
    Location:
    Rome, IT
  3. macrumors regular

    Joined:
    Aug 12, 2008
    Location:
    Cambridge, UK
    #3
    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

    Code:
    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 :)
     
  4. macrumors newbie

    Joined:
    Feb 5, 2014
    #4
    problem with reinstalling a deleted script

    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
     

Share This Page