{"id":569,"date":"2007-08-05T18:55:36","date_gmt":"2007-08-06T01:55:36","guid":{"rendered":"http:\/\/www.latenightsw.com\/blogfs5\/?p=41"},"modified":"2012-05-05T19:52:23","modified_gmt":"2012-05-06T02:52:23","slug":"dock-icon-changer","status":"publish","type":"post","link":"http:\/\/markalldritt.com\/?p=569","title":{"rendered":"Dock Icon Changer"},"content":{"rendered":"<p>One of my FaceSpan 4 examples demonstrated how to manipulate an application&#8217;s Dock icon.  In this example, I rewrite that example using FaceSpan 5.  Here&#8217;s the original code:<\/p>\n\n<pre>\nproperty pAppIcon : missing value\nproperty pSmileImage : missing value\nproperty pCoolImage : missing value\n\non awake from nib theObject\n    -- cache the images we'll be using\n    set pAppIcon to load image \"NSApplicationIcon\"\n    set pSmileImage to load image \"smile\"\n    set pCoolImage to load image \"cool\"\nend awake from nib\n\non clicked theObject\n    local theName\n\n    -- For radio buttons, theObject is the cell that was clicked\n    -- In our case, we have named the cells 'none', 'smile' and 'cool'\n\n    set theName to name of theObject\n    if theName is \"smile\" then\n        set image of image view \"preview\" of window \"main\" to pSmileImage\n        set icon image to pSmileImage\n    else if theName is \"cool\" then\n        set image of image view \"preview\" of window \"main\" to pCoolImage\n        set icon image to pCoolImage\n    else\n        -- otherwise, reset the dock icon to the application's icon\n        set image of image view \"preview\" of window \"main\" to my pAppIcon\n        set icon image to my pAppIcon\n    end if\nend clicked\n<\/pre>\n\n<p>Much of this code is concerned with managing the images that appear in the example.  The balance of the code responds to radio button selections by altering the images in the &#8216;preview&#8217; <em>image view<\/em> and the application&#8217;s dock icon.<\/p>\n\n<p>Here&#8217;s the code rewritten to take advantage of FaceSpan 5:<\/p>\n\n<pre>\non action theObject\n    if my id is theObject's id then\n        local theImageName\n\n        --  Read the dockImageName property of the selected radio button\n        set theImageName to my selection's dockImageName\n\n        --  Display the image in the preview view and the dock icon\n        set my application's dock image to theImageName\n        set image of my window's preview to my application's dock image\n    end if\nend action\n<\/pre>\n\n<p>You&#8217;ll notice the following differences (beyond its being considerably shorter):<\/p>\n\n<ul>\n<li>the code deals in the names of images (located within the application bundle) rather than having to explicitly load images, and retain references to the loaded images.<\/li>\n<li>references to the &#8220;preview&#8221; <em>image view<\/em> are made using the &#8220;preview&#8221; property of the window object rather than having to give full object specifiers (though that is possible).<\/li>\n<li>the code reads the name of the dock image from &#8220;dockImageName&#8221; property defined in each radio button object.<\/li>\n<li>the implicit scope in FaceSpan 5 is the object to which the code belongs (a <em>box<\/em> object in this case) rather than the application as is the case in FaceSpan 4 (and AppleScript Studio).<\/li>\n<\/ul>\n\n<p>Here&#8217;s how the project appears in the FaceSpan IDE:<\/p>\n\n<p><img id=\"image40\" src=\"http:\/\/blog.latenightsw.com\/wp-content\/uploads\/2007\/08\/dockiconchangeproject.jpg\" alt=\"dockiconchangeproject.jpg\" \/><\/p>\n\n<p>Its not enough to simply recreate the FaceSpan 4 example in FaceSpan 5.  Lets take advantage of some additional dock functionality: FaceSpan 5 allows you to add progress and count badges.<\/p>\n\n<p>Here&#8217;s the code that adds a Safari-style progress bar to the Dock icon:<\/p>\n\n<pre>\n    set my application's dock progress value to 0.8 -- 80%\n    set my application's dock progress style to Safari progress\n<\/pre>\n\n<p>And here&#8217;s the code that adds a Mail style count to the Dock icon:<\/p>\n\n<pre>\n    set my application's dock count value to 2007\n    set my application's dock count style to Mail count\n<\/pre>\n\n<p>When its all put together, here&#8217;s how it appears in the running application:<\/p>\n\n<p><object classid=\"clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B\" codebase=\"http:\/\/www.apple.com\/qtactivex\/qtplugin.cab\" height=\"288\" width=\"459\"><\/p>\n\n<p><param name=\"src\" value=\"http:\/\/blog.latenightsw.com\/wp-content\/uploads\/2007\/08\/dockicons.mov\">\n<param name=\"autoplay\" value=\"false\">\n<param name=\"type\" value=\"video\/quicktime\" height=\"288\" width=\"459\"><\/p>\n\n<p>\n<\/object><\/p>\n\n<p>And here is the finished project: <a id=\"p42\" href=\"http:\/\/blog.latenightsw.com\/wp-content\/uploads\/2007\/08\/dockiconchangefs5.zip\">Dock Icon Change (FS5)<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>One of my FaceSpan 4 examples demonstrated how to manipulate an application&#8217;s Dock icon. In this example, I rewrite that example using FaceSpan 5. Here&#8217;s&#8230;<div class=\"more-link-wrapper\"><a class=\"more-link\" href=\"http:\/\/markalldritt.com\/?p=569\">Continue Reading<span class=\"screen-reader-text\">Dock Icon Changer<\/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":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false}}},"categories":[10],"tags":[],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p7AQk-9b","_links":{"self":[{"href":"http:\/\/markalldritt.com\/index.php?rest_route=\/wp\/v2\/posts\/569"}],"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=569"}],"version-history":[{"count":7,"href":"http:\/\/markalldritt.com\/index.php?rest_route=\/wp\/v2\/posts\/569\/revisions"}],"predecessor-version":[{"id":607,"href":"http:\/\/markalldritt.com\/index.php?rest_route=\/wp\/v2\/posts\/569\/revisions\/607"}],"wp:attachment":[{"href":"http:\/\/markalldritt.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=569"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/markalldritt.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=569"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/markalldritt.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=569"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}