help with script!

Hi Experts!

I’m quite new to AppleScript…hoping for a little help.

I wrote the script below, which works, but is quite “ugly”. It reports information about the SAN volumes on the system.

I can’t figure out how to loop through my disks, called “F1” “F2” etc… i know how to do the “repeat” thing, but how to reference a disk with a variable? disk “F”&d doesn’t work…

I’m using TextEdit as a “dump”, but I would also like this to display in a nice window, with a “refresh” button, and which could be copied to clipboard.

I’m also interested in how to format it in TextEdit – make some items bold, etc. I tried

keystroke "b" using command down

but that did nothing.

THANKS!


tell application "Finder"
	set gb to 1024 ^ 3
	set free_space to {1, 2, 3, 4, 5, 6}
	set omf_c to {1, 2, 3, 4, 5, 6}
	set mxf_c to {1, 2, 3, 4, 5, 6}
	set omf_s to {1, 2, 3, 4, 5, 6}
	set mxf_s to {1, 2, 3, 4, 5, 6}
	
	set item 1 of free_space to (free space of disk "f1") / gb as integer
	set item 2 of free_space to (free space of disk "f2") / gb as integer
	set item 3 of free_space to (free space of disk "f3") / gb as integer
	set item 4 of free_space to (free space of disk "f4") / gb as integer
	set item 5 of free_space to (free space of disk "f5") / gb as integer
	set item 6 of free_space to (free space of disk "f6") / gb as integer
	
	set item 1 of omf_c to count of items of folder "OMFI MediaFiles" of disk "F1"
	set item 1 of mxf_c to count of items of folder "Avid MediaFiles:MXF:1" of disk "F1"
	set item 1 of omf_s to (physical size of folder "OMFI MediaFiles" of disk "F1")
	set item 1 of mxf_s to (physical size of folder "Avid MediaFiles:MXF:1" of disk "F1")
	
	set item 2 of omf_c to count of items of folder "OMFI MediaFiles" of disk "F2"
	set item 2 of mxf_c to count of items of folder "Avid MediaFiles:MXF:1" of disk "F2"
	set item 2 of omf_s to (physical size of folder "OMFI MediaFiles" of disk "F2")
	set item 2 of mxf_s to (physical size of folder "Avid MediaFiles:MXF:1" of disk "F2")
	
	set item 3 of omf_c to count of items of folder "OMFI MediaFiles" of disk "F3"
	set item 3 of mxf_c to count of items of folder "Avid MediaFiles:MXF:1" of disk "F3"
	set item 3 of omf_s to (physical size of folder "OMFI MediaFiles" of disk "F3")
	set item 3 of mxf_s to (physical size of folder "Avid MediaFiles:MXF:1" of disk "F3")
	
	set item 4 of omf_c to count of items of folder "OMFI MediaFiles" of disk "F4"
	set item 4 of mxf_c to count of items of folder "Avid MediaFiles:MXF:1" of disk "F4"
	set item 4 of omf_s to (physical size of folder "OMFI MediaFiles" of disk "F4")
	set item 4 of mxf_s to (physical size of folder "Avid MediaFiles:MXF:1" of disk "F4")
	
	set item 5 of omf_c to count of items of folder "OMFI MediaFiles" of disk "F5"
	set item 5 of mxf_c to count of items of folder "Avid MediaFiles:MXF:1" of disk "F5"
	set item 5 of omf_s to (physical size of folder "OMFI MediaFiles" of disk "F5")
	set item 5 of mxf_s to (physical size of folder "Avid MediaFiles:MXF:1" of disk "F5")
	
	set item 6 of omf_c to count of items of folder "OMFI MediaFiles" of disk "F6"
	set item 6 of mxf_c to count of items of folder "Avid MediaFiles:MXF:1" of disk "F6"
	set item 6 of omf_s to (physical size of folder "OMFI MediaFiles" of disk "F6")
	set item 6 of mxf_s to (physical size of folder "Avid MediaFiles:MXF:1" of disk "F6")
	
end tell
tell application "System Events"
	tell application "TextEdit" to activate
	tell application "TextEdit" to open "Users:alpha:Desktop:Media File Summary.rtf"
	
	keystroke ((current date) as string) & return
	keystroke "u" using command down
	repeat with d from 1 to 6
		tell process "TextEdit" to keystroke "F" & d & "	OMF	" & (item d of omf_c as string) & "	" & (((item d of omf_s) / gb) as integer) & return & ¬
			item d of free_space & "	MXF	" & (item d of mxf_c as string) & "	" & (((item d of mxf_s) / gb) as integer) & return & return
	end repeat
	keystroke up using command down -- this is supposed to go to the top, but it doesn't work
	keystroke "s" using command down
end tell


Many ways to do this, but give this a shot.

note I didn’t have time to test this so let me know any problems you encounter.

