I’ve got an Applescript I wrote that reports on folder sizes. In the script, I use Nigel Garvey’s convertByteSize subroutine to make sense of the reported sizes. The script works great but I need to include it inside an Automator action and that’s where I run into problems. When I paste the code into the “Run Applescript” action it won’t compile and trips up on the line
to convertByteSize from byteSize
After a little research, I’m guessing that the whole “Run Applescript” action is really a subroutine in and of itself and so the convertByteSize routine won’t run within it. Does that make sense? Can anyone think of a way around it?
One problem might be that you can’t put the “to” clause at the run level. You have to put the handler outside the “run” wrapper. Here’s a syntax example that doesn’t do anything except show you what I mean.
on run {input, parameters}
write_to_file(the_file, the_data)
--return input
end run
on write_to_file(the_file, the_data)
try
open for access the_file with write permission
set eof of the_file to 0
write (the_data) to the_file starting at eof
close access the_file
on error
try
close access the_file
end try
end try
end write_to_file