Jump to content

Check available disk space


Recommended Posts

  • 1 month later...
  • 5 months later...
  • 4 weeks later...
Posted (edited)

I’ve updated Florian’s original workflow. This version

  • has a friendlier display, including correct drive icons
  • handles volumes with spaces in their names
  • displays the correct name of the system drive
  • offers actions on the drives (Finder reveal and Alfred browsing)
  • is certified 100 % awk-free

disk-space-feedback.png

The repo is here, direct download here.

Edited by kopischke
  • 4 months later...
Posted (edited)

Hi guys,

 

Love the proper icons, kopischke, but your workflow shows drives with no free space (e.g. mounted CDs) as 0% full instead of 100% full.

 

Both workflows wrongly add 'b' (instead of 'B'). We're talking about megabytes, not megabits ;)

Edited by deanishe
Posted

If you replace the script filter contents with the following, it should do what you want:

list=$(df -H)
IFS=$'\n'

echo '<?xml version="1.0"?><items>'

for item in $list
do
	if [[ $item == /* ]]; then
		#name
		dev=$(echo $item | awk '{print $1}')
		path=$(echo $item | awk '{$1=$2=$3=$4=$5=$6=$7=$8=""; print $0}' | sed -e 's/^ *//g' -e 's/ *$//g')
		name=$path
		# echo "path : $path, dev : $dev"
		if [ "$path" == "/" ]; then
			name="$(diskutil info $dev | sed -nE 's/^ *Volume Name: +([^ ].*) *$/\1/p')"
		else
			name="${path##*/}"
		fi
		# echo "name : $name"
		# path=$(echo $item | awk '{print $1}')
		size=$(echo $item | awk '{print $2}')
		used=$(echo $item | awk '{print $3}')
		free=$(echo $item | awk '{print $4}')
		perc=$(echo $item | awk '{print $5}')
		free="${free/T/TB}"
		free="${free/G/GB}"
		free="${free/M/MB}"
		free="${free/K/KB}"
		echo '<item uid="diskspace" arg="" valid="no">
		<title>'$name': '$free' available</title>
		<subtitle>'$used'B ('$perc') used of '$size'B total</subtitle>
		<icon type="fileicon">'$path'</icon>
		</item>'
	fi
done

echo "</items>"
Posted

I'm afraid I can't help you with no information. Can you copy the script into its own file, run it in Terminal and post the error message you get?

Posted

If I put your script into the terminal I get the right informations:

 

<item uid="diskspace" arg="" valid="no">

<title><riki12>: 921GB available</title>

<subtitle>191GB (18%) used of 1.1TB total</subtitle>

<icon type="fileicon">/</icon>

</item>

<item uid="diskspace" arg="" valid="no">

<title><riki12> TC: 79GB available</title>

<subtitle>1.9TB (97%) used of 2.0TB total</subtitle>

<icon type="fileicon">/Volumes/<riki12> TC</icon>

</item>

 

 

but if I put your script into Alfred and I digit the keyword "space" nothing happens:

I can see the HD icon in a "working" status but nothing more.

Posted

<title><riki12> TC: 79GB available</title>

<icon type="fileicon">/Volumes/<riki12> TC</icon>

 

If that's what's coming out of the script, that's what's breaking Alfred. It doesn't like the < and > in the volume name, as it's invalid XML.

 

This might fix the problem:

#/bin/bash

list=$(df -H)
IFS=$'\n'

echo '<?xml version="1.0"?><items>'

for item in $list
do
	if [[ $item == /* ]]; then
		#name
		dev=$(echo $item | awk '{print $1}')
		path=$(echo $item | awk '{$1=$2=$3=$4=$5=$6=$7=$8=""; print $0}' | sed -e 's/^ *//g' -e 's/ *$//g')
		name=$path
		# echo "path : $path, dev : $dev"
		if [ "$path" == "/" ]; then
			name="$(diskutil info $dev | sed -nE 's/^ *Volume Name: +([^ ].*) *$/\1/p')"
		else
			name="${path##*/}"
		fi
		# echo "name : $name"
		# path=$(echo $item | awk '{print $1}')
		size=$(echo $item | awk '{print $2}')
		used=$(echo $item | awk '{print $3}')
		free=$(echo $item | awk '{print $4}')
		perc=$(echo $item | awk '{print $5}')
		free="${free/T/TB}"
		free="${free/G/GB}"
		free="${free/M/MB}"
		free="${free/K/KB}"
		echo '<item uid="diskspace" arg="" valid="no">
		<title><![CDATA['$name': '$free' available]]></title>
		<subtitle>'$used'B ('$perc') used of '$size'B total</subtitle>
		<icon type="fileicon"><![CDATA['$path']]></icon>
		</item>'
	fi
done

echo "</items>"

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...