set disk_list to {"F1", "F2", "F3", "F4", "F6"}
set gb to 1024 ^ 3
set free_space to {}
set omf_c to {}
set mxf_c to {}
set omf_s to {}
set mxf_s to {}
set exitFlag to "Refresh"

tell application "Finder"
	repeat until exitFlag = "Quit"
		repeat with aDisk in disk_list
			set end of free_space to (free space of disk aDisk) / gb as integer
			set end of omf_c to count of items of folder "OMFI MediaFiles" of disk aDisk
			set end of mxf_c to count of items of folder "Avid MediaFiles:MXF:1" of disk aDisk
			set end of omf_s to (physical size of folder "OMFI MediaFiles" of disk aDisk)
			set end of mxf_s to (physical size of folder "Avid MediaFiles:MXF:1" of disk aDisk)
		end repeat
		set dataString to ""
		repeat with i from 1 to 6
			--build a display string here something like this
			set dataString to item i of disk_list & return & ¬
				tab & "Free Space: " & item i of free_space & return & ¬
				tab & "OMFI Media Files: " & item i of omf_c & return & ¬
				tab & "Size of OMFI: " & item i of omf_s & return & ¬
				tab & "Avide Media Files: " & item i of mxf_c & return & ¬
				tab & "Size of Avid Media: " & item i of mxf_s & return & return
		end repeat
		display dialog data_string buttons {"Reresh", "Quit"} with title "Media File Summary"
		set exitFlag to button returned of result
	end repeat
end tell

Hi,

the repeat part to get the data could be like this

set gb to 1024 ^ 3
set {free_space, omf_c, mxf_c, omf_s, mxf_s} to {{}, {}, {}, {}, {}}
tell application "Finder"
	set SANdisks to {disk "f1", disk "f2", disk "f3", disk "f4", disk "f5", disk "f6"}
	repeat with i in SANdisks
		set end of free_space to (free space of i) / gb as integer
		tell folder "OMFI MediaFiles:" of i to set {end of omf_c, end of omf_s} to {(count items), physical size}
		tell folder "Avid MediaFiles:MXF:1:" of i to set {end of mxf_c, end of mxf_s} to {(count items), physical size}
	end repeat
end tell

Wow, thanks for the fast replies! This forum is excellent.

James, I ran your script (fixed a couple of typos, see below) … it works!

But is there any way to format the output? I need the numbers lined up in a column … and I’d like to be able to copy the text.

I have the “extra suites” add on – maybe that can help?


set disk_list to {"F1", "F2", "F3", "F4", "F5", "F6"}
set gb to 1024 ^ 3
set free_space to {}
set omf_c to {}
set mxf_c to {}
set omf_s to {}
set mxf_s to {}
set exitFlag to "Refresh"

tell application "Finder"
	repeat until exitFlag = "Quit"
		repeat with aDisk in disk_list
			set end of free_space to (free space of disk aDisk) / gb as integer
			set end of omf_c to count of items of folder "OMFI MediaFiles" of disk aDisk
			set end of mxf_c to count of items of folder "Avid MediaFiles:MXF:1" of disk aDisk
			set end of omf_s to (physical size of folder "OMFI MediaFiles" of disk aDisk)
			set end of mxf_s to (physical size of folder "Avid MediaFiles:MXF:1" of disk aDisk)
		end repeat
		set dataString to ""
		repeat with i from 1 to 6
			--build a display string here something like this
			set dataString to dataString & item i of disk_list & return & ¬
				tab & "Free Space: " & item i of free_space & return & ¬
				tab & "OMFI Media Files: " & item i of omf_c & return & ¬
				tab & "Size of OMFI: " & item i of omf_s & return & ¬
				tab & "Avide Media Files: " & item i of mxf_c & return & ¬
				tab & "Size of Avid Media: " & item i of mxf_s & return & return
		end repeat
		display dialog dataString buttons {"Reresh", "Quit"} with title "Media File Summary"
		set exitFlag to button returned of result
	end repeat
end tell


well you could put a number of tabs in between the info and the actually result that way they would line up in a colum view. you could also send the contents of the data string to a clipboard for easy pasting elsewhere… OR just write the contents to a log file (with timestamps) in addition to displaying to screen.

Really you can do a lot… you just have to decided exactly what you want. let us know and we’ll come up with something… and they I can also incorporate Stefan’s code crunch =)

Can the numbers be formatted, like in Excel?

i.e., can I get “4355” to display as “4,355” and be right-aligned?

The script works well, but 5 times our of 10, I get this error:

“can’t make missing value into type real”

After the error the “gb” is highlighted:

set end of omf_s to ((physical size of folder “OMFI MediaFiles” of disk aDisk) / gb) as integer

The folder exists … it has a size … I don’t get it!

Any ideas?

No.

I guess, the Finder takes some time to calculate the size of the folder.
Either you add a delay or a repeat loop, which waits until the value is not missing value