Jump to content
Florian

Check available disk space

Recommended Posts

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

Share this post


Link to post

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

Share this post


Link to post

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>"

Share this post


Link to post

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.

Share this post


Link to post

<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>"

Share this post


Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...