<p>How can I poll disk activity in Applescript? Check to see if disk X is being read, written, or idle every N seconds and do something.</p>

[{'answer_id': 65954, 'author': 'jackrabbit', 'author_id': 3707, 'author_profile': 'https://Stackoverflow.com/users/3707', 'pm_score': 2, 'selected': False, 'text': '<p>In general, polling is less efficient than being notified when something happens. Additionally, if you\'re checking whether something is reading from a disk, you will probably be accessing said disk yourself, possibly influencing what you\'re trying to observe.</p>\n\n<p>Since 10.5, OSX includes something called the File System Events framework, which provides course-grained notifications of changes to the file system. The problem in your case is that this is Objective-C only. Apple has some nice <a href="http://developer.apple.com/documentation/Darwin/Conceptual/FSEvents_ProgGuide/" rel="nofollow noreferrer" title="FSEvents Programming Guide">documentation</a> about this API.</p>\n\n<p>Fortunately, there is also the <code>call method</code> AppleScript command. This allows you to work with Objective-C objects from within AppleScript. Here\'s the <a href="http://developer.apple.com/documentation/AppleScript/Conceptual/StudioBuildingApps/chapter04/chapter_4_section_2.html#//apple_ref/doc/uid/20001251-TPXREF175" rel="nofollow noreferrer" title="call method reference">documentation</a> on that.</p>\n\n<p>I have no experience with either, hence the documentation references. Hopefully, this should get you going.</p>\n'}, {'answer_id': 66377, 'author': 'Mike Heinz', 'author_id': 1565, 'author_profile': 'https://Stackoverflow.com/users/1565', 'pm_score': 0, 'selected': False, 'text': "<p>You could run the terminal command iostat periodically. You'd have to parse the results into a form you could digest.</p>\n\n<p>If you know enough about various UNIX command line tools, I'd suggest iostat piping the output to awk or sed to extract just the information you want.</p>\n"}, {'answer_id': 158032, 'author': 'Milhous', 'author_id': 17712, 'author_profile': 'https://Stackoverflow.com/users/17712', 'pm_score': 0, 'selected': False, 'text': '<p>You should really look at Dtrace.  It has the ability to do this sort of thing. </p>\n\n<pre><code>#!/usr/sbin/dtrace -s\n/*\n * bitesize.d - analyse disk I/O size by process.\n *              Written using DTrace (Solaris 10 build 63).\n *\n * This produces a report for the size of disk events caused by \n * processes. These are the disk events sent by the block I/O driver.\n *\n * If applications must use the disks, we generally prefer they do so\n * sequentially with large I/O sizes. \n *\n * 15-Jun-2005, ver 1.00\n *\n * USAGE:   bitesize.d  # wait several seconds, then hit Ctrl-C\n *\n * FIELDS:\n *      PID process ID\n *      CMD command and argument list\n *      value   size in bytes\n *      count   number of I/O operations\n *\n * NOTES: \n * The application may be requesting smaller sized operations, which\n * are being rounded up to the nearest sector size or UFS block size.\n * To analyse what the application is requesting, DTraceToolkit programs\n * such as Proc/fddist may help.\n *\n * SEE ALSO: seeksize.d, iosnoop\n *\n * Standard Disclaimer: This is freeware, use at your own risk.\n *\n * 31-Mar-2004  Brendan Gregg   Created this, build 51.\n * 10-Oct-2004     "      " Rewrote to use the io provider, build 63.\n */\n\n#pragma D option quiet\n\n/*\n * Print header\n */\ndtrace:::BEGIN\n{\n    printf("Sampling... Hit Ctrl-C to end.\\n");\n}\n\n/*\n * Process io start\n */\nio:::start\n{\n    /* fetch details */\n    this-&gt;size = args[0]-&gt;b_bcount;\n    cmd = (string)curpsinfo-&gt;pr_psargs;\n\n    /* store details */\n    @Size[pid,cmd] = quantize(this-&gt;size);\n}\n\n/*\n * Print final report\n */\ndtrace:::END \n{\n    printf("\\n%8s  %s\\n","PID","CMD");\n    printa("%8d  %s\\n%@d\\n",@Size);\n}\n</code></pre>\n\n<p>From <a href="http://developer.apple.com/documentation/Darwin/Reference/ManPages/man1/bitesize.d.1m.html" rel="nofollow noreferrer">here</a>.</p>\n\n<p>To run use </p>\n\n<pre><code>sudo dtrace -s bitsize.d\n</code></pre>\n'}, {'answer_id': 366058, 'author': 'Darryl Hein', 'author_id': 5441, 'author_profile': 'https://Stackoverflow.com/users/5441', 'pm_score': 0, 'selected': False, 'text': '<p>As <a href="https://stackoverflow.com/questions/64748/disk-activity-in-applescript#66377">Porkchop D. Clown</a> mentioned, you can use iostat. A command you could use is:</p>\n\n<pre><code> iostat -c 50 -w 5\n</code></pre>\n\n<p>Which will run iostat 50 times every 5 seconds.</p>\n'}]
['https://Stackoverflow.com/questions/64748', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/7216/']