{"id":836,"date":"2014-11-27T11:13:47","date_gmt":"2014-11-27T18:13:47","guid":{"rendered":"http:\/\/blog.latenightsw.com\/?p=836"},"modified":"2014-12-04T14:12:37","modified_gmt":"2014-12-04T21:12:37","slug":"getting-yosemite-applescript-progress-information","status":"publish","type":"post","link":"http:\/\/markalldritt.com\/?p=836","title":{"rendered":"Getting Yosemite AppleScript Progress Information"},"content":{"rendered":"<p>Yosemite (Mac OS X 10.10) introduced 4 new properties scripts can set to report progress information:<\/p>\n\n<p><code>progress total steps<\/code> (an integer)<br \/>\n  <code>progress completed steps<\/code> (an integer)<br \/>\n  <code>progress description<\/code> (text)<br \/>\n  <code>progress additional description<\/code> (text)  <\/p>\n\n<p>See the <a href=\"https:\/\/developer.apple.com\/library\/mac\/releasenotes\/AppleScript\/RN-AppleScript\/RN-10_10\/RN-10_10.html\">Yosemite AppleScript Release Notes<\/a> for full details.<\/p>\n\n<p>What is not explained is how a host application can access this information and display a script&#8217;s progress in its own UI.  Here&#8217;s how you do it.<\/p>\n\n<p>At intervals the script will call the OSAActiveProc.  Within this callback function you can make OSA calls that access the running script&#8217;s state.  You start by getting a reference to the &#8216;AppleScript&#8217; object.  From there you can read the value of the four progress properties.  The following code uses my own OSAID wrapper object (RKOSAID &#8211; don&#8217;t ask, Script Debugger is 20 year old code).  You can use whichever OSA API you are most familiar with.<\/p>\n\n<pre><code>--  Provisional property ID constants until Apple puts them into a public API\n\n#define pASProgressTotalSteps_LNS       'ppgt'\n#define pASProgressStepsCompleted_LNS   'ppgc'\n#define pASProgressDescription_LNS      'ppgd'\n#define pASProgressAdditionalDescription_LNS 'ppga'\n\n@interface RKOSAID (AppleScriptProgress)\n\n- (NSDictionary*) appleScriptProgress;\n\n@end\n\n@implementation RKOSAID (AppleScriptProgress)\n\n- (NSDictionary*) appleScriptProgress {\n\n    \/\/ Get a reference to the 'AppleScript' object\n    RKOSAID* as = [self propertyForPropertyID:pASTopLevelScript];\n\n    \/\/ Extract the progress properties\n    RKOSAID* totalSteps = [as propertyForPropertyID:pASProgressTotalSteps_LNS];\n    RKOSAID* steps = [as propertyForPropertyID:pASProgressStepsCompleted_LNS];\n    RKOSAID* description = [as propertyForPropertyID:pASProgressDescription_LNS];\n    RKOSAID* addnlDescription = [as propertyForPropertyID:pASProgressAdditionalDescription_LNS];\n\n    \/\/ Convert into Cocoa objects and return\n    return @{@\"totalSteps\": @(totalSteps.descriptor.int32Value),\n             @\"steps\": @(steps.descriptor.int32Value),\n             @\"description\" : description.descriptor.stringValue,\n             @\"additionalDescription\" : addnlDescription.descriptor.stringValue};\n}\n\n@end\n<\/code><\/pre>\n\n<p><strong>NOTE<\/strong>: My -[RKOSAID propertyForPropertyID:] call wraps the OSAGetProperty() call defined in ASDebugging.h.<\/p>\n\n<p><strong>SEE ALSO<\/strong>: <a href=\"http:\/\/blog.latenightsw.com\/?p=893\">OSAID Leaks Cause Crashes<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Yosemite (Mac OS X 10.10) introduced 4 new properties scripts can set to report progress information: progress total steps (an integer) progress completed steps (an&#8230;<div class=\"more-link-wrapper\"><a class=\"more-link\" href=\"http:\/\/markalldritt.com\/?p=836\">Continue Reading<span class=\"screen-reader-text\">Getting Yosemite AppleScript Progress Information<\/span><\/a><\/div><\/p>","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"jetpack_publicize_message":"","jetpack_is_tweetstorm":false,"jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false}}},"categories":[6,8],"tags":[],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p7AQk-du","_links":{"self":[{"href":"http:\/\/markalldritt.com\/index.php?rest_route=\/wp\/v2\/posts\/836"}],"collection":[{"href":"http:\/\/markalldritt.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/markalldritt.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/markalldritt.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/markalldritt.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=836"}],"version-history":[{"count":7,"href":"http:\/\/markalldritt.com\/index.php?rest_route=\/wp\/v2\/posts\/836\/revisions"}],"predecessor-version":[{"id":905,"href":"http:\/\/markalldritt.com\/index.php?rest_route=\/wp\/v2\/posts\/836\/revisions\/905"}],"wp:attachment":[{"href":"http:\/\/markalldritt.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=836"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/markalldritt.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=836"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/markalldritt.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=836"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}