Free space to folder name

tell application "Finder"
	set D to free space of disk ("BOOT")
	(round (D * 100)) / 100
	make new folder
	set name to D
end tell

tis is what i have so far it dosent work because the rounding dosent work

i am trying to make a folder that will just get updated to haveing the current disc free space be its name

More than just the rounding, I’m afraid. Try something like this:


tell application "Finder"
	set D to (free space of disk ("BOOT")) / (1024 ^ 3) as text
	set N to (text 1 thru 5 of D) & " GB"
	make new folder with properties {name:N}
end tell

Funny you should ask, I have a routine that does what you’re asking and a bunch more, except I write a file (not a folder name) and it also updates an Excel spreadsheet and graph for long-term tracking.

The only problem is without posting the whole huge script (373 lines), I couldn’t find a handy way to to give you just the relevant bits.

I do use this line to create the generic file and give it the name of the free space percentage:


			make new file at messagePath with properties {name:messageName}

Instead of renaming the file name I just delete it and re-create it every time.

To get the file space I use a routine I think I found here, or perhaps one of my books, that does a round+truncate using MOD for the most part, plus a routine to convert E+ notation to text (so it can be a human-readable number). If anyone wants to see the entire script out of curiosity, I can post it. Just didn’t want to confuse the original poster with too much information.

coughpost_it_to_ScriptBuilderscough :smiley:

Couldn’t have said it better myself, James :cool:

is there a way that this would work as a folder action so that the folder would just update to the freespace?

tell application "Finder"
set theFolder to (theFolderAlias)
	set D to (free space of disk ("BOOT")) / (1024 ^ 3) as text
	set N to (text 1 thru 5 of D) & " GB Free"
	set name of theFolder to N
end tell

I’ve always been hesitant to post there since I rarely write script to “work in the wild”…they are generally coded to take advantage of our specific environment and wouldn’t work anywhere else without some description of what to change. My “Free Space Tracker” script has alot of dependencies and assumptions and wouldn’t be useful “as is.”

Are you cool with “unpolished” stuff like that?

The only exception so far was the File Type/Creator fixer I created…

http://bbs.applescript.net/viewtopic.php?id=19095

…but I was told to put that in Code Exchange.

I’ll post the code, but is ScriptBuilder or Code Exchange more appropriate (if either) for my Free Space Tracker?

Perhaps this is something ScriptBuilders can help you with.

anyone know how to turn this into a folderaction or have a site i could look at on making folder actions?

Hi,

there is a problem renaming a file or folder within a hot folder,
because this runs into a infinite loop. The folder action handler
detects every renamed file or folder as a new file.

Given the dependencies, as you put it, I’d think that Code Exchange would be the place, with comments where the dependencies need to be adjusted. Love to have it. :cool:

I’d use an “on idle” stay-open script application like this:


property Fname : "freeSpace" -- this only appears briefly, if at all
property tFldr : ((path to desktop folder as text) & Fname)

on run
	try
		tell application "Finder" to delete tFldr -- get a fresh start if you have quit but left tFldr in place.
	end try
end run

on idle
	tell application "Finder"
		try
			set tFldr to alias ((path to desktop folder as text) & Fname)
		on error
			set tFldr to make new folder with properties {name:Fname} at desktop
		end try
		tell application "Finder"
			set D to (free space of disk ("BOOT")) / (1024 ^ 3) as text
			set N to (text 1 thru 5 of D) & " GB Free"
			set Fname to N
			set name of tFldr to N
		end tell
	end tell
	return 60 -- one minute
end idle

Remember the old, saying, be careful what you wish for…

http://bbs.applescript.net/viewtopic.php?id=20393

But like my File Type/Creator fixer, I sincerely hope someone finds something useful in my coding efforts. I’ve learned so much in the last year. I’ve taken on things a bit beyond my reach a couple times and managed to make them work, and alot of it is thanks to insights from MacScripter. Any little bit I can give back to the community is given happily! :D:):lol::cool: