{"id":10036,"date":"2014-10-29T23:38:16","date_gmt":"2014-10-30T03:38:16","guid":{"rendered":"http:\/\/mjtsai.com\/blog\/?p=10036"},"modified":"2017-08-01T14:49:52","modified_gmt":"2017-08-01T18:49:52","slug":"applescript-and-yosemite","status":"publish","type":"post","link":"https:\/\/mjtsai.com\/blog\/2014\/10\/29\/applescript-and-yosemite\/","title":{"rendered":"AppleScript and Yosemite"},"content":{"rendered":"<p><a href=\"http:\/\/www.automatedworkflows.com\/2014\/10\/28\/whats-new-with-automation-in-yosemite\/\">Ray Robertson<\/a>:<\/p>\n<blockquote cite=\"http:\/\/www.automatedworkflows.com\/2014\/10\/28\/whats-new-with-automation-in-yosemite\/\"><p>Apple introduced a great variety of new automation features and updates in Yosemite. I&rsquo;ve written up a quick summary below with links to more detailed information.<\/p><\/blockquote>\n<p><a href=\"http:\/\/www.red-sweater.com\/blog\/3000\/yosemites-automation-improvements\">Daniel Jalkut<\/a>:<\/p>\n<blockquote cite=\"http:\/\/www.red-sweater.com\/blog\/3000\/yosemites-automation-improvements\"><p>Unfortunately the progress feature of AppleScript has not been exposed to 3rd party developers, so far as I can tell.<\/p><\/blockquote>\n<p><a href=\"https:\/\/developer.apple.com\/library\/mac\/releasenotes\/AppleScript\/RN-AppleScript\/RN-10_10\/RN-10_10.html\">AppleScript Release Notes<\/a>:<\/p>\n<blockquote cite=\"https:\/\/developer.apple.com\/library\/mac\/releasenotes\/AppleScript\/RN-AppleScript\/RN-10_10\/RN-10_10.html\"><p>AppleScript\/Objective-C is now available to all scripts, not just library scripts.<\/p><\/blockquote>\n<p>I&rsquo;ve been wanting this feature for years. You no longer have to create a special AppleScriptObjC application; you can use it from any script. This will be useful both for the powerful Cocoa APIs as well as the many basic data structures and operations that were never part of AppleScript.<\/p>\n<p>Here are some examples:<\/p>\n<pre>use framework \"Foundation\"\n\n-- Calling an Objective-C class method:\nget current application's NSDate's timeIntervalSinceReferenceDate()\n\n-- Use pipes to avoid conflicts with AppleScript keywords.\nget current application's NSDate's |date|'s timeIntervalSinceReferenceDate()\n\n-- Basically, you just use &ldquo;'s&rdquo; in place of &ldquo;.&rdquo;.\nset _array to current application's NSMutableArray's alloc()'s init()\n\n-- &ldquo;count&rdquo; is also reserved.\nget _array's |count|()\n\n-- AppleScript changes &ldquo;_array's addObject_(1)&rdquo; to the <a href=\"http:\/\/mjtsai.com\/blog\/2013\/10\/25\/applescript-and-mavericks\/\">interleaved syntax<\/a>:\n_array's addObject:1\n\n-- AppleScript changes &ldquo;_array's insertObject_atIndex_(0, 0)&rdquo; to:\n_array's insertObject:0 atIndex:0\n\nset _string to _array's |description|()\nset _appleScriptString to _string as Unicode text\n\nset _data to _string's dataUsingEncoding:(current application's NSUTF8StringEncoding)\nset _tildePath to current application's NSString's stringWithString:\"~\/Desktop\/test\"\nset _path to _tildePath's stringByExpandingTildeInPath()\nset {_ok, _error} to _data's writeToFile:_path options:0 |error|:(reference)\n-- Should return &ldquo;{1, missing value}&rdquo;.\n-- The file will contain &ldquo;(0, 1)&rdquo;.<\/pre>\n<p>Unfortunately, it looks like the technology is not yet very mature. Script Editor beach balled and had to be force-quit half a dozen times while I was writing this sample.<\/p>\n<p>Update (2014-10-31): <a href=\"http:\/\/joris.kluivers.nl\/blog\/2014\/10\/31\/yosemite-scripting-progress-reporting\/\">Joris Kluivers<\/a> shows that developers <em>can<\/em> get at the progress of a script&mdash;via <code>NSProgress<\/code>.<\/p>\n<p>Update (2014-11-29): <a href=\"http:\/\/blog.latenightsw.com\/?p=836\">Mark Aldritt<\/a>:<\/p>\n<blockquote cite=\"http:\/\/blog.latenightsw.com\/?p=836\"><p>What is not explained is how a host application can access this information and display a script&rsquo;s progress in its own UI. Here&rsquo;s how you do it.<\/p>\n<p>At intervals the script will call the OSAActiveProc. Within this callback function you can make OSA calls that access the running script&rsquo;s state. You start by getting a reference to the &lsquo;AppleScript&rsquo; object. From there you can read the value of the four progress properties.<\/p><\/blockquote>","protected":false},"excerpt":{"rendered":"<p>Ray Robertson: Apple introduced a great variety of new automation features and updates in Yosemite. I&rsquo;ve written up a quick summary below with links to more detailed information. Daniel Jalkut: Unfortunately the progress feature of AppleScript has not been exposed to 3rd party developers, so far as I can tell. AppleScript Release Notes: AppleScript\/Objective-C is [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"apple_news_api_created_at":"","apple_news_api_id":"","apple_news_api_modified_at":"","apple_news_api_revision":"","apple_news_api_share_url":"","apple_news_coverimage":0,"apple_news_coverimage_caption":"","apple_news_is_hidden":false,"apple_news_is_paid":false,"apple_news_is_preview":false,"apple_news_is_sponsored":false,"apple_news_maturity_rating":"","apple_news_metadata":"\"\"","apple_news_pullquote":"","apple_news_pullquote_position":"","apple_news_slug":"","apple_news_sections":"\"\"","apple_news_suppress_video_url":false,"apple_news_use_image_component":false,"footnotes":""},"categories":[4],"tags":[159,650,131,69,30,903,1549,71],"class_list":["post-10036","post","type-post","status-publish","format-standard","hentry","category-programming-category","tag-applescript","tag-applescriptobjc","tag-bug","tag-cocoa","tag-mac","tag-mac-os-x-10-10-yosemite","tag-nsprogress","tag-programming"],"apple_news_notices":[],"_links":{"self":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/10036","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/comments?post=10036"}],"version-history":[{"count":5,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/10036\/revisions"}],"predecessor-version":[{"id":10173,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/10036\/revisions\/10173"}],"wp:attachment":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/media?parent=10036"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/categories?post=10036"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/tags?post=10036"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}