Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

soliton

macrumors newbie
Original poster
May 14, 2010
4
0
I've tried recording my actions, trying as a workflow, app, service - but it never seems to work when I try to play it back.

My main goal: I need to know the size of two folders (how many GB) on a daily basis. I think the easiest way to do that would be to Get Info on both, take one screenshot and drag that screenshot file into a shared folder that I have access to. I would need to schedule it to happen at the same time each night.

A better more detailed version would be to Get Info, copy the string beside Size: eg, "2,731 bytes (4 KB on disk) for 1 item"
and paste that into a new Excel sheet row each day.

Any help for either?

Many thanks! :)
 
There is a command-line tool that can easily calculate and output the numbers you want. If you want to look at it, and its myriad of options, it's the 'du' command:
https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man1/du.1.html

One simple example:
Code:
du -mxd 0 ~/Documents ~/Library
This outputs the total sizes (measured in MB) of two folders in your home folder. Other measuring units are possible (see the man page).

If necessary, the output of 'du' can be parsed and reformatted by a simple 'awk' program. I can post an example, but it will be simpler if you tell us the exact pathnames of the two folders whose sizes you want, and exactly what format you want them in (tab-delimited, comma-delimited, etc.).

Another command of interest is 'pbcopy', which takes text (such as the output of 'du' or 'awk') and puts it on the clipboard. From there, it can be pasted into any app that accepts text:
https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man1/pbcopy.1.html

These commands can be placed into an Automator action "Run Shell Script". If the workflow is created as a Service, then the result of the 'du', 'awk', and 'pbcopy' would be two lines of text containing numbers and pathnames, sitting in the clipboard. You could manually paste it into Excel, or write it to a tab-delimited text file that Excel can open.
 
I think you should look for NSTask with NSPipe
You execute terminal commands with the NSTask and catch the output with NSPipe
I found it very usefull for my project (on xCode)

But better yet you use applescript for this and put it on your tasklist to perform each day
Simply catch the output of shell script
Set value1 to do shellscript "........"
Explode the result and set it to clipboard and paste it wherever you want on the excel sheet.
 
I've tried recording my actions, trying as a workflow, app, service - but it never seems to work when I try to play it back.

My main goal: I need to know the size of two folders (how many GB) on a daily basis. I think the easiest way to do that would be to Get Info on both, take one screenshot and drag that screenshot file into a shared folder that I have access to. I would need to schedule it to happen at the same time each night.

A better more detailed version would be to Get Info, copy the string beside Size: eg, "2,731 bytes (4 KB on disk) for 1 item"
and paste that into a new Excel sheet row each day.

Any help for either?

Many thanks! :)

I'm thinking bash script and cron job would do what you need. This line will give you the size and directory name.

Code:
du -h /path/to/directory | tail -n 1

If you want only the size then.

Code:
du -h /path/to/directory | tail -n 1  | cut -d 'G' -f 1

Now put in a bash script.

Code:
#!/bin/bash
# Get first directory size
dir1='du -h /path/to/directory1 | tail -n 1  | cut -d 'G' -f 1'
# Get second directory size
dir2='du -h /path/to/directory2 | tail -n 1  | cut -d 'G' -f 1'
#Echo to tab separated file
echo $dir1 \t $dir2 > /path/to/file.tsv

You would then be able to import the .tsv file into excel. You would schedule the bash.sh file to run in a cron job with crontab -e then entered into it.

Code:
@daily /path/to/bash.sh

Now the bash.sh is just a rough untested on my part, except getting the proper value, you may have to do some adjustments. Like echoing the headings for proper import, checking to see if file exists then appending instead of just wiping out with the new daily contents like I have now when creating the file, putting a date in it as well them type of things.
 
Thanks chown!

I think grabbing the info and writing it into a file would be the best option.

The path is: Aspera_33 (which is a mounted networked drive on the computer) inside that drive are the two folders Break and Wrap

can you do gigabytes for the du command, so du -gxd ? comma-delimited is fine - is it possible to have each new entry on a new line in the document, ie to insert a linebreak command at the end?

Is there any other info you need? location of the text file could be on the desktop (admin/desktop) and be called 33_tracking

Once this all goes into Automator, is there a way to schedule it to run the service at a certain time?

Thanks again! Much appreciated.
 
Code:
echo $dir1 \t $dir2 >> /path/to/file.tsv

You could add the double '>' there as well to append a new row to the file each day. I would probably go for .csv as well and replace \t with either ',' or ';'. Both Excel and Numbers (and most other similar applications) opens CSV files and in this case it's just two columns of numbers.
 
You could add the double '>' there as well to append a new row to the file each day. I would probably go for .csv as well and replace \t with either ',' or ';'. Both Excel and Numbers (and most other similar applications) opens CSV files and in this case it's just two columns of numbers.

Yeah I mentioned that append idea I used tabs as the values I was dealing with doing similar idea would contain those characters so made it impossible to use those separators also left out.

Code:
chmod +x /path/to/bash.sh

To make it executable so it will actually run...
 
Yeah I mentioned that append idea I used tabs as the values I was dealing with doing similar idea would contain those characters so made it impossible to use those separators also left out.

Yeah well, tabs is indistinguishable from whitespace which is why they aren't that great as separators. In this case neither comma or semi colon is used, but it was just a small suggestion of improvement to your answer.
 
Thanks chown!

I think grabbing the info and writing it into a file would be the best option.

The path is: Aspera_33 (which is a mounted networked drive on the computer) inside that drive are the two folders Break and Wrap

can you do gigabytes for the du command, so du -gxd ? comma-delimited is fine - is it possible to have each new entry on a new line in the document, ie to insert a linebreak command at the end?

Is there any other info you need? location of the text file could be on the desktop (admin/desktop) and be called 33_tracking

Once this all goes into Automator, is there a way to schedule it to run the service at a certain time?

Thanks again! Much appreciated.

Please answer all of the following.

1. What OS version is the computer running? Be specific; e.g. "10.8.3" is specific, "Mountain Lion" is not.

2. What do you want to happen if Aspera_33 isn't mounted when the task runs?

3. What do you want to happen if the admin user isn't logged in at the time you've scheduled the task to run?

4. If other users can login to the computer, do you want the task to be scheduled regardless of whether the admin user has logged in previously?

5. If you haven't read the data from the file "33_tracking" from the last time the task ran, what should happen when the task runs again? Should it overwrite the old contents of "33_tracking", or should it append?

6. What time of day do you want the task to run? How often, daily?

7. WIll you ever want to change the time of day, or how often it runs?

8. Will you ever want to stop the task from running?

9. Mount Aspera_33, then copy and paste the following command into a Terminal window:
Code:
ls -ld /Volumes/*sper*/{Break,Wrap}
Then copy and paste the complete output (including any error messages) into a reply posted here.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.